[SOLVED] QSerialPort fails opening with "File exists" error message
-
Hi all,
I am developing a custom embedded device. This device runs Buildroot linux with Qt 5.3. It features an AVR-MCU (Arduino 1284p) that is connected to the main processor (that runs Linux and Qt) via a serial connection (RX, TX). The Arduino-MCU simple reads the serial port for commands, executes them (i.e. read temperature sensor) and prints the result.
In the linux shell I can run cat /dev/ttyS3 to read the data the Arduino has written and I can send bytes by calling echo 'Hello Arduino' >> /dev/ttyS3 for example. That works fine.
If I want to use QSerialPort by calling:
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) qDebug() << info.portName(); m_serialPort = new QSerialPort("ttyS3"); m_serialPort->setBaudRate(QSerialPort::Baud9600); m_serialPort->setFlowControl(QSerialPort::NoFlowControl); m_serialPort->setParity(QSerialPort::NoParity); m_serialPort->setDataBits(QSerialPort::Data8); m_serialPort->setStopBits(QSerialPort::OneStop); if (m_serialPort->open(QIODevice::ReadWrite)) { qDebug() << "Serial Port opened ttyS3"; this->connect(m_serialPort,SIGNAL(readyRead()),SLOT(serialDataReceived())); } else { qDebug() << "Failed to open ttyS3 serial port"; qDebug() << m_serialPort->errorString(); qDebug() << m_serialPort->error(); }
I receive the error message "File exists" (errorString) and the error-ID is 2. I am running the Qt application as root. http://superuser.com/questions/569255/how-to-quickly-determine-which-process-if-any-listens-to-a-serial-port lists a few linux commands that identify the process that has the serial port in use. Non of the examples (lsof /dev/ttyS3 nor fuser -n file /dev/ttyS3) lists a process. So I am pretty sure the serial port is not in use.
If I try the source code with ttyS2 everything works fine (besides the fact that nothing useful is connected to ttyS2 of course ;-)).
Anyone has an idea what's going wrong?
Thanks a lot.
Phillip -
Hi and welcome to devnet,
Just an idea: did you check the permissions on /dev/ttyS3 ?
-
Most likely that "File exists" goes from the tty-locker (from QLockFile), because the ttyS3-lock file exists. It is probable that this issue belongs to this bug: https://bugreports.qt.io/browse/QTBUG-36983
So, you can:
- Try to use a latest version of QtSerialPort
- Just find out the lock-file and to remove it before opening.
- That is better - it is do not start the application with a root privileges. You should try to create an user, and to add his to "dialout" grop or similar (depends on your base distro).