I wrote a java program using JSSC library to communicate with a usb serial device in linux.but I encountered several problems when going to communicate.
- Sometimes when going to write data to the port.but serial device didn't read data.but my java program indicate that write is success.(only sometimes happened)
- Before I write to the port first I check for garbage data and Read them if available and give a purge also. but program didn't detect any garbage data before write.but after write and wait for device response(read) garbage data read by the program.
This is my code snippet for writing to the port:
serialPort.readBytes(); //for check garbage data
//purge the port
serialPort.purgePort(PURGE_RXCLEAR );
serialPort.purgePort(PURGE_TXCLEAR);
serialPort.purgePort(PURGE_RXABORT);
serialPort.purgePort(PURGE_TXABORT);
//write to port
serialPort.writeString(s);
System.out.println("Write: "+s);
return true;
please help me to solve at least any problem of above.