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 etablish 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 modbus_connect() function shall return 0 if successful. Otherwise
18       it shall return -1 and set errno to one of the values defined by the
19       system calls of the 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[1]>
37

NOTES

39        1. stephane.raimbault@gmail.com
40           mailto:stephane.raimbault@gmail.com
41
42
43
44libmodbus 3.0.8                   07/31/2019                 MODBUS_CONNECT(3)
Impressum