0

For clarity I am using Python and pyModbusTCP to communicate via modbus. If I am using function code 1 to read coil status, how can I determine the function code of the message that was sent back?

Below is an example of how I sent messages to a modbus slave:

self.ModbusClient_call = ModbusClient(host=self.ip, port=502, auto_open=True, debug=False)

...

coilData = self.ModbusClient_call.read_coils(self.modbus_address)
return coilData

Per the PyModbusTCP documentation using the read_coils method is equivalent to sending a message and indicating in the first byte the function code 0x01. I am having trouble figuring out how to extract the function code from the response message though, any help much appreciated!

  • The expected response function code should be `0x01` (the same as the request). PymodbusTCP checks if the returned function code [indicates an error](https://github.com/sourceperl/pyModbusTCP/blob/8da1f0c0e378ac6f8991b54c2cca467c5153da54/pyModbusTCP/client.py#L715) but, other than that, I don't believe it does anything further with it (it's not generally needed). Can you please explain your use-case? – Brits Jan 30 '23 at 23:40

0 Answers0