summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@theqtcompany.com>2016-03-14 10:36:39 +0100
committerKarsten Heimrich <karsten.heimrich@theqtcompany.com>2016-03-15 09:00:00 +0000
commited4f07584064f0cae3321cdec5272c85912a90e3 (patch)
treee9c378f14545c07bbaf28d55cfb9749cfaaaf004 /src
parent4a5ce24c6452ce2d141cd7bf9a2f46efe45ddb0b (diff)
Fix serial line access order. Unbreaks serial line connect.
Fix issues introduced by commit e40343337940705ceb830f9f20a: * Setup the serial line environment before open, calls after open will not change the the values until reconnect. * Calling clear on an closed port will set and emit an error, successive calls to open() will fail because of how the error signal is received. Even though the error was set before the successful open, the signal is delivered after the open call and and so we close the connection again. Change-Id: Ic694e9d144c24bf94c4e94e5483aaddcc4c664a5 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/serialbus/qmodbusrtuserialmaster.cpp3
-rw-r--r--src/serialbus/qmodbusrtuserialmaster_p.h1
-rw-r--r--src/serialbus/qmodbusrtuserialslave.cpp3
-rw-r--r--src/serialbus/qmodbusrtuserialslave_p.h1
4 files changed, 4 insertions, 4 deletions
diff --git a/src/serialbus/qmodbusrtuserialmaster.cpp b/src/serialbus/qmodbusrtuserialmaster.cpp
index afdcac9..c646ee7 100644
--- a/src/serialbus/qmodbusrtuserialmaster.cpp
+++ b/src/serialbus/qmodbusrtuserialmaster.cpp
@@ -97,9 +97,10 @@ bool QModbusRtuSerialMaster::open()
return true;
Q_D(QModbusRtuSerialMaster);
+ d->setupEnvironment(); // to be done before open
if (d->m_serialPort->open(QIODevice::ReadWrite)) {
- d->setupEnvironment();
setState(QModbusDevice::ConnectedState);
+ d->m_serialPort->clear(); // only possible after open
} else {
setError(d->m_serialPort->errorString(), QModbusDevice::ConnectionError);
}
diff --git a/src/serialbus/qmodbusrtuserialmaster_p.h b/src/serialbus/qmodbusrtuserialmaster_p.h
index c3b1b5a..022c902 100644
--- a/src/serialbus/qmodbusrtuserialmaster_p.h
+++ b/src/serialbus/qmodbusrtuserialmaster_p.h
@@ -225,7 +225,6 @@ public:
void setupEnvironment() {
if (m_serialPort) {
- m_serialPort->clear();
m_serialPort->setPortName(m_comPort);
m_serialPort->setParity(m_parity);
m_serialPort->setBaudRate(m_baudRate);
diff --git a/src/serialbus/qmodbusrtuserialslave.cpp b/src/serialbus/qmodbusrtuserialslave.cpp
index 718d739..644ad07 100644
--- a/src/serialbus/qmodbusrtuserialslave.cpp
+++ b/src/serialbus/qmodbusrtuserialslave.cpp
@@ -107,9 +107,10 @@ bool QModbusRtuSerialSlave::open()
return true;
Q_D(QModbusRtuSerialSlave);
+ d->setupEnvironment(); // to be done before open
if (d->m_serialPort->open(QIODevice::ReadWrite)) {
- d->setupEnvironment();
setState(QModbusDevice::ConnectedState);
+ d->m_serialPort->clear(); // only possible after open
} else {
setError(d->m_serialPort->errorString(), QModbusDevice::ConnectionError);
}
diff --git a/src/serialbus/qmodbusrtuserialslave_p.h b/src/serialbus/qmodbusrtuserialslave_p.h
index 213572c..4c5f885 100644
--- a/src/serialbus/qmodbusrtuserialslave_p.h
+++ b/src/serialbus/qmodbusrtuserialslave_p.h
@@ -323,7 +323,6 @@ public:
void setupEnvironment() {
if (m_serialPort) {
- m_serialPort->clear();
m_serialPort->setPortName(m_comPort);
m_serialPort->setParity(m_parity);
m_serialPort->setBaudRate(m_baudRate);