1MODBUS_SET_SOCKET(3) libmodbus Manual MODBUS_SET_SOCKET(3)
2
3
4
6 modbus_set_socket - set socket of the context
7
9 int modbus_set_socket(modbus_t *ctx, int s);
10
12 The modbus_set_socket() function shall set the socket or file
13 descriptor in the libmodbus context. This function is useful for
14 managing multiple client connections to the same server.
15
17 The function shall return 0 if successful. Otherwise it shall return -1
18 and set errno.
19
21 ctx = modbus_new_tcp("127.0.0.1", 1502);
22 server_socket = modbus_tcp_listen(ctx, NB_CONNECTION);
23
24 FD_ZERO(&rdset);
25 FD_SET(server_socket, &rdset);
26
27 /* .... */
28
29 if (FD_ISSET(master_socket, &rdset)) {
30 modbus_set_socket(ctx, master_socket);
31 rc = modbus_receive(ctx, query);
32 if (rc != -1) {
33 modbus_reply(ctx, query, rc, mb_mapping);
34 }
35 }
36
38 modbus_get_socket(3)
39
41 The libmodbus documentation was written by Stéphane Raimbault
42 <stephane.raimbault@gmail.com>
43
44
45
46libmodbus v3.1.7 07/20/2023 MODBUS_SET_SOCKET(3)