How can I cleaning up com port buffer with JSerialComm. Every time i call serialEvent(SerialPortEvent event) I get new and old data.
This is my code example:
`public void serialEvent(SerialPortEvent event) {
if (userPort.bytesAvailable() > 0) {
System.out.println(userPort.bytesAvailable());
byte[] readBuffer = new byte[userPort.bytesAvailable()];
if (userPort.bytesAvailable() == 15) {
int numRead = userPort.readBytes(readBuffer, readBuffer.length);
for (int i = 0; i < readBuffer.length; i++) {
bytesRiesived.add(readBuffer[i]);
}
System.out.println(bytesRiesived);
control.addToList(bytesRiesived);
System.out.println("end");
bytesRiesived.clear();
}
}
}`
For example, I send 15 bytes from device and I see 15 bytes in the System.out.println(userPort.bytesAvailable());
Then after some time (about 5 minutes) I send another 15 bytes and I see 30 bytes in the System.out.println(userPort.bytesAvailable());
So tell me please: how to cleaning up com port buffer.
How can I cleaning up com port buffer with JSerialComm. Every time i call
serialEvent(SerialPortEvent event)I get new and old data.This is my code example:
`public void serialEvent(SerialPortEvent event) {
For example, I send 15 bytes from device and I see 15 bytes in the
System.out.println(userPort.bytesAvailable());Then after some time (about 5 minutes) I send another 15 bytes and I see 30 bytes in the
System.out.println(userPort.bytesAvailable());So tell me please: how to cleaning up com port buffer.