Modbus TCP implementation

I’ve been testing a few hours to get modbus data read over an TCP to RTU bridge. Everything looks good until the data needs to be parsed by HA.

Test in symply modbus 1.8.2:
2023/08/25 15:04:21 >>> 00 01 00 00 00 06 01 04 0B FA 00 01
2023/08/25 15:04:21 < 00 02 00 00 00 05 01 04 02 00 A0


  • name: “Kstar”
    type: tcp
    host: 192.168.0.XXX
    port: 502
    • name: “SoC”
      input_type: input
      address: 3066
      slave: 1
      data_type: int16

debug log:

2023-08-25 16:12:34.727 DEBUG (SyncWorker_9) [pymodbus.logging] Connection to Modbus server established. Socket (‘192.168.0.XXX’, 59534)
2023-08-25 16:12:34.727 DEBUG (SyncWorker_9) [pymodbus.logging] Current transaction state - TRANSACTION_COMPLETE
2023-08-25 16:12:34.728 DEBUG (SyncWorker_9) [pymodbus.logging] Running transaction 32
2023-08-25 16:12:34.728 DEBUG (SyncWorker_9) [pymodbus.logging] SEND: 0x0 0x20 0x0 0x0 0x0 0x6 0x1 0x4 0xb 0xfa 0x0 0x1
2023-08-25 16:12:34.729 DEBUG (SyncWorker_9) [pymodbus.logging] New Transaction state “SENDING”
2023-08-25 16:12:34.731 DEBUG (SyncWorker_9) [pymodbus.logging] Changing transaction state from “SENDING” to “WAITING FOR REPLY”
2023-08-25 16:12:34.776 DEBUG (SyncWorker_9) [pymodbus.logging] Changing transaction state from “WAITING FOR REPLY” to “PROCESSING REPLY”
2023-08-25 16:12:34.777 DEBUG (SyncWorker_9) [pymodbus.logging] RECV: 0x0 0x21 0x0 0x0 0x0 0x5 0x1 0x4 0x2 0x0 0xc8
2023-08-25 16:12:34.777 DEBUG (SyncWorker_9) [pymodbus.logging] Processing: 0x0 0x21 0x0 0x0 0x0 0x5 0x1 0x4 0x2 0x0 0xc8
2023-08-25 16:12:34.778 DEBUG (SyncWorker_9) [pymodbus.logging] Factory Response[ReadInputRegistersResponse’: 4]
2023-08-25 16:12:34.778 DEBUG (SyncWorker_9) [pymodbus.logging] Getting transaction 32
2023-08-25 16:12:34.781 DEBUG (SyncWorker_9) [pymodbus.logging] Changing transaction state from “PROCESSING REPLY” to “TRANSACTION_COMPLETE”
2023-08-25 16:12:34.782 DEBUG (SyncWorker_9) [homeassistant.components.modbus.modbus] Pymodbus: Kstar: Modbus Error: [Input/Output] No Response received from the remote slave/Unable to decode response

So the modbus request and answer are good, however the single quote after ReadInputRegistersResponse doesn’t make sense.

Anybody seen this before?

For those who would struggle with the same situation, it turns out the Waveshare TCP to RTU bridge, when set to TCP client, will still respond correctly to modbus TCP queries but leave the TCP session open. pymodbus times out and throws away the data.
Setting the Waveshare bridge to TCP server mode solved the issue.