modbus-tcp.c
Go to the documentation of this file.
1 /*
2  * Copyright © 2001-2011 Stéphane Raimbault <stephane.raimbault@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <errno.h>
23 #ifndef _MSC_VER
24 #include <unistd.h>
25 #endif
26 #include <signal.h>
27 #include <sys/types.h>
28 
29 #if defined(_WIN32)
30 # define OS_WIN32
31 /* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later.
32  * minwg32 headers check WINVER before allowing the use of these */
33 # ifndef WINVER
34 # define WINVER 0x0501
35 # endif
36 # include <ws2tcpip.h>
37 # define SHUT_RDWR 2
38 # define close closesocket
39 #else
40 # include <sys/socket.h>
41 # include <sys/ioctl.h>
42 
43 #if defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ < 5)
44 # define OS_BSD
45 # include <netinet/in_systm.h>
46 #endif
47 
48 # include <netinet/in.h>
49 # include <netinet/ip.h>
50 # include <netinet/tcp.h>
51 # include <arpa/inet.h>
52 # include <poll.h>
53 # include <netdb.h>
54 #endif
55 
56 #if !defined(MSG_NOSIGNAL)
57 #define MSG_NOSIGNAL 0
58 #endif
59 
61 
62 #include "libmodbus/modbus-tcp.h"
64 
65 #ifdef OS_WIN32
66 static int _modbus_tcp_init_win32(void)
67 {
68  /* Initialise Windows Socket API */
69  WSADATA wsaData;
70 
71  if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
72  fprintf(stderr, "WSAStartup() returned error code %d\n",
73  (unsigned int)GetLastError());
74  errno = EIO;
75  return -1;
76  }
77  return 0;
78 }
79 #endif
80 
81 static int _modbus_set_slave(modbus_t *ctx, int slave)
82 {
83  /* Broadcast address is 0 (MODBUS_BROADCAST_ADDRESS) */
84  if (slave >= 0 && slave <= 247) {
85  ctx->slave = slave;
86  } else if (slave == MODBUS_TCP_SLAVE) {
87  /* The special value MODBUS_TCP_SLAVE (0xFF) can be used in TCP mode to
88  * restore the default value. */
89  ctx->slave = slave;
90  } else {
91  errno = EINVAL;
92  return -1;
93  }
94 
95  return 0;
96 }
97 
98 /* Builds a TCP request header */
100  int addr, int nb,
101  uint8_t *req)
102 {
103 
104  /* Extract from MODBUS Messaging on TCP/IP Implementation Guide V1.0b
105  (page 23/46):
106  The transaction identifier is used to associate the future response
107  with the request. So, at a time, on a TCP connection, this identifier
108  must be unique. */
109  static uint16_t t_id = 0;
110 
111  /* Transaction ID */
112  if (t_id < UINT16_MAX)
113  t_id++;
114  else
115  t_id = 0;
116  req[0] = t_id >> 8;
117  req[1] = t_id & 0x00ff;
118 
119  /* Protocol Modbus */
120  req[2] = 0;
121  req[3] = 0;
122 
123  /* Length will be defined later by set_req_length_tcp at offsets 4
124  and 5 */
125 
126  req[6] = ctx->slave;
127  req[7] = function;
128  req[8] = addr >> 8;
129  req[9] = addr & 0x00ff;
130  req[10] = nb >> 8;
131  req[11] = nb & 0x00ff;
132 
134 }
135 
136 /* Builds a TCP response header */
138 {
139  /* Extract from MODBUS Messaging on TCP/IP Implementation
140  Guide V1.0b (page 23/46):
141  The transaction identifier is used to associate the future
142  response with the request. */
143  rsp[0] = sft->t_id >> 8;
144  rsp[1] = sft->t_id & 0x00ff;
145 
146  /* Protocol Modbus */
147  rsp[2] = 0;
148  rsp[3] = 0;
149 
150  /* Length will be set later by send_msg (4 and 5) */
151 
152  /* The slave ID is copied from the indication */
153  rsp[6] = sft->slave;
154  rsp[7] = sft->function;
155 
157 }
158 
159 
160 int _modbus_tcp_prepare_response_tid(const uint8_t *req, int *req_length)
161 {
162  return (req[0] << 8) + req[1];
163 }
164 
165 int _modbus_tcp_send_msg_pre(uint8_t *req, int req_length)
166 {
167  /* Substract the header length to the message length */
168  int mbap_length = req_length - 6;
169 
170  req[4] = mbap_length >> 8;
171  req[5] = mbap_length & 0x00FF;
172 
173  return req_length;
174 }
175 
176 ssize_t _modbus_tcp_send(modbus_t *ctx, const uint8_t *req, int req_length)
177 {
178  /* MSG_NOSIGNAL
179  Requests not to send SIGPIPE on errors on stream oriented
180  sockets when the other end breaks the connection. The EPIPE
181  error is still returned. */
182  return send(ctx->s, (const char*)req, req_length, MSG_NOSIGNAL);
183 }
184 
185 ssize_t _modbus_tcp_recv(modbus_t *ctx, uint8_t *rsp, int rsp_length) {
186  return recv(ctx->s, (char *)rsp, rsp_length, 0);
187 }
188 
189 int _modbus_tcp_check_integrity(modbus_t *ctx, uint8_t *msg, const int msg_length)
190 {
191  return msg_length;
192 }
193 
195  const uint8_t *rsp, int rsp_length)
196 {
197  /* Check TID */
198  if (req[0] != rsp[0] || req[1] != rsp[1]) {
199  if (ctx->debug) {
200  fprintf(stderr, "Invalid TID received 0x%X (not 0x%X)\n",
201  (rsp[0] << 8) + rsp[1], (req[0] << 8) + req[1]);
202  }
203  errno = EMBBADDATA;
204  return -1;
205  } else {
206  return 0;
207  }
208 }
209 
211 {
212  int rc;
213  int option;
214 
215  /* Set the TCP no delay flag */
216  /* SOL_TCP = IPPROTO_TCP */
217  option = 1;
218  rc = setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
219  (const void *)&option, sizeof(int));
220  if (rc == -1) {
221  return -1;
222  }
223 
224 #ifndef OS_WIN32
225 
229  /* Set the IP low delay option */
230  option = IPTOS_LOWDELAY;
231  rc = setsockopt(s, IPPROTO_IP, IP_TOS,
232  (const void *)&option, sizeof(int));
233  if (rc == -1) {
234  return -1;
235  }
236 #endif
237 
238  return 0;
239 }
240 
241 /* Establishes a modbus TCP connection with a Modbus server. */
243 {
244  int rc;
245  struct sockaddr_in addr;
246  modbus_tcp_t *ctx_tcp = ctx->backend_data;
247 
248 #ifdef OS_WIN32
249  if (_modbus_tcp_init_win32() == -1) {
250  return -1;
251  }
252 #endif
253 
254  ctx->s = socket(PF_INET, SOCK_STREAM, 0);
255  if (ctx->s == -1) {
256  return -1;
257  }
258 
259  rc = _modbus_tcp_set_ipv4_options(ctx->s);
260  if (rc == -1) {
261  close(ctx->s);
262  return -1;
263  }
264 
265  if (ctx->debug) {
266  printf("Connecting to %s\n", ctx_tcp->ip);
267  }
268 
269  addr.sin_family = AF_INET;
270  addr.sin_port = htons(ctx_tcp->port);
271  addr.sin_addr.s_addr = inet_addr(ctx_tcp->ip);
272  rc = connect(ctx->s, (struct sockaddr *)&addr,
273  sizeof(struct sockaddr_in));
274  if (rc == -1) {
275  close(ctx->s);
276  return -1;
277  }
278 
279  return 0;
280 }
281 
282 /* Establishes a modbus TCP PI connection with a Modbus server. */
284 {
285  int rc;
286  struct addrinfo *ai_list;
287  struct addrinfo *ai_ptr;
288  struct addrinfo ai_hints;
289  modbus_tcp_pi_t *ctx_tcp_pi = ctx->backend_data;
290 
291 #ifdef OS_WIN32
292  if (_modbus_tcp_init_win32() == -1) {
293  return -1;
294  }
295 #endif
296 
297  memset(&ai_hints, 0, sizeof(ai_hints));
298 #ifdef AI_ADDRCONFIG
299  ai_hints.ai_flags |= AI_ADDRCONFIG;
300 #endif
301  ai_hints.ai_family = AF_UNSPEC;
302  ai_hints.ai_socktype = SOCK_STREAM;
303  ai_hints.ai_addr = NULL;
304  ai_hints.ai_canonname = NULL;
305  ai_hints.ai_next = NULL;
306 
307  ai_list = NULL;
308  rc = getaddrinfo(ctx_tcp_pi->node, ctx_tcp_pi->service,
309  &ai_hints, &ai_list);
310  if (rc != 0)
311  return rc;
312 
313  for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) {
314  int s;
315 
316  s = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
317  if (s < 0)
318  continue;
319 
320  if (ai_ptr->ai_family == AF_INET)
322 
323  rc = connect(s, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
324  if (rc != 0) {
325  close(s);
326  continue;
327  }
328 
329  ctx->s = s;
330  break;
331  }
332 
333  freeaddrinfo(ai_list);
334 
335  if (ctx->s < 0) {
336  return -1;
337  }
338 
339  return 0;
340 }
341 
342 /* Closes the network connection and socket in TCP mode */
344 {
345  shutdown(ctx->s, SHUT_RDWR);
346  close(ctx->s);
347 }
348 
350 {
351  int rc;
352  int rc_sum = 0;
353 
354  do {
355  /* Extract the garbage from the socket */
356  char devnull[MODBUS_TCP_MAX_ADU_LENGTH];
357 #ifndef OS_WIN32
358  rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, MSG_DONTWAIT);
359 #else
360  /* On Win32, it's a bit more complicated to not wait */
361  fd_set rfds;
362  struct timeval tv;
363 
364  tv.tv_sec = 0;
365  tv.tv_usec = 0;
366  FD_ZERO(&rfds);
367  FD_SET(ctx->s, &rfds);
368  rc = select(ctx->s+1, &rfds, NULL, NULL, &tv);
369  if (rc == -1) {
370  return -1;
371  }
372 
373  if (rc == 1) {
374  /* There is data to flush */
375  rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, 0);
376  }
377 #endif
378  if (rc > 0) {
379  rc_sum += rc;
380  }
381  } while (rc == MODBUS_TCP_MAX_ADU_LENGTH);
382 
383  return rc_sum;
384 }
385 
386 /* Listens for any request from one or many modbus masters in TCP */
387 int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
388 {
389  int new_socket;
390  int yes;
391  struct sockaddr_in addr;
392  modbus_tcp_t *ctx_tcp = ctx->backend_data;
393 
394 #ifdef OS_WIN32
395  if (_modbus_tcp_init_win32() == -1) {
396  return -1;
397  }
398 #endif
399 
400  new_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
401  if (new_socket == -1) {
402  return -1;
403  }
404 
405  yes = 1;
406  if (setsockopt(new_socket, SOL_SOCKET, SO_REUSEADDR,
407  (char *) &yes, sizeof(yes)) == -1) {
408  close(new_socket);
409  return -1;
410  }
411 
412  memset(&addr, 0, sizeof(addr));
413  addr.sin_family = AF_INET;
414  /* If the modbus port is < to 1024, we need the setuid root. */
415  addr.sin_port = htons(ctx_tcp->port);
416  addr.sin_addr.s_addr = INADDR_ANY;
417  if (bind(new_socket, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
418  close(new_socket);
419  return -1;
420  }
421 
422  if (listen(new_socket, nb_connection) == -1) {
423  close(new_socket);
424  return -1;
425  }
426 
427  return new_socket;
428 }
429 
430 int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
431 {
432  int rc;
433  struct addrinfo *ai_list;
434  struct addrinfo *ai_ptr;
435  struct addrinfo ai_hints;
436  const char *node;
437  const char *service;
438  int new_socket;
439  modbus_tcp_pi_t *ctx_tcp_pi = ctx->backend_data;
440 
441  if (ctx_tcp_pi->node[0] == 0)
442  node = NULL; /* == any */
443  else
444  node = ctx_tcp_pi->node;
445 
446  if (ctx_tcp_pi->service[0] == 0)
447  service = "502";
448  else
449  service = ctx_tcp_pi->service;
450 
451  memset(&ai_hints, 0, sizeof (ai_hints));
452  ai_hints.ai_flags |= AI_PASSIVE;
453 #ifdef AI_ADDRCONFIG
454  ai_hints.ai_flags |= AI_ADDRCONFIG;
455 #endif
456  ai_hints.ai_family = AF_UNSPEC;
457  ai_hints.ai_socktype = SOCK_STREAM;
458  ai_hints.ai_addr = NULL;
459  ai_hints.ai_canonname = NULL;
460  ai_hints.ai_next = NULL;
461 
462  ai_list = NULL;
463  rc = getaddrinfo(node, service, &ai_hints, &ai_list);
464  if (rc != 0)
465  return -1;
466 
467  new_socket = -1;
468  for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) {
469  int s;
470 
471  s = socket(ai_ptr->ai_family, ai_ptr->ai_socktype,
472  ai_ptr->ai_protocol);
473  if (s < 0) {
474  if (ctx->debug) {
475  perror("socket");
476  }
477  continue;
478  } else {
479  int yes = 1;
480  rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
481  (void *) &yes, sizeof (yes));
482  if (rc != 0) {
483  close(s);
484  if (ctx->debug) {
485  perror("setsockopt");
486  }
487  continue;
488  }
489  }
490 
491  rc = bind(s, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
492  if (rc != 0) {
493  close(s);
494  if (ctx->debug) {
495  perror("bind");
496  }
497  continue;
498  }
499 
500  rc = listen(s, nb_connection);
501  if (rc != 0) {
502  close(s);
503  if (ctx->debug) {
504  perror("listen");
505  }
506  continue;
507  }
508 
509  new_socket = s;
510  break;
511  }
512  freeaddrinfo(ai_list);
513 
514  if (new_socket < 0) {
515  return -1;
516  }
517 
518  return new_socket;
519 }
520 
521 /* On success, the function return a non-negative integer that is a descriptor
522  for the accepted socket. On error, -1 is returned, and errno is set
523  appropriately. */
524 int modbus_tcp_accept(modbus_t *ctx, int *socket)
525 {
526  struct sockaddr_in addr;
527  socklen_t addrlen;
528 
529  addrlen = sizeof(addr);
530  ctx->s = accept(*socket, (struct sockaddr *)&addr, &addrlen);
531  if (ctx->s == -1) {
532  close(*socket);
533  *socket = 0;
534  return -1;
535  }
536 
537  if (ctx->debug) {
538  printf("The client connection from %s is accepted\n",
539  inet_ntoa(addr.sin_addr));
540  }
541 
542  return ctx->s;
543 }
544 
546 {
547  struct sockaddr_storage addr;
548  socklen_t addrlen;
549 
550  addrlen = sizeof(addr);
551  ctx->s = accept(*socket, (void *)&addr, &addrlen);
552  if (ctx->s == -1) {
553  close(*socket);
554  *socket = 0;
555  }
556 
557  if (ctx->debug) {
558  printf("The client connection is accepted.\n");
559  }
560 
561  return ctx->s;
562 }
563 
564 int _modbus_tcp_select(modbus_t *ctx, fd_set *rfds, struct timeval *tv, int length_to_read)
565 {
566  int s_rc;
567  while ((s_rc = select(ctx->s+1, rfds, NULL, NULL, tv)) == -1) {
568  if (errno == EINTR) {
569  if (ctx->debug) {
570  fprintf(stderr, "A non blocked signal was caught\n");
571  }
572  /* Necessary after an error */
573  FD_ZERO(rfds);
574  FD_SET(ctx->s, rfds);
575  } else {
576  return -1;
577  }
578  }
579 
580  if (s_rc == 0) {
581  errno = ETIMEDOUT;
582  return -1;
583  }
584 
585  return s_rc;
586 }
587 
589 {
590  return 0;
591 }
592 
612 };
613 
614 
634 };
635 
636 modbus_t* modbus_new_tcp(const char *ip, int port)
637 {
638  modbus_t *ctx;
639  modbus_tcp_t *ctx_tcp;
640  size_t dest_size;
641  size_t ret_size;
642 
643 #if defined(OS_BSD)
644  /* MSG_NOSIGNAL is unsupported on *BSD so we install an ignore
645  handler for SIGPIPE. */
646  struct sigaction sa;
647 
648  sa.sa_handler = SIG_IGN;
649  if (sigaction(SIGPIPE, &sa, NULL) < 0) {
650  /* The debug flag can't be set here... */
651  fprintf(stderr, "Coud not install SIGPIPE handler.\n");
652  return NULL;
653  }
654 #endif
655 
656  ctx = (modbus_t *) malloc(sizeof(modbus_t));
657  _modbus_init_common(ctx);
658 
659  /* Could be changed after to reach a remote serial Modbus device */
660  ctx->slave = MODBUS_TCP_SLAVE;
661 
662  ctx->backend = &(_modbus_tcp_backend);
663 
664  ctx->backend_data = (modbus_tcp_t *) malloc(sizeof(modbus_tcp_t));
665  ctx_tcp = (modbus_tcp_t *)ctx->backend_data;
666 
667  dest_size = sizeof(char) * 16;
668  ret_size = strlcpy(ctx_tcp->ip, ip, dest_size);
669  if (ret_size == 0) {
670  fprintf(stderr, "The IP string is empty\n");
671  modbus_free(ctx);
672  errno = EINVAL;
673  return NULL;
674  }
675 
676  if (ret_size >= dest_size) {
677  fprintf(stderr, "The IP string has been truncated\n");
678  modbus_free(ctx);
679  errno = EINVAL;
680  return NULL;
681  }
682 
683  ctx_tcp->port = port;
684 
685  return ctx;
686 }
687 
688 
689 modbus_t* modbus_new_tcp_pi(const char *node, const char *service)
690 {
691  modbus_t *ctx;
692  modbus_tcp_pi_t *ctx_tcp_pi;
693  size_t dest_size;
694  size_t ret_size;
695 
696  ctx = (modbus_t *) malloc(sizeof(modbus_t));
697  _modbus_init_common(ctx);
698 
699  /* Could be changed after to reach a remote serial Modbus device */
700  ctx->slave = MODBUS_TCP_SLAVE;
701 
703 
704  ctx->backend_data = (modbus_tcp_pi_t *) malloc(sizeof(modbus_tcp_pi_t));
705  ctx_tcp_pi = (modbus_tcp_pi_t *)ctx->backend_data;
706 
707  dest_size = sizeof(char) * _MODBUS_TCP_PI_NODE_LENGTH;
708  ret_size = strlcpy(ctx_tcp_pi->node, node, dest_size);
709  if (ret_size == 0) {
710  fprintf(stderr, "The node string is empty\n");
711  modbus_free(ctx);
712  errno = EINVAL;
713  return NULL;
714  }
715 
716  if (ret_size >= dest_size) {
717  fprintf(stderr, "The node string has been truncated\n");
718  modbus_free(ctx);
719  errno = EINVAL;
720  return NULL;
721  }
722 
723  dest_size = sizeof(char) * _MODBUS_TCP_PI_SERVICE_LENGTH;
724  ret_size = strlcpy(ctx_tcp_pi->service, service, dest_size);
725  if (ret_size == 0) {
726  fprintf(stderr, "The service string is empty\n");
727  modbus_free(ctx);
728  errno = EINVAL;
729  return NULL;
730  }
731 
732  if (ret_size >= dest_size) {
733  fprintf(stderr, "The service string has been truncated\n");
734  modbus_free(ctx);
735  errno = EINVAL;
736  return NULL;
737  }
738 
739  return ctx;
740 }
modbus_t * modbus_new_tcp_pi(const char *node, const char *service)
Definition: modbus-tcp.c:689
int _modbus_tcp_build_response_basis(sft_t *sft, uint8_t *rsp)
Definition: modbus-tcp.c:137
int _modbus_tcp_prepare_response_tid(const uint8_t *req, int *req_length)
Definition: modbus-tcp.c:160
static int _modbus_tcp_set_ipv4_options(int s)
Definition: modbus-tcp.c:210
int modbus_tcp_pi_accept(modbus_t *ctx, int *socket)
Definition: modbus-tcp.c:545
size_t strlcpy(char *dest, const char *src, size_t dest_size)
Definition: modbus.c:1651
#define MODBUS_TCP_MAX_ADU_LENGTH
Definition: modbus-tcp.h:41
void modbus_free(modbus_t *ctx)
Definition: modbus.c:1528
const modbus_backend_t * backend
ssize_t _modbus_tcp_recv(modbus_t *ctx, uint8_t *rsp, int rsp_length)
Definition: modbus-tcp.c:185
int _modbus_tcp_check_integrity(modbus_t *ctx, uint8_t *msg, const int msg_length)
Definition: modbus-tcp.c:189
void * backend_data
int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
Definition: modbus-tcp.c:387
int slave
modbus_t * modbus_new_tcp(const char *ip, int port)
Definition: modbus-tcp.c:636
int _modbus_tcp_flush(modbus_t *ctx)
Definition: modbus-tcp.c:349
int _modbus_tcp_send_msg_pre(uint8_t *req, int req_length)
Definition: modbus-tcp.c:165
#define _MODBUS_TCP_PI_NODE_LENGTH
#define _MODBUS_TCP_PI_SERVICE_LENGTH
int modbus_tcp_accept(modbus_t *ctx, int *socket)
Definition: modbus-tcp.c:524
void _modbus_init_common(modbus_t *ctx)
Definition: modbus.c:1448
static int _modbus_tcp_pi_connect(modbus_t *ctx)
Definition: modbus-tcp.c:283
static int _modbus_set_slave(modbus_t *ctx, int slave)
Definition: modbus-tcp.c:81
int function
int _modbus_tcp_pre_check_confirmation(modbus_t *ctx, const uint8_t *req, const uint8_t *rsp, int rsp_length)
Definition: modbus-tcp.c:194
char node[_MODBUS_TCP_PI_NODE_LENGTH]
modbus_t * ctx
int _modbus_tcp_filter_request(modbus_t *ctx, int slave)
Definition: modbus-tcp.c:588
#define _MODBUS_TCP_HEADER_LENGTH
ssize_t _modbus_tcp_send(modbus_t *ctx, const uint8_t *req, int req_length)
Definition: modbus-tcp.c:176
#define EMBBADDATA
Definition: modbus.h:116
int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
Definition: modbus-tcp.c:430
#define _MODBUS_TCP_PRESET_RSP_LENGTH
#define _MODBUS_TCP_PRESET_REQ_LENGTH
#define MSG_NOSIGNAL
Definition: modbus-tcp.c:57
static int _modbus_tcp_connect(modbus_t *ctx)
Definition: modbus-tcp.c:242
#define MODBUS_TCP_SLAVE
Definition: modbus-tcp.h:36
#define _MODBUS_TCP_CHECKSUM_LENGTH
char service[_MODBUS_TCP_PI_SERVICE_LENGTH]
void _modbus_tcp_close(modbus_t *ctx)
Definition: modbus-tcp.c:343
int t_id
const modbus_backend_t _modbus_tcp_pi_backend
Definition: modbus-tcp.c:615
const modbus_backend_t _modbus_tcp_backend
Definition: modbus-tcp.c:593
int _modbus_tcp_select(modbus_t *ctx, fd_set *rfds, struct timeval *tv, int length_to_read)
Definition: modbus-tcp.c:564
int _modbus_tcp_build_request_basis(modbus_t *ctx, int function, int addr, int nb, uint8_t *req)
Definition: modbus-tcp.c:99


libmodbus
Author(s):
autogenerated on Sat Nov 21 2020 03:17:32