modbus_set_error_recovery.txt 2.4 KB

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