1MODBUS_RTU_SET_RTS(3)          libmodbus Manual          MODBUS_RTU_SET_RTS(3)
2
3
4

NAME

6       modbus_rtu_set_rts - set the RTS mode in RTU
7

SYNOPSIS

9       int modbus_rtu_set_rts(modbus_t *ctx, int mode)
10

DESCRIPTION

12       The modbus_rtu_set_rts() function shall set the Request To Send mode to
13       communicate on a RS485 serial bus. By default, the mode is set to
14       MODBUS_RTU_RTS_NONE and no signal is issued before writing data on the
15       wire.
16
17       To enable the RTS mode, the values MODBUS_RTU_RTS_UP or
18       MODBUS_RTU_RTS_DOWN must be used, these modes enable the RTS mode and
19       set the polarity at the same time. When MODBUS_RTU_RTS_UP is used, an
20       ioctl call is made with RTS flag enabled then data is written on the
21       bus after a delay of 1 ms, then another ioctl call is made with the RTS
22       flag disabled and again a delay of 1 ms occurs. The MODBUS_RTU_RTS_DOWN
23       mode applies the same procedure but with an inverted RTS flag.
24
25       This function can only be used with a context using a RTU backend.
26

RETURN VALUE

28       The function shall return 0 if successful. Otherwise it shall return -1
29       and set errno to one of the values defined below.
30

ERRORS

32       EINVAL
33           The libmodbus backend isn’t RTU or the mode given in argument is
34           invalid.
35

EXAMPLE

37       Enable the RTS mode with positive polarity.
38
39           modbus_t *ctx;
40           uint16_t tab_reg[10];
41
42           ctx = modbus_new_rtu("/dev/ttyS0", 115200, 'N', 8, 1);
43           modbus_set_slave(ctx, 1);
44           modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485);
45           modbus_rtu_set_rts(ctx, MODBUS_RTU_RTS_UP);
46
47           if (modbus_connect(ctx) == -1) {
48               fprintf(stderr, "Connexion failed: %s\n", modbus_strerror(errno));
49               modbus_free(ctx);
50               return -1;
51           }
52
53           rc = modbus_read_registers(ctx, 0, 7, tab_reg);
54           if (rc == -1) {
55               fprintf(stderr, "%s\n", modbus_strerror(errno));
56               return -1;
57           }
58
59           modbus_close(ctx);
60           modbus_free(ctx);
61
62

SEE ALSO

64       modbus_rtu_get_rts(3)
65

AUTHORS

67       The libmodbus documentation was written by Stéphane Raimbault
68       <stephane.raimbault@gmail.com>
69
70
71
72libmodbus v3.1.6                  07/21/2022             MODBUS_RTU_SET_RTS(3)
Impressum