mirror of
https://github.com/nymea/nymea-plugins.git
synced 2026-10-25 14:02:37 +01: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);
|
m_serialPort->setFlowControl(QSerialPort::FlowControl::NoFlowControl);
|
||||||
|
|
||||||
connect(m_serialPort, &QSerialPort::readyRead, this, &OwletSerialTransport::onReadyRead);
|
connect(m_serialPort, &QSerialPort::readyRead, this, &OwletSerialTransport::onReadyRead);
|
||||||
typedef void (QSerialPort:: *errorSignal)(QSerialPort::SerialPortError);
|
#if QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
|
||||||
connect(m_serialPort, static_cast<errorSignal>(&QSerialPort::error), this, [=](){
|
// NOTE: Using QueuedConnection because in older Qt versions error is emitted before the port says its closed which might end up in a loop...
|
||||||
if (m_serialPort->error() != QSerialPort::NoError) {
|
connect(m_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onError(QSerialPort::SerialPortError)), Qt::QueuedConnection);
|
||||||
qCWarning(dcOwlet()) << "Serial port error occured" << m_serialPort->error() << m_serialPort->errorString();
|
#else
|
||||||
emit error();
|
connect(m_serialPort, &QSerialPort::errorOccurred, this, &OwletSerialTransport::onError);
|
||||||
m_reconnectTimer->start();
|
#endif
|
||||||
if (m_serialPort->isOpen()) {
|
|
||||||
m_serialPort->close();
|
|
||||||
}
|
|
||||||
emit connectedChanged(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_reconnectTimer = new QTimer(this);
|
m_reconnectTimer = new QTimer(this);
|
||||||
m_reconnectTimer->setInterval(5000);
|
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:
|
private slots:
|
||||||
void onReadyRead();
|
void onReadyRead();
|
||||||
|
void onError(QSerialPort::SerialPortError serialPortError);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user