modbus_rtu_set_rts.txt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. modbus_rtu_set_rts(3)
  2. =====================
  3. NAME
  4. ----
  5. modbus_rtu_set_rts - set the RTS mode in RTU
  6. SYNOPSIS
  7. --------
  8. *int modbus_rtu_set_rts(modbus_t *'ctx', int 'mode')*
  9. DESCRIPTION
  10. -----------
  11. The *modbus_rtu_set_rts()* function shall set the Request To Send mode to
  12. communicate on a RS485 serial bus. By default, the mode is set to
  13. `MODBUS_RTU_RTS_NONE` and no signal is issued before writing data on the wire.
  14. To enable the RTS mode, the values `MODBUS_RTU_RTS_UP` or `MODBUS_RTU_RTS_DOWN`
  15. must be used, these modes enable the RTS mode and set the polarity at the same
  16. time. When `MODBUS_RTU_RTS_UP` is used, an ioctl call is made with RTS flag
  17. enabled then data is written on the bus after a delay of 1 ms, then another
  18. ioctl call is made with the RTS flag disabled and again a delay of 1 ms occurs.
  19. The `MODBUS_RTU_RTS_DOWN` mode applies the same procedure but with an inverted
  20. RTS flag.
  21. This function can only be used with a context using a RTU backend.
  22. RETURN VALUE
  23. ------------
  24. The function shall return 0 if successful. Otherwise it shall return -1 and set
  25. errno to one of the values defined below.
  26. ERRORS
  27. ------
  28. *EINVAL*::
  29. The libmodbus backend isn't RTU or the mode given in argument is invalid.
  30. EXAMPLE
  31. -------
  32. .Enable the RTS mode with positive polarity
  33. [source,c]
  34. -------------------
  35. modbus_t *ctx;
  36. uint16_t tab_reg[10];
  37. ctx = modbus_new_rtu("/dev/ttyS0", 115200, 'N', 8, 1);
  38. modbus_set_slave(ctx, 1);
  39. modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485);
  40. modbus_rtu_set_rts(ctx, MODBUS_RTU_RTS_UP);
  41. if (modbus_connect(ctx) == -1) {
  42. fprintf(stderr, "Connexion failed: %s\n", modbus_strerror(errno));
  43. modbus_free(ctx);
  44. return -1;
  45. }
  46. rc = modbus_read_registers(ctx, 0, 7, tab_reg);
  47. if (rc == -1) {
  48. fprintf(stderr, "%s\n", modbus_strerror(errno));
  49. return -1;
  50. }
  51. modbus_close(ctx);
  52. modbus_free(ctx);
  53. -------------------
  54. SEE ALSO
  55. --------
  56. linkmb:modbus_rtu_get_rts[3]
  57. AUTHORS
  58. -------
  59. The libmodbus documentation was written by Stéphane Raimbault
  60. <stephane.raimbault@gmail.com>