用于连接到 /dev/ttyACM0 的 Java RXTXcomm 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9717477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:38:03  来源:igfitidea点击:

Java RXTXcomm lib to connect to /dev/ttyACM0

javaserial-portcommunicationrxtx

提问by while true

I'm using RXXTX java lib to connect to serial ports. I'm using this lib with no problems connecting to /dev/ttyUSB0 (1,2,3,etc).

我正在使用 RXXTX java lib 连接到串行端口。我正在使用这个库,连接到 /dev/ttyUSB0(1、2、3 等)没有问题。

But when I want to connect to /dev/ttyACM0 the port its not found.

但是当我想连接到 /dev/ttyACM0 时,找不到端口。

CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/ttyACM0");

the Exception is thrown:

抛出异常:

gnu.io.NoSuchPortException at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:218)

gnu.io.NoSuchPortException at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:218)

I already listed all the ports but no success.

我已经列出了所有端口,但没有成功。

回答by MountainX

Processing and USB ports /dev/ttyACM0, /dev/ttyACM1, .... http://pblog.ebaker.me.uk/2011/09/processing-usb-ports-devttyacm0.html

处理和 USB 端口 /dev/ttyACM0, /dev/ttyACM1, .... http://pblog.ebaker.me.uk/2011/09/processing-usb-ports-devttyacm0.html

Processing doesn't like reading Linux USB devices like /dev/ttyACM0 or /dev/ttyACM1.

The solution is easy, just symlink the devices like this...

ln -s /dev/ttyACM[x] /dev/ttyS8[x]

You can put any number after the ttyS, although it is possible that ttyS0 and other low numbers are defined, numbers in the eighties are (almost) guaranteed to work.

处理不喜欢读取 Linux USB 设备,如 /dev/ttyACM0 或 /dev/ttyACM1。

解决方案很简单,只需像这样符号链接设备...

ln -s /dev/ttyACM[x] /dev/ttyS8[x]

您可以在 ttyS 之后放置任何数字,尽管可能定义了 ttyS0 和其他低数字,但(几乎)保证可以使用 80 年代的数字。

回答by AHonarmand

This might help you: https://groups.google.com/forum/#!topic/openhab/f-gVkwJg-hg

这可能对您有所帮助:https: //groups.google.com/forum/#!topic/openhab/f-gVkwJg-hg

update your startup script to include "->Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0" in the Java command line

更新您的启动脚本以在 Java 命令行中包含“->Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0”