All you get is a stream and a SerialPortEvent.DATA_AVAILABLE when data is available in the stream. What you could do is add a level of indirection and create your own listener that would be called when 6 characters have passed through and simply pass in the byte array with thoose 6 characters. I added where you would insert te code below. The implementation is up to you.
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
// partition readBuffer into chunks of 6 bytes
...
registeredListener.dataReceived(sixByteByteArray);
} catch (IOException e) {
}
break;
}
}