mirror of
https://github.com/nymea/nymea-plugins.git
synced 2026-08-02 03:07:33 +02:00
Make error signal depending on the Qt version
This commit is contained in:
parent
3c1fd0d7ca
commit
9878a0c18c
@ -20,18 +20,13 @@ OwletSerialTransport::OwletSerialTransport(const QString &serialPortName, uint b
|
||||
m_serialPort->setFlowControl(QSerialPort::FlowControl::NoFlowControl);
|
||||
|
||||
connect(m_serialPort, &QSerialPort::readyRead, this, &OwletSerialTransport::onReadyRead);
|
||||
typedef void (QSerialPort:: *errorSignal)(QSerialPort::SerialPortError);
|
||||
connect(m_serialPort, static_cast<errorSignal>(&QSerialPort::error), this, [=](){
|
||||
if (m_serialPort->error() != QSerialPort::NoError) {
|
||||
qCWarning(dcOwlet()) << "Serial port error occured" << m_serialPort->error() << m_serialPort->errorString();
|
||||
emit error();
|
||||
m_reconnectTimer->start();
|
||||
if (m_serialPort->isOpen()) {
|
||||
m_serialPort->close();
|
||||
}
|
||||
emit connectedChanged(false);
|
||||
}
|
||||
});
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
|
||||
// NOTE: Using QueuedConnection because in older Qt versions error is emitted before the port says its closed which might end up in a loop...
|
||||
connect(m_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onError(QSerialPort::SerialPortError)), Qt::QueuedConnection);
|
||||
#else
|
||||
connect(m_serialPort, &QSerialPort::errorOccurred, this, &OwletSerialTransport::onError);
|
||||
#endif
|
||||
|
||||
|
||||
m_reconnectTimer = new QTimer(this);
|
||||
m_reconnectTimer->setInterval(5000);
|
||||
@ -167,3 +162,16 @@ void OwletSerialTransport::onReadyRead()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OwletSerialTransport::onError(QSerialPort::SerialPortError serialPortError)
|
||||
{
|
||||
if (serialPortError != QSerialPort::NoError && serialPortError != QSerialPort::OpenError && m_serialPort->isOpen()) {
|
||||
qCWarning(dcOwlet()) << "Serial port error occured" << serialPortError << m_serialPort->errorString();
|
||||
emit error();
|
||||
m_reconnectTimer->start();
|
||||
if (m_serialPort->isOpen()) {
|
||||
m_serialPort->close();
|
||||
}
|
||||
emit connectedChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void onReadyRead();
|
||||
void onError(QSerialPort::SerialPortError serialPortError);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user