CommPortIdentifier.getPortIdentifiers with zero ports on Linux

最后都变了- 提交于 2019-12-01 11:36:56

问题


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:


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)




回答3:


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.



来源:https://stackoverflow.com/questions/11790811/commportidentifier-getportidentifiers-with-zero-ports-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!