Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cheetor5923 opened this issue Mar 2, 2020 · 1 comment
Open

Comments

@cheetor5923
Copy link

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

@bobemoe
Copy link

bobemoe commented Jul 6, 2023

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!

ModbusRTUClientClass::ModbusRTUClientClass() :
ModbusClient(1000)
{
}
ModbusRTUClientClass::ModbusRTUClientClass(RS485Class& rs485) :
ModbusClient(1000), _rs485(&rs485)

I've started looking into the code, and it looks like ArduinoModbus is passing the args as seconds and milliseconds:

modbus_set_response_timeout(_mb, _timeout / 1000, (_timeout % 1000) * 1000);

while libmodbus is expecting the values as seconds and microseconds:

int modbus_set_response_timeout(modbus_t *ctx, uint32_t to_sec, uint32_t to_usec)
{
if (ctx == NULL ||
(to_sec == 0 && to_usec == 0) || to_usec > 999999) {

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!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants