Please note: Although the library I'm using is called the Java Simple Serial Connector, this question is really more about Java coding against serial ports in general, and any strategies associated with doing so.
I'm using a Java library (JSSC as mentioned above) to read data from a serial port. The library requires you to poll the port for all available bytes. But this has me worried, because in between 2 different poll attempts, data could be streamed to the port (from the serial device) and therefore perhaps "lost".
Unless there is some kind of buffering/caching mechanism at the hardware layer that buffers data coming in to the serial port. In that case, the library's API makes sense, as it probably consults the buffer and reads anything thats been queueing up inside it. So I ask:
- Is there such a "serial port buffer"? If so what is it? If not, then are there any strategies to "lossless" serial port reads?
- If there is such a buffer, how does it work? What happens when it fills up?
- The Java lib I'm using reads serial port data as
byte[]
's; does it make sense to then construct aByteArrayInputStream
from thesebyte[]
? What benefits would one gain from doing so?