correct disconnect
This commit is contained in:
@@ -154,19 +154,21 @@ void MainWindows::onStateChanged(QModbusDevice::State state) {
|
||||
|
||||
void MainWindows::onConnectButtonClicked() {
|
||||
if (!m_connected) {
|
||||
m_disconnectRequested = false;
|
||||
if (!m_modbusClient->connectDevice()) {
|
||||
QMessageBox::critical(this, tr("Connection Error"),
|
||||
tr("Could not connect to the Modbus device!"));
|
||||
}
|
||||
// Start connection timeout timer
|
||||
QTimer::singleShot(m_connectTimeout, this, [this]() {
|
||||
if (!m_connected) {
|
||||
if (!m_connected && !m_disconnectRequested) {
|
||||
m_modbusClient->disconnectDevice();
|
||||
QMessageBox::warning(this, tr("Connection Timeout"),
|
||||
tr("Connection attempt timed out!"));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
m_disconnectRequested = true;
|
||||
m_modbusClient->disconnectDevice();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user