CommPortIdentifier.getPortIdentifiers with zero po

2020-03-28 02:27发布

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 ?

标签: java linux rxtx
3条回答
祖国的老花朵
2楼-- · 2020-03-28 02:52

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楼-- · 2020-03-28 02:54

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)

查看更多
何必那么认真
4楼-- · 2020-03-28 03:06

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

查看更多
登录 后发表回答