Serial Port Communication Using Java & RXTX in Eclipse

≯℡__Kan透↙ 提交于 2019-11-30 19:10:00

问题


To write an java application to communicate with serial port devices on windows environment , browsed in google seem to be divert to many directions also fond some of the third party tools library like RXTX JavaComm. On trying with RXTX sample codes using eclipse Reference.

No serial ports were displayed in output just blank

Output :

Stable Library

Native lib Version = RXTX-2.1-7

Java lib Version = RXTX-2.1-7

What mistake i have did ?

Let me know that is this approach is the better or suggest me better solution ?

Kindly let me know the alternatives for this problem , i wanna communicate with device via serial port using java, the data will be sent from the device and it should be written to the files.

Thanks in advance


回答1:


If the linked example fails it means that RXTX hasn't detected any serial ports on your machine. You may have a serial port on your machine but one of the reasons it isn't recognized by your OS might be because it is actually a serial-to-USB adapter, and is being recognized as an USB port.

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

ls /dev/ttyS*

outputs:

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

the adapted port might look like this:

/dev/ttyUSB0

If you can see some output on your serial attached device (e.g. POS printer or LCD display) you can test it like this:

echo 'hello' > /dev/ttyUSB0

and the device should show the 'hello' string if it is attached to that port and everything is working properly.

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

RxTx is being used for sequential printing successfully. In the print scenario the RxTx library was called upon sequentially and used only to send the data to the port. Only some serial flags were red the detect to buissiness of the device.

But because of its limitations we simply could not use it for reading input from a serially connected IButton. In the iButton scenario the data is expected to be received asynchronously from the port. There were constant bugs and hangs when we tried to implement it with RxTx, but with JSSC it was implemented almost immediatley.



来源:https://stackoverflow.com/questions/14018438/serial-port-communication-using-java-rxtx-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!