简体   繁体   中英

Unable to find serial ports

Using Rxtx API.

I am 100% sure there is a serial port available. On Debian, I can see /dev/ttyUSB3 exists when the device is connected.

Tried running getPortIdentifiers() and got nothing when I tried iterating over the hashset

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

Also did not work. I got:

Exception Caused by: gnu.io.NoSuchPortException

What am I doing wrong? I am fairly sure rxtx was set up correctly.

The problem here is with how RXTX defines ports. By default, it will only look for certain serial ports(on Linux, /dev/ttySX ). There are several options you have to fix this:

  1. Set the gnu.io.rxtx.SerialPorts property when you start Java(either on the command line, or through code. See the Rxtx documentation for more details)
  2. Use a different serial port library that lets you select serial ports manually.

For #2, the following are libraries that I know of:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM