summaryrefslogtreecommitdiffstats
path: root/src/serialbus/qmodbusrtuserialmaster_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Rename and deprecate QModbusRtuSerialSlave and QModbusRtuSerialMasterKarsten Heimrich2021-03-021-424/+0
| | | | | | | | | | This change follows the recommendation announced by the Modbus organization in the press release of July 9th, 2020. Task-number: QTBUG-91213 Change-Id: Id946eea900b620a7f021caa30ae40e3f0b0c3dc4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Allow setting the RTU inter frame delay on slaves as wellKarsten Heimrich2021-01-291-24/+0
| | | | | | Fixes: QTBUG-89995 Change-Id: I401d2511b336367801d941ec1f5e06cc4cd6cd08 Reviewed-by: André Hartmann <aha_1980@gmx.de>
* Add ; to Q_UNUSEDLars Schmertmann2020-12-201-1/+1
| | | | | | | | This is required to remove the ; from the macro with Qt 6. Task-number: QTBUG-82978 Change-Id: I76cbcea127f326d61bfb9420e4afe0b260a3f190 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Report intermediate errors while in a Modbus send/receive cycleKarsten Heimrich2020-04-211-1/+3
| | | | | | Task-number: QTBUG-79312 Change-Id: Iec1f9a0427bd04ebb8ceb4c66ece96e443092a6e Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Remove usages of deprecated APIsSona Kurazyan2019-08-061-1/+1
| | | | | | | | | Replace QSerialPort::error(QSerialPort::SerialPortError) with QSerialPort::errorOccurred(QSerialPort::SerialPortError). Task-number: QTBUG-76491 Change-Id: Ic1d0a9ff89d346eca6cd2fd448cc02360c5e8783 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Expose the underling QIODevice used for Modbus communicationKarsten Heimrich2019-06-071-0/+2
| | | | | | | | | | | Sometimes it is necessary to get the device to set some special option on the device, like setting the HW flow control (RTS/CTS) parameters on the QSerialPort etc. Task-number: QTBUG-75405 Task-number: QTBUG-76232 Change-Id: I20e4824dcb8bde7020972607c6a76a01a5d01fc1 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Implement handling for sending Modbus RTU broadcast requestsKarsten Heimrich2019-04-011-9/+17
| | | | | | | | | | Introduces some methods to set the turnaround delay between a Modbus broadcast message and a following Modbus message. More details can be found in the Modbus_over_serial_line_V1.pdf spec at page 10. Change-Id: Iddeb7247566663facb79032135c1e4cc2434ca4f Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Rewrite RTU master state machineKarsten Heimrich2019-04-011-136/+135
| | | | | | | Task-number: QTBUG-73965 Task-number: QTBUG-73230 Change-Id: I4e4b201b172d32802ce934f111631279dc7157e1 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Move lambda code into separate functionsKarsten Heimrich2019-04-011-132/+155
| | | | | Change-Id: I259175817d5767c7cf24c6f04f4faae190f773ed Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Fix typosKarsten Heimrich2019-03-211-1/+1
| | | | | | Change-Id: Ic7f032217e641bf573f66f1231987828ea078709 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Fix RTU Master ignoring responses due to being in Send stateAlex Blasche2018-10-241-2/+11
| | | | | | | | | | | | | | | | The fix for QTBUG-62299 limits the processing of serial responses in RTU serial master to cases when the state machine is in receive mode only. So far the Receive state was triggered by the sendTimer. However modern kernels accept serial packages faster then the sendTimer can fire. This patches addresses the problem by setting the Receive state even before sendTimer fires. If the bytesWritten() callback detects that the entire PDU/ADU was written it stops sendTimer and immediately progresses the state machine to the Receive state. Fixes: QTBUG-69188 Change-Id: I1657973ef99f1b3e4008e887029b30890d825d59 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
* Fix case of accessing deleted memoryAlex Blasche2018-10-221-1/+3
| | | | | | | | | | | | | If the current QModbusRtuSerialMaster instance is deleted, the interFrameDelay timer may still be active and trigger the associated lambda. Since the lambda calls back into the deleted class instance, a crash may occur. Adding the public class instance as context to the singleshot connect ensures that the lambda is not called if the class instance was deleted already. Fixes: QTBUG-65684 Change-Id: Ic7d90ba68a1533e6de50c61117f5de8dc5e048b4 Reviewed-by: André Hartmann <aha_1980@gmx.de>
* Fix unxepected state in Modbus process queued elementKarsten Heimrich2017-08-141-0/+4
| | | | | | | | | | | | | Due to the nature of our serial bus device, a frame could already be send completely, but the bytes written did not report that yet. Then we received an answer before we reached the receive state, messing up the whole state logic. Now we process incoming frames only if we are in receive state, otherwise drop full frames. Task-number: QTBUG-62144 Task-number: QTBUG-62299 Change-Id: I88a4cf0b64a823409cbb277431a004a9d126cddc Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Fix build with Clang 5.0: remove unused captureThiago Macieira2017-06-131-1/+1
| | | | | | | qmodbusrtuserialmaster_p.h:356:68: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture] Change-Id: Ia53158e207a94bf49489fffd14c7903c7e4655cb Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Updated copyright headersAndre Hartmann2017-02-021-1/+1
| | | | | Change-Id: I7d38491c7ee15a1de788375acf9144c59b507d2a Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-10-011-2/+3
|\ | | | | | | Change-Id: Iba3271a050240b60f21e1696af320fdf82a7dd34
| * Fixed QModbusRtuSerialMaster stack overflow on closeMichael Winkelmann2016-09-261-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | QSerialPort::aboutToClose calls q->close() which leads to an infinite recursion. Calling QModbusRtuSerialMaster::close() explicitly is not necessary because when the serial port is closed, QModbusRtuSerialMaster::close() has been invoked already in all cases. Moreover, QSerialPort::aboutToClose asserts that serial master is always in closing state. Task-number: QTBUG-56009 Change-Id: If0dce93bbaa22116328b467f26c289cb58efc93f Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
| * Fix Modbus timeout on Windows.Karsten Heimrich2016-06-031-3/+1
| | | | | | | | | | | | | | | | | | | | Use a properly set or calculated value, do not sporadically calculate it inside a sending function. The only place the caluculation shall happen is in setupEnvironment(). Task-number: QTBUG-53767 Change-Id: Id40fd3406bee404b9d44c8ad43a5160622eda2de Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Fix Modbus timeout on Windows.Karsten Heimrich2016-06-031-3/+1
| | | | | | | | | | | | | | | | | | | | | | Use a properly set or calculated value, do not sporadically calculate it inside a sending function. The only place the caluculation shall happen is in calculateInterFrameDelay(). Task-number: QTBUG-53767 Change-Id: I15fdd42990f1211ab0133b557c5b0ffd625038c1 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com> Reviewed-by: André Hartmann <aha_1980@gmx.de>
* | Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-05-061-4/+4
|\| | | | | | | Change-Id: I687907747e05cedbd3f9f1c20df95e5de2d5cd48
| * Replace 'Q_DECL_OVERRIDE' with 'override'Denis Shienkov2016-04-261-2/+2
| | | | | | | | | | Change-Id: Iebbd61359296499600fe164429e710273a94b86d Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
| * Use 'auto' where it is possibleDenis Shienkov2016-04-221-1/+1
| | | | | | | | | | | | Change-Id: I3d915a6230a1f35317abc39d6266a9d46a5d9be6 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com> Reviewed-by: André Hartmann <aha_1980@gmx.de>
| * Use 'nullptr' where it is possibleDenis Shienkov2016-04-211-1/+1
| | | | | | | | | | Change-Id: I729e6b53cbc0b9a16c72c2351cc95d6bd7a2a0aa Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Merge remote-tracking branch 'gerrit/5.6' into 5.7Alex Blasche2016-03-171-1/+0
|\| | | | | | | Change-Id: If97de045fd88034b9379ff1abef8633a1e73b37a
| * Fix serial line access order. Unbreaks serial line connect.Karsten Heimrich2016-03-151-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Add API to set and retrieve the Modbus RTU inter frame delay.Karsten Heimrich2016-03-091-19/+28
|/ | | | | Change-Id: Id09913509802c74b1a389d7a83a1136bbeccbaf6 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Move clearing or updating values into a common function.Karsten Heimrich2016-03-011-15/+21
| | | | | Change-Id: I25ee09e5fe70464048500dc4d376d4e38805ca50 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Special implementation for Diagnostics:ReturnQueryData msg code.Karsten Heimrich2016-02-181-1/+19
| | | | | Change-Id: I1a07113ae1b6089a315862638dca8e6d4018fdd2 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Some API and data size calculation fixes.Karsten Heimrich2016-02-171-3/+2
| | | | | | | | | | | | | | | | | | | API: * We pass the PDU already, no need to pass the data part because we can get it from the PDU inside the function. Calculation: * Ignore the fact that "Diagnostics:ReturnQueryData" and "EncapsulatedInterfaceTransport" can be of variable length. A proper fix needs to be employed in the receiving code. * Refactor stream operator into a single function, it was quite similar except {minimum|calculate} data size. * Take into account that only "Diagnostics:ReturnQueryData" and "EncapsulatedInterfaceTransport" are of variable size. Change-Id: I0f958395f10bf4d93cc2436399ddc36c87f1c4da Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Implement missing serial port error handling.Karsten Heimrich2016-01-291-0/+50
| | | | | Change-Id: Ia93089df68775bcba62ab71b198d903c2100915f Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Implement timeout handling more close to the specification.Karsten Heimrich2016-01-291-118/+146
| | | | | | | | - Implements 3.5 character timeout handling. - Take send and response timeouts into account. Change-Id: I765dfe188b45671f007cb3f8f1cc66bb48ce94ed Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Only stop the response timeout after receiving a valid ADU.Karsten Heimrich2016-01-251-2/+1
| | | | | Change-Id: Ibb6da3a63ed8f6097eccf51019733beb9f257db9 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Adjust header includes according to our coding conventions.Karsten Heimrich2016-01-081-4/+4
| | | | | Change-Id: Id2c01e09e5d24bf2ecce57211cb13299478544e3 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Resolve TODO's. Merge both error code enums, update code.Karsten Heimrich2016-01-081-2/+2
| | | | | Change-Id: I52bfdcd84d2164b45754fdfe85a96679f64133f2 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Fix crash in case the queue is empty, we need to return early.Karsten Heimrich2015-12-211-1/+3
| | | | | Change-Id: I32355dce87d571a9d8f116d96b7d38cf133e0b21 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Use a local timer object, simplifies code quite a bit.Karsten Heimrich2015-12-181-65/+44
| | | | | Change-Id: Id6f79d0d4b160295f87aae0790ac84cd8c9cd5cb Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Implement: If a queued object gets deleted, remove it from the queue.Karsten Heimrich2015-12-181-0/+8
| | | | | Change-Id: Ibe9902e2a884b844898a88544fed809d3c7f5eeb Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Use the updated timeout as argument for the timeoutChanged signal.Karsten Heimrich2015-12-181-4/+1
| | | | | | | | Makes the connection and update of running timers a bit less verbose. Change-Id: I372f4ea8a23b5eace2e5d3b790a4a6e35a93da37 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Implement number of retries before a request fails.Karsten Heimrich2015-12-181-14/+15
| | | | | Change-Id: If3d1f50b431793dcb9209cfd20f077aa98675431 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Add identifier to be able to better distinguish debug output.Karsten Heimrich2015-12-181-1/+1
| | | | | Change-Id: Ifce397518fb6544a7080201ed29172d319d4c0da Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Implement Modbus device connection parameters.Karsten Heimrich2015-12-181-5/+10
| | | | | Change-Id: I6ca93f853f8b56cb97d2f724f32a4f3ea08d805e Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Add identifier to be able to better distinguish debug output.Karsten Heimrich2015-12-011-11/+12
| | | | | Change-Id: I043b1b522401782b243ef0cbd869c5cfbcc616b7 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Fix writing to a connected serial port with no receiver.Karsten Heimrich2015-12-011-4/+8
| | | | | | | | | | * fix debug output and use QT_MODBUS_LOW * clear the serial port buffer before next write * restart the proccessing once we received an timeout * enqueue the PDU in case we proccess requests already Change-Id: Id7413977731d377bb8d5128a9e93b80a9faca46d Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Return the real function code without the exception byte.Karsten Heimrich2015-12-011-2/+1
| | | | | Change-Id: Ifb4f0964f47b48f0cb9b33056c732a039cbaee69 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Move QModbusClient responseTimer into QModbusRtuSerialMasterAlex Blasche2015-11-241-18/+49
| | | | | | | | | | The TCP client doesn't use a queue system for requests and therefore needs one timer per request. Therefore the abstraction offered by QModbusClient is not suitable for the TCP client. As a consequence we move the response timer into the RTU client implementation. Change-Id: Ic30dfd730bcdae42ee7515be0fdf0eaff64af2fa Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
* Merge duplicated QueueElement handling code into one function.Karsten Heimrich2015-11-231-20/+1
| | | | | | Change-Id: I3d2d4f75e02659eabdb63ac78667f764e998f58a Reviewed-by: Ralf Nolden <nolden@kde.org> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Implement raw request send and receive handling.Karsten Heimrich2015-11-231-13/+17
| | | | | Change-Id: I6564e771830f8c2575e8c35376a36275728d06d4 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Extend QModbusReply to contain the raw response as well.Karsten Heimrich2015-11-231-3/+3
| | | | | | | | | | | The idea is to reuse this later in case of sending raw requests that we have no real data units for the return. This makes the protocol error functions superfluous as well, as now, the actual response can be queried for the real exception code. Change-Id: I5d6b5e050b273c8ff4ed19f0a3eae5c31420942e Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Finally rename all remaining slave* occurrences to server*.Karsten Heimrich2015-11-201-10/+10
| | | | | Change-Id: Ia71200686660f25f624e83d7bb3f8b3a8cb1b774 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Merge the TCP and RTU read/write implementations.Karsten Heimrich2015-11-191-2/+10
| | | | | | | | | This allows us to get rid of several public pure virtual functions and to have the implementation in a single place instead of duplicating it in several classes. Change-Id: I88fb28a5d507c7b64d20bba73765534e2925165e Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>