close the port under certain error conditions

This commit is contained in:
Kevin Matz 2023-04-14 10:18:29 -04:00
parent 379ae89cb6
commit 49b25f0a86
2 changed files with 21 additions and 0 deletions

View File

@ -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<ENTTEC::Pro::MessageData> 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

View File

@ -77,6 +77,7 @@ private:
private slots:
void parseMessageBuffer();
void serialErrorOccured(QSerialPort::SerialPortError);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(DmxWidget::RxErrors)