使用Java& RXTX在Eclipse中 [英] Serial Port Communication Using Java & RXTX in Eclipse

查看:211
本文介绍了使用Java& RXTX在Eclipse中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要编写一个Java应用程序与Windows环境中的串口设备进行通信,在谷歌浏览中似乎转移到许多方向,也喜欢一些第三方工具库,如 RXTX JavaComm 。尝试使用Eclipse的RXTX示例代码参考



输出中没有串行端口空白



输出:


稳定库



本机lib版本= RXTX-2.1-7



Java lib版本= RXTX-2.1-7


我做了什么错误?


$ b $让我知道这种方法是更好还是建议我更好的解决方案?



请让我知道这个问题的替代方案,我想通过串口通过java与设备进行通信,数据将从设备发送,并将其写入文件。



提前感谢

解决方案

如果链接的例子失败意味着RXTX没有检测到您的机器上的任何串行端口。您的机器上可能有一个串行端口,但您的操作系统无法识别的原因之一可能是因为它实际上是串行到USB适配器,并且被识别为USB端口。



如果你在Linux上,串行端口通常如下所示:

  ls / dev / ttyS * 

输出:

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

适配端口可能如下所示:

  / dev / ttyUSB0 

如果您可以在串行连接的设备上看到一些输出(例如POS打印机或LCD显示屏),您可以测试如下:

  echo'hello'> / dev / ttyUSB0 

,如果设备连接到该端口,设备应显示hello并且一切都正常工作。



但是,我一定会推荐 Java简单串行连接器库通过RxTx。我们已经在商业POS应用程序中尝试了这两个(目前为> 1M个门票)。



RxTx正在成功顺序打印。在打印场景中,RxTx库被顺序调用,并且仅用于将数据发送到端口。只有一些串行标志被红色的检测到设备的繁琐。



但是由于其限制,我们根本无法使用它来读取串行连接的IButton的输入。在iButton情景中,预期数据将从端口异步接收。当我们尝试使用RxTx实现它时,会有不断的bug和挂起,但是JSSC它几乎被实现了immediatley。


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

解决方案

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.

这篇关于使用Java& RXTX在Eclipse中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆