在windows环境下编写一个java应用程序与串口设备通信,在google上浏览似乎转向了很多方向,也喜欢一些第三方工具库,如RXTX JavaComm.关于使用 Eclipse 尝试使用 RXTX 示例代码 参考.
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
输出:
稳定库
本机库版本 = RXTX-2.1-7
Native lib Version = RXTX-2.1-7
Java 库版本 = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
我犯了什么错误?
让我知道这种方法更好还是建议我更好的解决方案?
Let me know that is this approach is the better or suggest me better solution ?
请让我知道这个问题的替代方案,我想使用 java 通过串行端口与设备通信,数据将从设备发送并且应该写入文件.
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.
提前致谢
如果链接示例失败,则表示RXTX没有检测到您机器上的任何个串口.您的机器上可能有一个串行端口,但您的操作系统无法识别它的原因之一可能是因为它实际上是一个串行到 USB 适配器,并且被识别为 USB港口.
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.
如果您在 Linux 上,串行端口通常如下所示:
If you are on Linux, serial ports usually look like this:
ls /dev/ttyS*
输出:
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
调整后的端口可能如下所示:
the adapted port might look like this:
/dev/ttyUSB0
如果您可以在串行连接设备(例如 POS 打印机或 LCD 显示器)上看到一些输出,您可以像这样测试它:
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
如果设备连接到该端口并且一切正常,则设备应显示hello"字符串.
and the device should show the 'hello' string if it is attached to that port and everything is working properly.
但是,我肯定会推荐 Java 简单串行连接器 库在 RxTx 上.我们已经在商业 POS 应用程序中尝试过这两种应用程序(目前 >100 万张票).
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 已成功用于顺序打印.在打印场景中,RxTx 库被顺序调用并仅用于将数据发送到端口.只有一些串行标志是红色的,以检测设备的业务.
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.
但由于它的限制,我们根本无法使用它来读取来自串行连接的 IButton 的输入.在 iButton 场景中,预计数据将从端口异步接收.当我们尝试使用 RxTx 实现它时,经常会出现错误和挂起,但使用 JSSC 几乎是立即实现的.
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 & 的串口通信Eclipse 中的 RXTX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!