Chris L. Chris L. - 4 months ago 57
Linux Question

QSerialPort Error: Device Not Open

I have a Qt application that I am attempting to build on Linux. I have a FTDI device that I want to interact with using the Qt application I have made, however I keep getting an error message that the device failed to open. I have checked whether the device is connected to the PC and it is connected given that I can retrieve the serial number, device description, etc. from the device. I have also tried this on Windows and it works without a problem, only Linux.

Here's my code by the way:

foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
{
if(info.description() != "")
{
QSerialPort *serial = new QSerialPort(info);
serial -> setPortName(info.portName());

if (!serial->open(QIODevice::ReadWrite)) {
std::cout << "Fail to open device" << std::endl;
}

serial -> setDataBits(QSerialPort::Data8);
serial -> setStopBits(QSerialPort::OneStop);
serial -> setParity(QSerialPort::NoParity);

}
}

Answer

Add yourself to the dialout group:

sudo usermod -a -G dialout YOURUSERNAME

or

sudo adduser YOURUSERNAME dialout

Then logout and login again to take affect.