| 1 | # modbus_set_response_timeout |
| 2 | |
| 3 | ## Name |
| 4 | |
| 5 | modbus_set_response_timeout - set timeout for response |
| 6 | |
| 7 | ## Synopsis |
| 8 | |
| 9 | ```c |
| 10 | int modbus_set_response_timeout(modbus_t *ctx, uint32_t to_sec, uint32_t to_usec); |
| 11 | ``` |
| 12 | |
| 13 | ## Description |
| 14 | |
| 15 | The *modbus_set_response_timeout()* function shall set the timeout interval used |
| 16 | to wait for a response. When a byte timeout is set, if elapsed time for the |
| 17 | first byte of response is longer than the given timeout, an `ETIMEDOUT` error |
| 18 | will be raised by the function waiting for a response. When byte timeout is |
| 19 | disabled, the full confirmation response must be received before expiration of |
| 20 | the response timeout. |
| 21 | |
| 22 | The value of `to_usec` argument must be in the range 0 to 999999. |
| 23 | |
| 24 | ## Return value |
| 25 | |
| 26 | The function shall return 0 if successful. Otherwise it shall return -1 and set |
| 27 | errno. |
| 28 | |
| 29 | ## Errors |
| 30 | |
| 31 | - *EINVAL*, the argument `ctx` is NULL, or both `to_sec` and `to_usec` are zero, |
| 32 | or `to_usec` is larger than 999999. |
| 33 | |
| 34 | ## Example |
| 35 | |
| 36 | ```c |
| 37 | uint32_t old_response_to_sec; |
| 38 | uint32_t old_response_to_usec; |
| 39 | |
| 40 | /* Save original timeout */ |
| 41 | modbus_get_response_timeout(ctx, &old_response_to_sec, &old_response_to_usec); |
| 42 | |
| 43 | /* Define a new timeout of 200ms */ |
| 44 | modbus_set_response_timeout(ctx, 0, 200000); |
| 45 | ``` |
| 46 | |
| 47 | ## See also |
| 48 | |
| 49 | - [modbus_get_response_timeout](modbus_get_response_timeout.md) |
| 50 | - [modbus_get_byte_timeout](modbus_get_byte_timeout.md) |
| 51 | - [modbus_set_byte_timeout](modbus_set_byte_timeout.md) |