Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void addFile(File file) throws SerialPortException
- {
- try {
- System.out.println("Start of add file");
- serialCommunication.openPort(port,"115200");
- String[] waitForResponse = {"ERROR","CONNECTED"};
- byte[] fileData = new byte[(int) file.length()];
- System.out.println("file data to string " + new String(fileData.toString()));
- DataInputStream dis = new DataInputStream(new FileInputStream(file));
- dis.readFully(fileData); //file gets converted to bytes
- dis.close();
- serialCommunication.send("AT^SJDL=1," + file.length() + ",\"" + file.getName() + "\"",waitForResponse,5000);
- System.out.println("check if connected");
- if(!SerialCommunication.serialResponseManager.getLastResponse().equals("ERROR"))//check if AT command was ok
- {
- System.out.println("CONNECTED");
- serialCommunication.send(fileData); //file data gets sent
- System.out.println("file upload finished");
- serialCommunication.close();
- }
- else
- {
- System.out.println("FAILED TO START UPLOAD OF FILE");
- serialCommunication.close();
- }
- }
- catch (Exception ex)
- {
- System.out.println("Exception on addFile " + ex);
- serialCommunication.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement