On a linux (Ubuntu 17.04) instance the nrjavaserial seems to be injecting hex 00 chars into the byte stream when reading out a serial port.
This behaviour is quite "persistent", e.g. happening with each read cycle. When connecting to the serial port on the OS itself (e.g. via screen or picocom) all communication with the serially attached device is correct. When connecting the device to a Mac OS X machine running the same java code, then all communication is correct.
The java code is writing to the serial port using:
if (logger.isTraceEnabled()) {
logger.trace("writeString : '{}'", msg.getBytes());
}
outputStream.write(msg.getBytes());
outputStream.flush();
The java code is reading from the serial port using a loop containing:
if ((len = inputStream.read(tmpData)) > -1) {
foundStart = false;
if (logger.isTraceEnabled()) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
sb.append(String.format("%02X", tmpData[i]));
sb.append(" ");
}
logger.trace("Read {} bytes : {}", len, sb.toString());
}
The resulting line should be 'C5', but you can see that after the first byte, the input stream is returning some 00 bytes, instead of the byte equivalent for '5'
The first loop of the read loop always seems to return a single 00 byte (which gets discarded in my code)
On a linux (Ubuntu 17.04) instance the nrjavaserial seems to be injecting hex 00 chars into the byte stream when reading out a serial port.
This behaviour is quite "persistent", e.g. happening with each read cycle. When connecting to the serial port on the OS itself (e.g. via screen or picocom) all communication with the serially attached device is correct. When connecting the device to a Mac OS X machine running the same java code, then all communication is correct.
The java code is writing to the serial port using:
The java code is reading from the serial port using a loop containing:
The some corresponding logs are as follows:
2017-05-05 16:27:47.612 [TRACE] [.oceanic.handler.OceanicThingHandler] - writeString : '[103, 101, 116, 76, 65, 82, 13]' 2017-05-05 16:27:47.626 [TRACE] [.oceanic.handler.OceanicThingHandler] - Read 1 bytes : 00 2017-05-05 16:27:47.626 [TRACE] [.oceanic.handler.OceanicThingHandler] - Byte 0 equals '0'('00') 2017-05-05 16:27:47.637 [TRACE] [.oceanic.handler.OceanicThingHandler] - Reading the inputStream 2017-05-05 16:27:47.637 [TRACE] [.oceanic.handler.OceanicThingHandler] - Read 19 bytes : 32 36 2E 30 34 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Where you can see that after a bunch of normal bytes a series of 00 bytes is returned
In
2017-05-05 16:30:39.752 [TRACE] [.oceanic.handler.OceanicThingHandler] - writeString : '[103, 101, 116, 67, 89, 78, 13]' 2017-05-05 16:30:39.760 [TRACE] [.oceanic.handler.OceanicThingHandler] - Read 1 bytes : 00 2017-05-05 16:30:39.760 [TRACE] [.oceanic.handler.OceanicThingHandler] - Byte 0 equals '0'('00') 2017-05-05 16:30:39.771 [TRACE] [.oceanic.handler.OceanicThingHandler] - Reading the inputStream 2017-05-05 16:30:39.771 [TRACE] [.oceanic.handler.OceanicThingHandler] - Read 4 bytes : 43 00 00 00 2017-05-05 16:30:39.771 [TRACE] [.oceanic.handler.OceanicThingHandler] - Byte 0 equals '67'('43') 2017-05-05 16:30:39.771 [TRACE] [.oceanic.handler.OceanicThingHandler] - Found the start 2017-05-05 16:30:39.771 [TRACE] [.oceanic.handler.OceanicThingHandler] - dataBuffer[0] set to '67'('43') 2017-05-05 16:30:39.771 [TRACE] [.oceanic.handler.OceanicThingHandler] - Byte 1 equals '0'('00') 2017-05-05 16:30:39.771 [TRACE] [.oceanic.handler.OceanicThingHandler] - The resulting line is 'C'
The resulting line should be 'C5', but you can see that after the first byte, the input stream is returning some 00 bytes, instead of the byte equivalent for '5'
The first loop of the read loop always seems to return a single 00 byte (which gets discarded in my code)