Fix ModbusBridge request/response logic #22075
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This can happen in a setup where simultaneously: - two (or more) modbus TCP clients are sending requests
through the modbus-proxy [1] to Tasmota,
- ModbusSend commands are executed (e.g. using Berry).
Log excerpt (from build with TASMOTAMODBUSDEBUG enabled): 14:51:18.940 MBS: Serial Send: 04 03 01 00 00 09 84 65 14:51:19.054 MBS: Serial Send: 04 03 10 0A 00 05 A1 5E 14:51:19.136 MBS: Serial Received: 04 03 0A 00 00 00 D0 00 00 01 AB 00 00 89 62
Fix adds 'waitingForAnswerFromSerial' flag which is set after we send data to the serial port and prevents sending another requests before we receive an answer or timeout happened.
Fix stores temporarily a 'ModbusSend' command data and tries
to execute it after Modbus response has been received or
timeout has happened.
Add 'ModbusSerialTimeout' command which sets timeout in [ms] for how long we will be waiting for an answer from the client device. Default value is 1000 [ms] and it is not restored after reboot.
Sends error 11 (0xB) (as TCP response) when no answer was received from the serial port within the timeout set by 'ModbusSerialTimeout'
command.
Add Modbus 'TransactionId' to the logging.
[1] https://github.com/tiagocoutinho/modbus-proxy
Description:
Related issue (if applicable): fixes #
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass