From 49b25f0a86d77be2a8127536c54923e1a5b9ee8e Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Fri, 14 Apr 2023 10:18:29 -0400 Subject: [PATCH] close the port under certain error conditions --- platform/qt/dmxwidget/dmxwidget.cpp | 20 ++++++++++++++++++++ platform/qt/dmxwidget/dmxwidget.h | 1 + 2 files changed, 21 insertions(+) diff --git a/platform/qt/dmxwidget/dmxwidget.cpp b/platform/qt/dmxwidget/dmxwidget.cpp index 23a8bc8..e9185d6 100644 --- a/platform/qt/dmxwidget/dmxwidget.cpp +++ b/platform/qt/dmxwidget/dmxwidget.cpp @@ -28,6 +28,7 @@ DmxWidget::DmxWidget(QObject *parent) , port_(new QSerialPort(this)) { connect(this, &DmxWidget::serialDataRead, this, &DmxWidget::parseMessageBuffer); + connect(port_, &QSerialPort::errorOccurred, this, &DmxWidget::serialErrorOccured); } @@ -159,6 +160,25 @@ void DmxWidget::sendMessage(std::shared_ptr msg) const } +/** + * @brief DmxWidget::serialErrorOccured + * @param error + */ +void DmxWidget::serialErrorOccured(QSerialPort::SerialPortError error) +{ + switch (error) { + case QSerialPort::WriteError: + case QSerialPort::ReadError: + case QSerialPort::ResourceError: + case QSerialPort::TimeoutError: + close(); + break; + default: + break; + } +} + + /** * @brief DmxWidget::availableWidgets * @return diff --git a/platform/qt/dmxwidget/dmxwidget.h b/platform/qt/dmxwidget/dmxwidget.h index 159f0b0..a7b9474 100644 --- a/platform/qt/dmxwidget/dmxwidget.h +++ b/platform/qt/dmxwidget/dmxwidget.h @@ -77,6 +77,7 @@ private: private slots: void parseMessageBuffer(); + void serialErrorOccured(QSerialPort::SerialPortError); }; Q_DECLARE_OPERATORS_FOR_FLAGS(DmxWidget::RxErrors)