Skip to content

Commit

Permalink
Ignore UnknownError when syncing DTR/RTS state
Browse files Browse the repository at this point in the history
Fixes #60
  • Loading branch information
wh201906 committed Apr 7, 2024
1 parent 0e5c82e commit cae854b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1108,6 +1112,16 @@ bool Connection::SP_setFlowControl(QSerialPort::FlowControl flowControl)
return true;
}

void Connection::SP_setIgnoredErrorList(const QList<QSerialPort::SerialPortError> &errorList)
{
m_SP_ignoredErrorList = errorList;
}

QList<QSerialPort::SerialPortError> Connection::SP_getIgnoredErrorList()
{
return m_SP_ignoredErrorList;
}

QString Connection::BT_remoteName()
{
if(m_type == BT_Client && m_BTSocket != nullptr)
Expand Down
3 changes: 3 additions & 0 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QSerialPort::SerialPortError>& errorList);
QList<QSerialPort::SerialPortError> SP_getIgnoredErrorList();

// Bluetooth
QString BT_remoteName();
Expand Down Expand Up @@ -196,6 +198,7 @@ public slots:

//
QSerialPort::PinoutSignals m_SP_lastSignals;
QList<QSerialPort::SerialPortError> m_SP_ignoredErrorList;

QByteArray m_buf;

Expand Down
11 changes: 11 additions & 0 deletions src/datatab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit cae854b

Please sign in to comment.