Cannot open any (linux) serial ports
-
The attached code "finds" three kinds of serial ports but fails to open any.
Are the port names valid ?
Did I missed something in my code ?"ttyACM0"
"ttyUSB0"
"ttyS0"QString text; QSerialPortInfo info; QList<QSerialPortInfo> portList; QSerialPort serial; QElapsedTimer timer; BT_Utility_Library *BTUL = new BT_Utility_Library(); ui->listWidget_3->clear(); text = "Scan for avaiable serial ports "; BTUL->FLOWCHART( text , Q_FUNC_INFO, ui->listWidget_3, __LINE__ ); portList = info.availablePorts(); for(int i=0;i<portList.size();i++) { ui->listWidget_3->addItem(portList[i].portName()); text = portList[i].portName(); BTUL->FLOWCHART( text , Q_FUNC_INFO, ui->listWidget_3, __LINE__ ); } // try open all serial ports for(int i=0;i<portList.size();i++) { serial.setPortName(portList[i].portName() ); text = "serial port "; text += portList[i].portName() ; if(serial.open(QIODevice::ReadWrite)) { text += " open OK " ; } else { text += " ! FAILED to open"; } BTUL->FLOWCHART( text , Q_FUNC_INFO, ui->listWidget_3, __LINE__ ); } return;
-
This post is deleted!
-
Hi,
Yes they are valid.
What is likely happening is that your user may not be allowed to use them. You should check the groups it belongs to and see if the list contains the group that can access these devices.
-
@AnneRanch
When they fail to open try outputting https://doc.qt.io/qt-5/qserialport.html#error-prop,serial.error()
.This property holds the error status of the serial port
The I/O device status returns an error code. For example, if
open()
returns false, or a read/write operation returns -1, this property can be used to figure out the reason why the operation failed.Maybe it's reporting
QSerialPort::PermissionError
or others from https://doc.qt.io/qt-5/qserialport.html#SerialPortError-enum. https://doc.qt.io/qt-5/qiodevice.html#errorString,serial.errorString()
may have the text. -
Perfect group participation solution - getting "Permission denied " error.
THANKS