diff options
author | Karsten Heimrich <karsten.heimrich@theqtcompany.com> | 2016-03-01 14:27:07 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@theqtcompany.com> | 2016-03-01 14:23:34 +0000 |
commit | e40343337940705ceb830f9f20a09084185ab198 (patch) | |
tree | 4e02bcafa5bb1b0b1b2d0c98fe9244b3b60e2967 /src/serialbus/qmodbusrtuserialmaster_p.h | |
parent | 75dbf60352157085f106faf88e89e97288217ae2 (diff) |
Move clearing or updating values into a common function.
Change-Id: I25ee09e5fe70464048500dc4d376d4e38805ca50
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/serialbus/qmodbusrtuserialmaster_p.h')
-rw-r--r-- | src/serialbus/qmodbusrtuserialmaster_p.h | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/serialbus/qmodbusrtuserialmaster_p.h b/src/serialbus/qmodbusrtuserialmaster_p.h index 9517777..c3b1b5a 100644 --- a/src/serialbus/qmodbusrtuserialmaster_p.h +++ b/src/serialbus/qmodbusrtuserialmaster_p.h @@ -218,32 +218,38 @@ public: Q_Q(QModbusRtuSerialMaster); if (q->state() != QModbusDevice::ClosingState) q->close(); + m_sendTimer.stop(); + m_responseTimer.stop(); }); } - void updateSerialPortConnectionInfo() { + void setupEnvironment() { if (m_serialPort) { + m_serialPort->clear(); m_serialPort->setPortName(m_comPort); m_serialPort->setParity(m_parity); m_serialPort->setBaudRate(m_baudRate); m_serialPort->setDataBits(m_dataBits); m_serialPort->setStopBits(m_stopBits); + } - // According to the Modbus specification, in RTU mode message frames - // are separated by a silent interval of at least 3.5 character times. - // Calculate the timeout if we are less than 19200 baud, use a fixed - // timeout for everything equal or greater than 19200 baud. - if (m_baudRate < 19200) { - // Example: 9600 baud, 11 bit per packet -> 872 char/sec - // so: 1000 ms / 872 char = 1.147 ms/char * 3.5 character - // Always round up because the spec requests at least 3.5 char. - m_timeoutThreeDotFiveMs = qCeil(3500. / (qreal(m_baudRate) / 11.)); - } else { - // The spec recommends a timeout value of 1.750 msec. Without such - // precise single-shot timers use a approximated value of 1.750 msec. - m_timeoutThreeDotFiveMs = 2; - } + // According to the Modbus specification, in RTU mode message frames + // are separated by a silent interval of at least 3.5 character times. + // Calculate the timeout if we are less than 19200 baud, use a fixed + // timeout for everything equal or greater than 19200 baud. + if (m_baudRate < 19200) { + // Example: 9600 baud, 11 bit per packet -> 872 char/sec + // so: 1000 ms / 872 char = 1.147 ms/char * 3.5 character + // Always round up because the spec requests at least 3.5 char. + m_timeoutThreeDotFiveMs = qCeil(3500. / (qreal(m_baudRate) / 11.)); + } else { + // The spec recommends a timeout value of 1.750 msec. Without such + // precise single-shot timers use a approximated value of 1.750 msec. + m_timeoutThreeDotFiveMs = 2; } + + responseBuffer.clear(); + m_state = QModbusRtuSerialMasterPrivate::Idle; } void scheduleNextRequest() { |