简体   繁体   English

Qt - ubuntu中的串口名称

[英]Qt - serial port name in ubuntu

I have a problem with finding the serial port name on Ubuntu. 我在Ubuntu上找到串口名称时遇到问题。 As you know, for reading serial port on Windows, we can use this code for example: 如您所知,为了在Windows上读取串行端口,我们可以使用此代码作为示例:

serial->setPortName("com3");

but when I compile this code on Ubuntu, I can't use this code: 但是当我在Ubuntu上编译这段代码时,我无法使用这段代码:

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

I know that my serial port name is ttyACM0 and I can read data on it by issuing this command: 我知道我的串口名是ttyACM0,我可以通过发出以下命令来读取它的数据:

cat /dev/ttyACM0

but why cannot I use this name in my code? 但为什么我不能在我的代码中使用此名称? What should I do? 我该怎么办?

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. 为了获得普通用户的许可,请将您的系统管理员添加到负责串口的组中,例如通过USB模拟的串口。

It is either tty , uucp or something. 它是ttyuucp或者其他东西。 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: 然后检查组列并获取sysadmin执行此操作:

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

使用:

serial->setPortName("ttyACM0");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM