grid-x / modbus

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

Gets out of sync WRT transaction IDs #78

Open cmock opened 9 months ago

cmock commented 9 months ago

When used in the modbus plugin in https://github.com/influxdata/telegraf, the connection can get out of sync when the server is slow to respond, as seen in these log messages:

Nov 18 07:02:05 rockpro telegraf[1449366]: 2023-11-18T06:02:05Z E! [inputs.modbus] Error in plugin: slave 1: read tcp 192.168.57.7:56970->192.168.66.3:502: i/o timeout
Nov 18 07:02:10 rockpro telegraf[1449366]: 2023-11-18T06:02:10Z E! [inputs.modbus] Error in plugin: slave 1: modbus: response transaction id '7616' does not match request '7617'
Nov 18 07:02:20 rockpro telegraf[1449366]: 2023-11-18T06:02:20Z E! [inputs.modbus] Error in plugin: slave 1: modbus: response transaction id '7617' does not match request '7618'
Nov 18 07:02:30 rockpro telegraf[1449366]: 2023-11-18T06:02:30Z E! [inputs.modbus] Error in plugin: slave 1: modbus: response transaction id '7618' does not match request '7619'
Nov 18 07:02:40 rockpro telegraf[1449366]: 2023-11-18T06:02:40Z E! [inputs.modbus] Error in plugin: slave 1: modbus: response transaction id '7619' does not match request '7620'
Nov 18 07:02:50 rockpro telegraf[1449366]: 2023-11-18T06:02:50Z E! [inputs.modbus] Error in plugin: slave 1: modbus: response transaction id '7620' does not match request '7621'

The connection then never recovers until restarted. It'd be nice to have some kind of error counter and an error reported to the calling code when that's exceeded, or an automatic re-opening of the connection.

Also see https://github.com/influxdata/telegraf/issues/14317