1MODBUS_SET_ERROR_REC(3) libmodbus Manual MODBUS_SET_ERROR_REC(3)
2
3
4
6 modbus_set_error_recovery - set the error recovery mode
7
9 int modbus_set_error_recovery(modbus_t *ctx, modbus_error_recovery_mode
10 error_recovery);
11
13 The modbus_set_error_recovery() function shall set the error recovery
14 mode to apply when the connection fails or the byte received is not
15 expected. The argument error_recovery may be bitwise-or’ed with zero or
16 more of the following constants.
17
18 By default there is no error recovery (MODBUS_ERROR_RECOVERY_NONE) so
19 the application is responsible for controlling the error values
20 returned by libmodbus functions and for handling them if necessary.
21
22 When MODBUS_ERROR_RECOVERY_LINK is set, the library will attempt an
23 reconnection after a delay defined by response timeout of the libmodbus
24 context. This mode will try an infinite close/connect loop until
25 success on send call and will just try one time to re-establish the
26 connection on select/read calls (if the connection was down, the values
27 to read are certainly not available any more after reconnection, except
28 for slave/server). This mode will also run flush requests after a delay
29 based on the current response timeout in some situations (eg. timeout
30 of select call). The reconnection attempt can hang for several seconds
31 if the network to the remote target unit is down.
32
33 When MODBUS_ERROR_RECOVERY_PROTOCOL is set, a sleep and flush sequence
34 will be used to clean up the ongoing communication, this can occurs
35 when the message length is invalid, the TID is wrong or the received
36 function code is not the expected one. The response timeout delay will
37 be used to sleep.
38
39 The modes are mask values and so they are complementary.
40
41 It’s not recommended to enable error recovery for slave/server.
42
44 The function shall return 0 if successful. Otherwise it shall return -1
45 and set errno to one of the values defined below.
46
48 EINVAL
49 The value of the argument error_recovery is not positive.
50
52 modbus_set_error_recovery(ctx,
53 MODBUS_ERROR_RECOVERY_LINK |
54 MODBUS_ERROR_RECOVERY_PROTOCOL);
55
57 The libmodbus documentation was written by Stéphane Raimbault
58 <stephane.raimbault@gmail.com>
59
60
61
62libmodbus v3.1.6 02/04/2022 MODBUS_SET_ERROR_REC(3)