PDA

View Full Version : Permission error while locking the device when writing to QSerialPort



Cazzaniga
29th June 2018, 09:22
Hi,
I'm working on a Qt5.7 application cross-compiled for my device. I added the serialport module to read and write to the serialport.
After opening the QSerialPort, when I try to write to it, the following error message (attached to the thread) appears in the GUI: "Permission error while locking the device", and the message is not sent to the serial port.
This is the way I open and try to write to the serial port:


serialport->setPortName("/dev/ttymxc2");
serialport->setBaudRate(QSerialPort::Baud9600);
serialport->setDataBits(QSerialPort::Data8);
serialport->setParity(QSerialPort::NoParity);
serialport->setStopBits(QSerialPort::OneStop);
serialport->setFlowControl(QSerialPort::NoFlowControl);
//serial->setFlowControl(QSerialPort::HardwareControl);
if (serialport->open(QIODevice::ReadWrite))
//opened
...

The write section:


QByteArray ba;
ba.resize(50);
...
const qint64 bytesWritten = serialport->write(ba);


Could anyone help to find the solution? What am I missing?
Thank you!

Lesiok
29th June 2018, 11:24
Try in system console this command : ls /dev/tty*
Here is output from my system :
crw-rw-rw- 1 root tty 5, 0 06-01 22:06 /dev/tty
crw--w---- 1 root tty 4, 0 06-01 22:06 /dev/tty0
crw------- 1 root root 4, 1 06-01 22:08 /dev/tty1
crw--w---- 1 root tty 4, 10 06-01 22:06 /dev/tty10
crw--w---- 1 root tty 4, 11 06-01 22:06 /dev/tty11
crw--w---- 1 root tty 4, 12 06-01 22:06 /dev/tty12As You see only root and tty group have permision to use tty devices.
A problem with system configuration not with application.