arduino-libraries / ArduinoModbus

245 stars 116 forks source link

ModbusRTUClient.setTimeout does not set timeout of Stream class #28

Open cheetor5923 opened 4 years ago

cheetor5923 commented 4 years ago

When called, ModbusRTUClient.setTimeout does not propagate the timeout to it's associated Stream class.

bobemoe commented 1 year ago

I'm having trouble with this too. It seems to be taking 1500ms to timeout by default, which is strange to begin with as the default timeout appears to be 1000ms!

https://github.com/arduino-libraries/ArduinoModbus/blob/02abf6d250365a283cb8ea41562c1dd210dde496/src/ModbusRTUClient.cpp#L29-L35

I've started looking into the code, and it looks like ArduinoModbus is passing the args as seconds and milliseconds: https://github.com/arduino-libraries/ArduinoModbus/blob/02abf6d250365a283cb8ea41562c1dd210dde496/src/ModbusClient.cpp#L422

while libmodbus is expecting the values as seconds and microseconds: https://github.com/arduino-libraries/ArduinoModbus/blob/02abf6d250365a283cb8ea41562c1dd210dde496/src/libmodbus/modbus.c#L1693-L1696

I'm not sure this is the current issue, as I'm trying to set it to 50ms, and even if that was passed over as 50us I would expect to see an almost instant timeout, however I'm still getting 1500ms timeout.

What's going on here!?