Serial Port Exchange Using Java & RXTX in Eclipse

To write a java application to communicate with serial port devices in a Windows environment, google browsing seems to be redirected to many directions, it also supports some third-party tool libraries such as RXTX JavaComm . When you try using the RXTX code examples, use the eclipse Link .

No serial ports were displayed on the output only empty

Output:

Stable library

Native version lib = RXTX-2.1-7

Java lib Version = RXTX-2.1-7

What mistake did I make?

Let me know if this approach is better or offers me a better solution?

Please let me know the alternatives for this problem, I want to communicate with the device via the serial port using java, the data will be sent from the device and must be written to files.

Thank you in advance

+2
source share
1 answer

If the linked example failed, then RXTX did not detect any serial ports on your computer. You may have a serial port on your computer, but one of the reasons it is not recognized by your OS may be because it is actually a USB serial port adapter and is recognized as a USB port.

If you are running Linux, serial ports usually look like this:

ls /dev/ttyS* 

outputs:

 /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 

an adapted port might look like this:

 /dev/ttyUSB0 

If you can see any output on your device connected to the network (for example, a POS printer or LCD), you can check it as follows:

 echo 'hello' > /dev/ttyUSB0 

and the device should show the string "hello" if it is connected to this port, and everything works correctly.

However, I would definitely recommend the Java library simple serial connector through RxTx. We tried both in a commercial POS application (> 1M tickets at this time).

RxTx is used for sequential printing. In the print script, the RxTx library was called sequentially and was used only to send data to the port. Only some of the serial flags were red to detect device health.

But due to its limitations, we simply could not use it to read input from a connected IButton. In an iButton script, it is expected that data will be received asynchronously from the port. There were constant errors and freezes when we tried to implement it using RxTx, but with JSSC it was implemented almost immediately.

+3
source

All Articles