0

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?

Community
  • 1
  • 1
z3ky
  • 1
  • 1
  • possible duplicate of [Disabling EOF (0x1A) using SerialPort](http://stackoverflow.com/questions/13711594/disabling-eof-0x1a-using-serialport) – zapl Nov 08 '14 at 14:00
  • Actually more like http://stackoverflow.com/a/5934997/995891 cant undo the close from mobile it seems – zapl Nov 08 '14 at 14:08
  • 1
    possible duplicate of [RXTX serial connection - issue with blocking read()](http://stackoverflow.com/questions/5219450/rxtx-serial-connection-issue-with-blocking-read) – Frank van Puffelen Nov 08 '14 at 17:06

0 Answers0