-->

CommPortIdentifier.getPortIdentifiers with zero po

2020-03-28 02:29发布

问题:

i am trying to connect serial port on ubuntu. However, It doesn't work for me. I succesfully run the same project on Windows just with different drivers. The problem is that I can't load any ports while I am using this:

CommPortIdentifier.getPortIdentifiers(); // i am using rxtx 2.1.7

It always return zero ports. I would like to use port ttyS0 whichworks great with minicon so i am sure that port is not blocked and the machine is not broken.

Anyone has a reason for this ?

回答1:

It was just becouse low priviligies. I had to add myself to a group which is supposed to work with ttyS0.



回答2:

I used this command

sudo chmod 666 /dev/ttyUSB0

I had the same problem and it worked the moment after I used this command. Like Smolda said, it is a permission problem.



回答3:

if nothing helps, you should consider to add this line to your java code:

System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/yourtty");

did it for me. (Only if you work with the RXTX library)



标签: java linux rxtx