Qt - serial port name in ubuntu

风格不统一 提交于 2019-12-10 20:19:51

问题


I have a problem with finding the serial port name on Ubuntu. As you know, for reading serial port on Windows, we can use this code for example:

serial->setPortName("com3");

but when I compile this code on Ubuntu, I can't use this code:

serial->setPortName("/dev/ttyACM0");

I know that my serial port name is ttyACM0 and I can read data on it by issuing this command:

cat /dev/ttyACM0

but why cannot I use this name in my code? What should I do?


回答1:


In order to get permission for your regular user, please get your sysadmin add to the group that is in charge of the serial ports like that emulated over usb.

It is either tty, uucp or something. It varies from distribution to distribution, but you can easily check this by running the following command:

ls -l /dev/ttyACM0

Then check the group column and get the sysadmin do this:

sudo usermod -a -G group username

Please do not introduce security vulnerabilities by giving global write access to others like this:

sudo chmod 666 /dev/ttyACM0



回答2:


Use:

serial->setPortName("ttyACM0");


来源:https://stackoverflow.com/questions/26314120/qt-serial-port-name-in-ubuntu

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