I'm struggling with EOF on a serial port and using a Java InputStream.
My serial device sends continuously 16 bytes with a frequency of 100Hz. My receive routine is similar to this
private static final int MESSAGE_SIZE = 20;
public byte[] read() throws IOException {
final byte[] buffer = new byte[MESSAGE_SIZE];
int total = 0;
int read = 0;
while (total < MESSAGE_SIZE
&& (read = in.read(buffer, total, MESSAGE_SIZE - total)) >= 0) {
total += read;
}
return buffer;
}
posted and proved here.
As result, I get a mixture between the 16 bytes packets and EOF.
How can EOF occur on a serial port?