grid-x / modbus

BSD 3-Clause "New" or "Revised" License
78 stars 26 forks source link

Wait for correct response id #77

Open decadenza opened 10 months ago

decadenza commented 10 months ago

Due to noise/interference on the serial line (separate problem), I was having errors like:

error="modbus: response slave id '69' does not match request '1'"
error="modbus: response slave id '48' does not match request '1'"

And so on.

My system has only one slave with id 1. I came across this issue on a different repository. image

As I understand it, Modbus protocol specifies that master should manage the "unexpected slave" and wait for the correct one for the specified timeout setting.

Checking the code I realised that the client was not waiting for the correct timeout before throwing the error.

With this simple change my error rate has reduced, and when it happens the correct "timeout" error is given.

decadenza commented 10 months ago

Added error value err = fmt.Errorf("modbus: response timeout")

decadenza commented 9 months ago

@frzifus Yes, that is what I was doing as a sub-optimal measure. But I think it would be preferable to actually follow the specifications. The problem arises when the traffic is high. Any thoughts?