问题
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