解决Ubuntu20.04上Qt串口通信 QSerialPort 打开失败的问题
运行Qt串口通信 open(QIODevice::ReadWrite) 时,总是失败。
1、打印失败原因
QString QSerialHelper::openSerail()
{if(this->open(QIODevice::ReadWrite) == true){return this->portName();}else{return "打开失败";//return this->errorString();}
}
错误信息:Permission denied
串口权限设置
将当前用户加入到 dialout 用户组,并重启系统。
2、查看串口信息
ls -l /dev/ttyUSB0
输出:
3、查看当前用户名
whoami
输出:
4、当前用户加入到dialout用户组
sudo usermod -aG dialout username
5、最后重启系统(重要)
shutdown -r now