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

NAME

6       modbus_connect - establish a Modbus connection
7

SYNOPSIS

9       int modbus_connect(modbus_t *ctx);
10

DESCRIPTION

12       The modbus_connect() function shall establish a connection to a Modbus
13       server, a network or a bus using the context information of libmodbus
14       context given in argument.
15

RETURN VALUE

17       The function shall return 0 if successful. Otherwise it shall return -1
18       and set errno to one of the values defined by the system calls of the
19       underlying platform.
20

EXAMPLE

22           modbus_t *ctx;
23
24           ctx = modbus_new_tcp("127.0.0.1", 502);
25           if (modbus_connect(ctx) == -1) {
26               fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
27               modbus_free(ctx);
28               return -1;
29           }
30

SEE ALSO

32       modbus_close(3)
33

AUTHORS

35       The libmodbus documentation was written by Stéphane Raimbault
36       <stephane.raimbault@gmail.com>
37
38
39
40libmodbus v3.1.7                  07/20/2023                 MODBUS_CONNECT(3)
Impressum