Java Coding to Serial Ports: Buffers and Streaming Strategies

Note: . Although the library I am using is called Java Simple Serial Connector , this question is really more about Java coding for serial ports in general and any strategies involved.

I am using Java library (JSSC as above) to read data from a serial port. The library requires you to poll the port for all available bytes. But this worries me, because between two different polling attempts, data can be transferred to the port (from the serial device) and therefore possibly "lost".

If there is no buffering / caching mechanism in the hardware that buffers the data coming into the serial port. The library API makes sense in this case, since it probably handles the buffer and reads whatever was in the queue in it. So I ask:

  • Is there such a "serial port buffer"? If so, what is it? If not, are there any strategies for lossless reading of the serial port?
  • If there is such a buffer, how does it work? What happens when it fills up?
  • I am using lib lib to read serial port data like byte[]

    ; does it make sense to then construct a ByteArrayInputStream

    from these byte[]

    ? What benefits will benefit from this?
+3


source to share





All Articles