Solved open(QIODevice::ReadWrite) fails with QSerialPort::UnsupportedOperationError (10)
-
Hello everyone,
I am new to Qt.
I am getting this error: QSerialPort::UnsupportedOperationError (10) when I try to open the serial port .
Below is the code snippet where I am seeing the error:
Header file:
typedef struct { QString data; QSerialPort::BaudRate baudRate; } struct_BaudRate; const struct_BaudRate baudRates[7] = { {" " , QSerialPort::UnknownBaud}, {"9600" , QSerialPort::Baud9600}, {"19200" , QSerialPort::Baud19200}, {"38400" , QSerialPort::Baud38400}, {"57600" , QSerialPort::Baud57600}, {"115200", QSerialPort::Baud115200}, {"Custom", QSerialPort::UnknownBaud} }; typedef struct { QString data; QSerialPort::DataBits dataBits; } struct_DataBits; const struct_DataBits dataBits[4] = { {"5", QSerialPort::Data5}, {"6", QSerialPort::Data6}, {"7", QSerialPort::Data7}, {"8", QSerialPort::Data8}, }; typedef struct { QString data; QSerialPort::Parity Parity; } struct_Parity; const struct_Parity parity[5] = { {"None" , QSerialPort::NoParity}, {"Even" , QSerialPort::EvenParity}, {"Odd" , QSerialPort::OddParity}, {"Mark" , QSerialPort::MarkParity}, {"Space", QSerialPort::SpaceParity} }; typedef struct { QString data; QSerialPort::StopBits StopBits; } struct_StopBits; const struct_StopBits stopBits[3] = { {"1", QSerialPort::OneStop}, {"1.5", QSerialPort::OneAndHalfStop}, {"2", QSerialPort::TwoStop} }; typedef struct { QString data; QSerialPort::FlowControl FlowControl; } struct_FlowControl; const struct_FlowControl flowControl[3] = { {"None", QSerialPort::NoFlowControl}, {"RTS/CTS", QSerialPort::HardwareControl}, {"XON/XOFF", QSerialPort::SoftwareControl} }; typedef struct { QString Port; QString Description; QString Manufacturer; QString SerialNum; QString Location; QString VendorID; QString ProductID; }struct_COMDetails;
openSerialPort():
void MainWindow::openSerialPort() { serialData = new QSerialPort(); serialData->setPortName(ui->combo_commPort->currentText()); serialData->setBaudRate(static_cast<QSerialPort::BaudRate>(baudRates[ui->combo_BaudRate->currentIndex()].baudRate)); serialData->setDataBits(static_cast<QSerialPort::DataBits>(dataBits[ui->combo_DataBits->currentIndex()].dataBits)); serialData->setParity(static_cast<QSerialPort::Parity>(parity[ui->combo_Parity->currentIndex()].Parity)); serialData->setStopBits(static_cast<QSerialPort::StopBits>(stopBits[ui->combo_StopBits->currentIndex()].StopBits)); serialData->setFlowControl(static_cast<QSerialPort::FlowControl>(flowControl[ui->combo_FlowControl->currentIndex()].FlowControl)); if (serialData->open(QIODevice::ReadWrite)) { ui->button_connect->setDisabled(true); } else { QSerialPort::SerialPortError strTempError = serialData->error(); QMessageBox::critical(this, tr("Error"), serialData->errorString()); }
-
This problem is solved now.
It was my mistake in giving incorrect index for Baud rates and other attributes.I will be closing this topic.
-
@PradeepCK said in open(QIODevice::ReadWrite) fails with QSerialPort::UnsupportedOperationError (10):
typedef struct {
QString data;
QSerialPort::BaudRate baudRate;
} struct_BaudRate;
const struct_BaudRate baudRates[7] = {
{" " , QSerialPort::UnknownBaud},
{"9600" , QSerialPort::Baud9600},
{"19200" , QSerialPort::Baud19200},
{"38400" , QSerialPort::Baud38400},
{"57600" , QSerialPort::Baud57600},
{"115200", QSerialPort::Baud115200},
{"Custom", QSerialPort::UnknownBaud}
};Just in case, you may want to use QComboBox::itemData to avoid defining structs/arrays that hold values (i.e. baud rate) related to every item in the combo list.