Use of struct timeval to set the response timeout on LibModbus

1.2k Views Asked by At

I am using the library LibModbus to connect with ADAM devices. I had some previous problem sending some commands to the device but setting a bigger response timeout it was fixed, this was in a previous version of the library.

Now, I am using the latest library, where the set_response_timeout uses a timeval struct. Link to the functions manual in the library: Get_response_timeout / set_response_timeout

I am using the library as follows

struct timeval response_timeout;
struct timeval old_response_timeout;
modbus_get_response_timeout(mb, &old_response_timeout);
printf("\nold_tv_sec: %d, old_tv_usec: %d\n", old_response_timeout.tv_sec, old_response_timeout.tv_usec);

response_timeout.tv_sec = 60;
response_timeout.tv_usec = 0;
modbus_set_response_timeout(mb, &response_timeout);

modbus_get_response_timeout(mb, &old_response_timeout);
printf("\nnew_tv_sec: %d, new_tv_usec: %d\n", old_response_timeout.tv_sec, old_response_timeout.tv_usec);

But if I print the value of the response timeout using get_response_timeout, previously and after setting it, it returns the same values:

  • Response of modbus_get_response_timeout(mb, &old_response_timeout) before the setting old_tv_sec: 500000, old_tv_usec: 23224832

  • Values of the timeval struct to send to modbus_set_response_timeout(mb, &response_timeout) to_set_tv_sec: 60, to_set_tv_usec: 0

  • Response of modbus_get_response_timeout(mb, &old_response_timeout) after setting the new values.

    new_tv_sec: 500000, new_tv_usec: 23224832

0

There are 0 best solutions below