1MODBUS_NEW_RTU(3)              Libmodbus Manual              MODBUS_NEW_RTU(3)
2
3
4

NAME

6       modbus_new_rtu - create a libmodbus context for RTU
7

SYNOPSIS

9       modbus_t *modbus_new_rtu(const char *device, int baud, char parity, int
10       data_bit, int stop_bit);
11

DESCRIPTION

13       The modbus_new_rtu() function shall allocate and initialize a modbus_t
14       structure to communicate in RTU mode on a serial line.
15
16       The device argument specifies the name of the serial port handled by
17       the OS, eg. /dev/ttyS0 or /dev/ttyUSB0. On Windows, it’s necessary to
18       prepend COM name with \\.\ for COM number greater than 9, eg.
19       \\\\.\\COM10. See
20       http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx for
21       details
22
23       The baud argument specifies the baud rate of the communication, eg.
24       9600, 19200, 57600, 115200, etc.
25
26       The parity argument can have one of the following values
27
28           ·   N for none
29
30           ·   E for even
31
32           ·   O for odd
33
34       The data_bits argument specifies the number of bits of data, the
35       allowed values are 5, 6, 7 and 8.
36
37       The stop_bits argument specifies the bits of stop, the allowed values
38       are 1 and 2.
39

RETURN VALUE

41       The modbus_new_rtu() function shall return a pointer to a modbus_t
42       structure if successful. Otherwise it shall return NULL and set errno
43       to one of the values defined below.
44

ERRORS

46       EINVAL
47           An invalid argument was given.
48

EXAMPLE

50           modbus_t *ctx;
51
52           ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1);
53           if (ctx == NULL) {
54               fprintf(stderr, "Unable to create the libmodbus context\n");
55               return -1;
56           }
57

SEE ALSO

59       modbus_new_tcp(3) modbus_free(3)
60

AUTHORS

62       The libmodbus documentation was written by Stéphane Raimbault
63       <stephane.raimbault@gmail.com[1]>
64

NOTES

66        1. stephane.raimbault@gmail.com
67           mailto:stephane.raimbault@gmail.com
68
69
70
71libmodbus 3.0.8                   07/31/2019                 MODBUS_NEW_RTU(3)
Impressum