Guest User

Untitled

a guest
May 7th, 2015
308
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void addFile(File file) throws SerialPortException
  2. {
  3. try {
  4. System.out.println("Start of add file");
  5. serialCommunication.openPort(port,"115200");
  6. String[] waitForResponse = {"ERROR","CONNECTED"};
  7. byte[] fileData = new byte[(int) file.length()];
  8. System.out.println("file data to string " + new String(fileData.toString()));
  9. DataInputStream dis = new DataInputStream(new FileInputStream(file));
  10. dis.readFully(fileData); //file gets converted to bytes
  11. dis.close();
  12. serialCommunication.send("AT^SJDL=1," + file.length() + ",\"" + file.getName() + "\"",waitForResponse,5000);
  13. System.out.println("check if connected");
  14. if(!SerialCommunication.serialResponseManager.getLastResponse().equals("ERROR"))//check if AT command was ok
  15. {
  16. System.out.println("CONNECTED");
  17. serialCommunication.send(fileData); //file data gets sent
  18. System.out.println("file upload finished");
  19. serialCommunication.close();
  20. }
  21. else
  22. {
  23. System.out.println("FAILED TO START UPLOAD OF FILE");
  24. serialCommunication.close();
  25. }
  26. }
  27. catch (Exception ex)
  28. {
  29. System.out.println("Exception on addFile " + ex);
  30. serialCommunication.close();
  31. }
  32. }
RAW Paste Data