javaserial-portrxtxjssc

What benefits do Java serial port libraries have over plain IO to the device?


There is a lot of talk about Java serial port libraries like RXTX and JSSC, but what do they really provide? In both linux and windows you can simply open the serial port like a file for reading and writing, can't you? What is the advantage of using the libraries over just reading and writing from the device with file IO?

I understand that the libraries allow you to configure the ports, which would normally need to be done by commandline calls. But assuming the ports are already configured, is there any reason to use the libraries?


Solution

  • In both linux and windows you can simply open the serial port like a file for reading and writing, can't you?

    While this is possible to do, it's not really a recommended way to do it. To go to your second point:

    But assuming the ports are already configured, is there any reason to use the libraries?

    Assuming the ports are configured and configured properly, then it's perfectly possible to simply open up the serial port and read and write it like a normal file. This does come with another caveat though: that if you depend on the control signals at all, you won't be able to get that data from the port. Most serial devices that I have worked with don't do anything with the control lines at all, but that's not something that you can always be sure of.

    The point behind using a library is so that you can get and set the exact settings that you need to in order to talk appropriately over the port.

    As for JSSC/RXTX not having an InputStream/OutputStream for them, I didn't like that about those libraries either, so I wrote my own.