1MODBUS_NEW_TCP_PI(3) Libmodbus Manual MODBUS_NEW_TCP_PI(3)
2
3
4
6 modbus_new_tcp_pi - create a libmodbus context for TCP Protocol
7 Independent
8
10 modbus_t *modbus_new_tcp_pi(const char *node, const char *service);
11
13 The modbus_new_tcp_pi() function shall allocate and initialize a
14 modbus_t structure to communicate with a Modbus TCP IPv4 or Ipv6
15 server.
16
17 The node argument specifies the host name or IP address of the host to
18 connect to, eg. 192.168.0.5 , ::1 or server.com.
19
20 The service argument is the service name/port number to connect to. To
21 use the default Modbus port use the string "502". On many Unix systems,
22 it’s convenient to use a port number greater than or equal to 1024
23 because it’s not necessary to have administrator privileges.
24
26 The modbus_new_tcp_pi() function shall return a pointer to a modbus_t
27 structure if successful. Otherwise it shall return NULL and set errno
28 to one of the values defined below.
29
31 EINVAL
32 The node string is empty or has been truncated. The service string
33 is empty or has been truncated.
34
36 modbus_t *ctx;
37
38 ctx = modbus_new_tcp_pi("::1", "1502");
39 if (ctx == NULL) {
40 fprintf(stderr, "Unable to allocate libmodbus context\n");
41 return -1;
42 }
43
44 if (modbus_connect(ctx) == -1) {
45 fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
46 modbus_free(ctx);
47 return -1;
48 }
49
51 modbus_new_tcp(3) modbus_new_rtu(3) modbus_free(3)
52
54 The libmodbus documentation was written by Stéphane Raimbault
55 <stephane.raimbault@gmail.com[1]>
56
58 1. stephane.raimbault@gmail.com
59 mailto:stephane.raimbault@gmail.com
60
61
62
63libmodbus 3.0.6 04/02/2014 MODBUS_NEW_TCP_PI(3)