5 modbus_rtu_set_rts - set the RTS mode in RTU
10 int modbus_rtu_set_rts(modbus_t *ctx, int mode)
15 The *modbus_rtu_set_rts()* function shall set the Request To Send mode to
16 communicate on a RS-485 serial bus. By default, the mode is set to
17 `MODBUS_RTU_RTS_NONE` and no signal is issued before writing data on the wire.
19 To enable the RTS mode, the values `MODBUS_RTU_RTS_UP` or `MODBUS_RTU_RTS_DOWN`
20 must be used, these modes enable the RTS mode and set the polarity at the same
21 time. When `MODBUS_RTU_RTS_UP` is used, an ioctl call is made with RTS flag
22 enabled then data is written on the bus after a delay of 1 ms, then another
23 ioctl call is made with the RTS flag disabled and again a delay of 1 ms occurs.
24 The `MODBUS_RTU_RTS_DOWN` mode applies the same procedure but with an inverted
27 This function can only be used with a context using a RTU backend.
31 The function shall return 0 if successful. Otherwise it shall return -1 and set
32 errno to one of the values defined below.
36 - *EINVAL*, the libmodbus backend isn't RTU or the mode given in argument is invalid.
40 Enable the RTS mode with positive polarity:
46 ctx = modbus_new_rtu("/dev/ttyS0", 115200, 'N', 8, 1);
47 modbus_set_slave(ctx, 1);
48 modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485);
49 modbus_rtu_set_rts(ctx, MODBUS_RTU_RTS_UP);
51 if (modbus_connect(ctx) == -1) {
52 fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
57 rc = modbus_read_registers(ctx, 0, 7, tab_reg);
59 fprintf(stderr, "%s\n", modbus_strerror(errno));
69 - [modbus_rtu_get_rts](modbus_rtu_get_rts.md)