From cae854bcdd0fa45a08e0056b7098a8802a786d2c Mon Sep 17 00:00:00 2001 From: wh201906 Date: Mon, 8 Apr 2024 01:09:39 +0800 Subject: [PATCH] Ignore UnknownError when syncing DTR/RTS state Fixes #60 --- src/connection.cpp | 16 +++++++++++++++- src/connection.h | 3 +++ src/datatab.cpp | 11 +++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/connection.cpp b/src/connection.cpp index 0da736d..52cb22c 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -605,8 +605,12 @@ void Connection::onErrorOccurred() m_errorStringList += m_serialPort->errorString(); qDebug() << "SerialPort Error:" << error << m_serialPort->errorString(); + if(m_SP_ignoredErrorList.contains(error)) + { + qDebug() << error << "ignored"; + } // no error - if(error == QSerialPort::NoError) + else if(error == QSerialPort::NoError) ; // serialport still works else if(error == QSerialPort::FramingError || error == QSerialPort::ParityError || error == QSerialPort::BreakConditionError || error == QSerialPort::UnsupportedOperationError || error == QSerialPort::TimeoutError || error == QSerialPort::ReadError || error == QSerialPort::WriteError) @@ -1108,6 +1112,16 @@ bool Connection::SP_setFlowControl(QSerialPort::FlowControl flowControl) return true; } +void Connection::SP_setIgnoredErrorList(const QList &errorList) +{ + m_SP_ignoredErrorList = errorList; +} + +QList Connection::SP_getIgnoredErrorList() +{ + return m_SP_ignoredErrorList; +} + QString Connection::BT_remoteName() { if(m_type == BT_Client && m_BTSocket != nullptr) diff --git a/src/connection.h b/src/connection.h index 4853bb2..b27cfaa 100644 --- a/src/connection.h +++ b/src/connection.h @@ -118,6 +118,8 @@ class Connection : public QObject bool SP_setStopBits(QSerialPort::StopBits stopBits); bool SP_setParity(QSerialPort::Parity parity); bool SP_setFlowControl(QSerialPort::FlowControl flowControl); + void SP_setIgnoredErrorList(const QList& errorList); + QList SP_getIgnoredErrorList(); // Bluetooth QString BT_remoteName(); @@ -196,6 +198,7 @@ public slots: // QSerialPort::PinoutSignals m_SP_lastSignals; + QList m_SP_ignoredErrorList; QByteArray m_buf; diff --git a/src/datatab.cpp b/src/datatab.cpp index d98980a..84a91fb 100644 --- a/src/datatab.cpp +++ b/src/datatab.cpp @@ -426,10 +426,21 @@ void DataTab::onConnEstablished() // ui->data_flowDTRBox->setChecked(m_connection->SP_isDataTerminalReady()); // sync states from UI to serial + // + // Some devices, such as Quectel EC200U/EC600U/EG912U, may not support getting or setting the DTR/RTS signals. + // When attempting these operations on such devices, they may report QSerialPort::UnknownError instead of QSerialPort::UnsupportedOperationError. + // This can cause the Connection class to close the device unexpectedly. + // These errors should be ignored when syncing the DTR/RTS state with the device. + + const auto oldErrorList = m_connection->SP_getIgnoredErrorList(); + auto errorList = oldErrorList; + errorList.append(QSerialPort::UnknownError); + m_connection->SP_setIgnoredErrorList(errorList); if(ui->data_flowDTRBox->isChecked() != m_connection->SP_isDataTerminalReady()) on_data_flowDTRBox_clicked(ui->data_flowDTRBox->isChecked()); if(ui->data_flowRTSBox->isChecked() != m_connection->SP_isRequestToSend()) on_data_flowRTSBox_clicked(ui->data_flowRTSBox->isChecked()); + m_connection->SP_setIgnoredErrorList(oldErrorList); } }