unit-test-client.c
Go to the documentation of this file.
1 /*
2  * Copyright © 2008-2010 Stéphane Raimbault <stephane.raimbault@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <stdio.h>
19 #include <unistd.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #include <errno.h>
23 #include <modbus.h>
24 
25 #include "unit-test.h"
26 
27 enum {
28  TCP,
31 };
32 
33 int main(int argc, char *argv[])
34 {
35  uint8_t *tab_rp_bits;
36  uint16_t *tab_rp_registers;
37  uint16_t *tab_rp_registers_bad;
38  modbus_t *ctx;
39  int i;
40  uint8_t value;
41  int nb_points;
42  int rc;
43  float real;
44  uint32_t ireal;
45  struct timeval old_response_timeout;
46  struct timeval response_timeout;
47  int use_backend;
48 
49  if (argc > 1) {
50  if (strcmp(argv[1], "tcp") == 0) {
51  use_backend = TCP;
52  } else if (strcmp(argv[1], "tcppi") == 0) {
53  use_backend = TCP_PI;
54  } else if (strcmp(argv[1], "rtu") == 0) {
55  use_backend = RTU;
56  } else {
57  printf("Usage:\n %s [tcp|tcppi|rtu] - Modbus client for unit testing\n\n", argv[0]);
58  exit(1);
59  }
60  } else {
61  /* By default */
62  use_backend = TCP;
63  }
64 
65  if (use_backend == TCP) {
66  ctx = modbus_new_tcp("127.0.0.1", 1502);
67  } else if (use_backend == TCP_PI) {
68  ctx = modbus_new_tcp_pi("::1", "1502");
69  } else {
70  ctx = modbus_new_rtu("/dev/ttyUSB1", 115200, 'N', 8, 1);
71  }
72  if (ctx == NULL) {
73  fprintf(stderr, "Unable to allocate libmodbus context\n");
74  return -1;
75  }
76  modbus_set_debug(ctx, TRUE);
80 
81  if (use_backend == RTU) {
83  }
84 
85  if (modbus_connect(ctx) == -1) {
86  fprintf(stderr, "Connection failed: %s\n",
87  modbus_strerror(errno));
88  modbus_free(ctx);
89  return -1;
90  }
91 
92  /* Allocate and initialize the memory to store the bits */
93  nb_points = (UT_BITS_NB > UT_INPUT_BITS_NB) ? UT_BITS_NB : UT_INPUT_BITS_NB;
94  tab_rp_bits = (uint8_t *) malloc(nb_points * sizeof(uint8_t));
95  memset(tab_rp_bits, 0, nb_points * sizeof(uint8_t));
96 
97  /* Allocate and initialize the memory to store the registers */
98  nb_points = (UT_REGISTERS_NB > UT_INPUT_REGISTERS_NB) ?
99  UT_REGISTERS_NB : UT_INPUT_REGISTERS_NB;
100  tab_rp_registers = (uint16_t *) malloc(nb_points * sizeof(uint16_t));
101  memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t));
102 
103  printf("** UNIT TESTING **\n");
104 
105  printf("\nTEST WRITE/READ:\n");
106 
109  /* Single */
110  rc = modbus_write_bit(ctx, UT_BITS_ADDRESS, ON);
111  printf("1/2 modbus_write_bit: ");
112  if (rc == 1) {
113  printf("OK\n");
114  } else {
115  printf("FAILED\n");
116  goto close;
117  }
118 
119  rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, 1, tab_rp_bits);
120  printf("2/2 modbus_read_bits: ");
121  if (rc != 1) {
122  printf("FAILED (nb points %d)\n", rc);
123  goto close;
124  }
125 
126  if (tab_rp_bits[0] != ON) {
127  printf("FAILED (%0X = != %0X)\n", tab_rp_bits[0], ON);
128  goto close;
129  }
130  printf("OK\n");
131  /* End single */
132 
133  /* Multiple bits */
134  {
135  uint8_t tab_value[UT_BITS_NB];
136 
137  modbus_set_bits_from_bytes(tab_value, 0, UT_BITS_NB, UT_BITS_TAB);
138  rc = modbus_write_bits(ctx, UT_BITS_ADDRESS,
139  UT_BITS_NB, tab_value);
140  printf("1/2 modbus_write_bits: ");
141  if (rc == UT_BITS_NB) {
142  printf("OK\n");
143  } else {
144  printf("FAILED\n");
145  goto close;
146  }
147  }
148 
149  rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, UT_BITS_NB, tab_rp_bits);
150  printf("2/2 modbus_read_bits: ");
151  if (rc != UT_BITS_NB) {
152  printf("FAILED (nb points %d)\n", rc);
153  goto close;
154  }
155 
156  i = 0;
157  nb_points = UT_BITS_NB;
158  while (nb_points > 0) {
159  int nb_bits = (nb_points > 8) ? 8 : nb_points;
160 
161  value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits);
162  if (value != UT_BITS_TAB[i]) {
163  printf("FAILED (%0X != %0X)\n", value, UT_BITS_TAB[i]);
164  goto close;
165  }
166 
167  nb_points -= nb_bits;
168  i++;
169  }
170  printf("OK\n");
171  /* End of multiple bits */
172 
174  rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS,
175  UT_INPUT_BITS_NB, tab_rp_bits);
176  printf("1/1 modbus_read_input_bits: ");
177 
178  if (rc != UT_INPUT_BITS_NB) {
179  printf("FAILED (nb points %d)\n", rc);
180  goto close;
181  }
182 
183  i = 0;
184  nb_points = UT_INPUT_BITS_NB;
185  while (nb_points > 0) {
186  int nb_bits = (nb_points > 8) ? 8 : nb_points;
187 
188  value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits);
189  if (value != UT_INPUT_BITS_TAB[i]) {
190  printf("FAILED (%0X != %0X)\n", value, UT_INPUT_BITS_TAB[i]);
191  goto close;
192  }
193 
194  nb_points -= nb_bits;
195  i++;
196  }
197  printf("OK\n");
198 
201  /* Single register */
202  rc = modbus_write_register(ctx, UT_REGISTERS_ADDRESS, 0x1234);
203  printf("1/2 modbus_write_register: ");
204  if (rc == 1) {
205  printf("OK\n");
206  } else {
207  printf("FAILED\n");
208  goto close;
209  }
210 
211  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
212  1, tab_rp_registers);
213  printf("2/2 modbus_read_registers: ");
214  if (rc != 1) {
215  printf("FAILED (nb points %d)\n", rc);
216  goto close;
217  }
218 
219  if (tab_rp_registers[0] != 0x1234) {
220  printf("FAILED (%0X != %0X)\n",
221  tab_rp_registers[0], 0x1234);
222  goto close;
223  }
224  printf("OK\n");
225  /* End of single register */
226 
227  /* Many registers */
228  rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS,
229  UT_REGISTERS_NB, UT_REGISTERS_TAB);
230  printf("1/5 modbus_write_registers: ");
231  if (rc == UT_REGISTERS_NB) {
232  printf("OK\n");
233  } else {
234  printf("FAILED\n");
235  goto close;
236  }
237 
238  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
239  UT_REGISTERS_NB, tab_rp_registers);
240  printf("2/5 modbus_read_registers: ");
241  if (rc != UT_REGISTERS_NB) {
242  printf("FAILED (nb points %d)\n", rc);
243  goto close;
244  }
245 
246  for (i=0; i < UT_REGISTERS_NB; i++) {
247  if (tab_rp_registers[i] != UT_REGISTERS_TAB[i]) {
248  printf("FAILED (%0X != %0X)\n",
249  tab_rp_registers[i],
250  UT_REGISTERS_TAB[i]);
251  goto close;
252  }
253  }
254  printf("OK\n");
255 
256  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
257  0, tab_rp_registers);
258  printf("3/5 modbus_read_registers (0): ");
259  if (rc != -1 && errno == EMBMDATA) {
260  printf("FAILED (nb points %d)\n", rc);
261  goto close;
262  }
263  printf("OK\n");
264 
265  nb_points = (UT_REGISTERS_NB >
266  UT_INPUT_REGISTERS_NB) ?
267  UT_REGISTERS_NB : UT_INPUT_REGISTERS_NB;
268  memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t));
269 
270  /* Write registers to zero from tab_rp_registers and store read registers
271  into tab_rp_registers. So the read registers must set to 0, except the
272  first one because there is an offset of 1 register on write. */
274  UT_REGISTERS_ADDRESS + 1, UT_REGISTERS_NB - 1,
275  tab_rp_registers,
276  UT_REGISTERS_ADDRESS,
277  UT_REGISTERS_NB,
278  tab_rp_registers);
279  printf("4/5 modbus_write_and_read_registers: ");
280  if (rc != UT_REGISTERS_NB) {
281  printf("FAILED (nb points %d != %d)\n", rc, UT_REGISTERS_NB);
282  goto close;
283  }
284 
285  if (tab_rp_registers[0] != UT_REGISTERS_TAB[0]) {
286  printf("FAILED (%0X != %0X)\n",
287  tab_rp_registers[0], UT_REGISTERS_TAB[0]);
288  }
289 
290  for (i=1; i < UT_REGISTERS_NB; i++) {
291  if (tab_rp_registers[i] != 0) {
292  printf("FAILED (%0X != %0X)\n",
293  tab_rp_registers[i], 0);
294  goto close;
295  }
296  }
297  printf("OK\n");
298 
299  /* End of many registers */
300 
301 
303  rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS,
304  UT_INPUT_REGISTERS_NB,
305  tab_rp_registers);
306  printf("1/1 modbus_read_input_registers: ");
307  if (rc != UT_INPUT_REGISTERS_NB) {
308  printf("FAILED (nb points %d)\n", rc);
309  goto close;
310  }
311 
312  for (i=0; i < UT_INPUT_REGISTERS_NB; i++) {
313  if (tab_rp_registers[i] != UT_INPUT_REGISTERS_TAB[i]) {
314  printf("FAILED (%0X != %0X)\n",
315  tab_rp_registers[i], UT_INPUT_REGISTERS_TAB[i]);
316  goto close;
317  }
318  }
319  printf("OK\n");
320 
321  printf("\nTEST FLOATS\n");
323  printf("1/2 Set float: ");
324  modbus_set_float(UT_REAL, tab_rp_registers);
325  if (tab_rp_registers[1] == (UT_IREAL >> 16) &&
326  tab_rp_registers[0] == (UT_IREAL & 0xFFFF)) {
327  printf("OK\n");
328  } else {
329  /* Avoid *((uint32_t *)tab_rp_registers)
330  * https://github.com/stephane/libmodbus/pull/104 */
331  ireal = (uint32_t) tab_rp_registers[0] & 0xFFFF;
332  ireal |= (uint32_t) tab_rp_registers[1] << 16;
333  printf("FAILED (%x != %x)\n", ireal, UT_IREAL);
334  goto close;
335  }
336 
337  printf("2/2 Get float: ");
338  real = modbus_get_float(tab_rp_registers);
339  if (real == UT_REAL) {
340  printf("OK\n");
341  } else {
342  printf("FAILED (%f != %f)\n", real, UT_REAL);
343  goto close;
344  }
345 
346  printf("\nAt this point, error messages doesn't mean the test has failed\n");
347 
349  printf("\nTEST ILLEGAL DATA ADDRESS:\n");
350 
351  /* The mapping begins at 0 and ends at address + nb_points so
352  * the addresses are not valid. */
353 
354  rc = modbus_read_bits(ctx, UT_BITS_ADDRESS,
355  UT_BITS_NB + 1, tab_rp_bits);
356  printf("* modbus_read_bits: ");
357  if (rc == -1 && errno == EMBXILADD) {
358  printf("OK\n");
359  } else {
360  printf("FAILED\n");
361  goto close;
362  }
363 
364  rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS,
365  UT_INPUT_BITS_NB + 1, tab_rp_bits);
366  printf("* modbus_read_input_bits: ");
367  if (rc == -1 && errno == EMBXILADD)
368  printf("OK\n");
369  else {
370  printf("FAILED\n");
371  goto close;
372  }
373 
374  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
375  UT_REGISTERS_NB + 1, tab_rp_registers);
376  printf("* modbus_read_registers: ");
377  if (rc == -1 && errno == EMBXILADD)
378  printf("OK\n");
379  else {
380  printf("FAILED\n");
381  goto close;
382  }
383 
384  rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS,
385  UT_INPUT_REGISTERS_NB + 1,
386  tab_rp_registers);
387  printf("* modbus_read_input_registers: ");
388  if (rc == -1 && errno == EMBXILADD)
389  printf("OK\n");
390  else {
391  printf("FAILED\n");
392  goto close;
393  }
394 
395  rc = modbus_write_bit(ctx, UT_BITS_ADDRESS + UT_BITS_NB, ON);
396  printf("* modbus_write_bit: ");
397  if (rc == -1 && errno == EMBXILADD) {
398  printf("OK\n");
399  } else {
400  printf("FAILED\n");
401  goto close;
402  }
403 
404  rc = modbus_write_bits(ctx, UT_BITS_ADDRESS + UT_BITS_NB,
405  UT_BITS_NB, tab_rp_bits);
406  printf("* modbus_write_coils: ");
407  if (rc == -1 && errno == EMBXILADD) {
408  printf("OK\n");
409  } else {
410  printf("FAILED\n");
411  goto close;
412  }
413 
414  rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS + UT_REGISTERS_NB,
415  UT_REGISTERS_NB, tab_rp_registers);
416  printf("* modbus_write_registers: ");
417  if (rc == -1 && errno == EMBXILADD) {
418  printf("OK\n");
419  } else {
420  printf("FAILED\n");
421  goto close;
422  }
423 
424 
426  printf("\nTEST TOO MANY DATA ERROR:\n");
427 
428  rc = modbus_read_bits(ctx, UT_BITS_ADDRESS,
429  MODBUS_MAX_READ_BITS + 1, tab_rp_bits);
430  printf("* modbus_read_bits: ");
431  if (rc == -1 && errno == EMBMDATA) {
432  printf("OK\n");
433  } else {
434  printf("FAILED\n");
435  goto close;
436  }
437 
438  rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS,
439  MODBUS_MAX_READ_BITS + 1, tab_rp_bits);
440  printf("* modbus_read_input_bits: ");
441  if (rc == -1 && errno == EMBMDATA) {
442  printf("OK\n");
443  } else {
444  printf("FAILED\n");
445  goto close;
446  }
447 
448  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
450  tab_rp_registers);
451  printf("* modbus_read_registers: ");
452  if (rc == -1 && errno == EMBMDATA) {
453  printf("OK\n");
454  } else {
455  printf("FAILED\n");
456  goto close;
457  }
458 
459  rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS,
461  tab_rp_registers);
462  printf("* modbus_read_input_registers: ");
463  if (rc == -1 && errno == EMBMDATA) {
464  printf("OK\n");
465  } else {
466  printf("FAILED\n");
467  goto close;
468  }
469 
470  rc = modbus_write_bits(ctx, UT_BITS_ADDRESS,
471  MODBUS_MAX_WRITE_BITS + 1, tab_rp_bits);
472  printf("* modbus_write_bits: ");
473  if (rc == -1 && errno == EMBMDATA) {
474  printf("OK\n");
475  } else {
476  goto close;
477  printf("FAILED\n");
478  }
479 
480  rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS,
482  tab_rp_registers);
483  printf("* modbus_write_registers: ");
484  if (rc == -1 && errno == EMBMDATA) {
485  printf("OK\n");
486  } else {
487  printf("FAILED\n");
488  goto close;
489  }
490 
492  printf("\nTEST SLAVE REPLY:\n");
493  modbus_set_slave(ctx, INVALID_SERVER_ID);
494  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
495  UT_REGISTERS_NB, tab_rp_registers);
496  if (use_backend == RTU) {
497  const int RAW_REQ_LENGTH = 6;
498  uint8_t raw_req[] = { INVALID_SERVER_ID, 0x03, 0x00, 0x01, 0xFF, 0xFF };
499  uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
500 
501  /* No response in RTU mode */
502  printf("1/4-A No response from slave %d: ", INVALID_SERVER_ID);
503 
504  if (rc == -1 && errno == ETIMEDOUT) {
505  printf("OK\n");
506  } else {
507  printf("FAILED\n");
508  goto close;
509  }
510 
511  /* Send an invalid query with a wrong slave ID */
512  modbus_send_raw_request(ctx, raw_req,
513  RAW_REQ_LENGTH * sizeof(uint8_t));
514  rc = modbus_receive_confirmation(ctx, rsp);
515 
516  printf("1/4-B No response from slave %d with invalid request: ",
517  INVALID_SERVER_ID);
518 
519  if (rc == -1 && errno == ETIMEDOUT) {
520  printf("OK\n");
521  } else {
522  printf("FAILED (%d)\n", rc);
523  goto close;
524  }
525 
526  } else {
527  /* Response in TCP mode */
528  printf("1/4 Response from slave %d: ", 18);
529 
530  if (rc == UT_REGISTERS_NB) {
531  printf("OK\n");
532  } else {
533  printf("FAILED\n");
534  goto close;
535  }
536  }
537 
539  if (rc == -1) {
540  printf("Invalid broacast address\n");
541  goto close;
542  }
543 
544  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
545  UT_REGISTERS_NB, tab_rp_registers);
546  printf("2/4 Reply after a broadcast query: ");
547  if (rc == UT_REGISTERS_NB) {
548  printf("OK\n");
549  } else {
550  printf("FAILED\n");
551  goto close;
552  }
553 
554  /* Restore slave */
555  if (use_backend == RTU) {
557  } else {
559  }
560 
561  printf("3/4 Report slave ID: \n");
562  /* tab_rp_bits is used to store bytes */
563  rc = modbus_report_slave_id(ctx, tab_rp_bits);
564  if (rc == -1) {
565  printf("FAILED\n");
566  goto close;
567  }
568 
569  /* Slave ID is an arbitraty number for libmodbus */
570  if (rc > 0) {
571  printf("OK Slave ID is %d\n", tab_rp_bits[0]);
572  } else {
573  printf("FAILED\n");
574  goto close;
575  }
576 
577  /* Run status indicator */
578  if (rc > 1 && tab_rp_bits[1] == 0xFF) {
579  printf("OK Run Status Indicator is %s\n", tab_rp_bits[1] ? "ON" : "OFF");
580  } else {
581  printf("FAILED\n");
582  goto close;
583  }
584 
585  /* Print additional data as string */
586  if (rc > 2) {
587  printf("Additional data: ");
588  for (i=2; i < rc; i++) {
589  printf("%c", tab_rp_bits[i]);
590  }
591  printf("\n");
592  }
593 
594  /* Save original timeout */
595  modbus_get_response_timeout(ctx, &old_response_timeout);
596 
597  /* Define a new and too short timeout */
598  response_timeout.tv_sec = 0;
599  response_timeout.tv_usec = 0;
600  modbus_set_response_timeout(ctx, &response_timeout);
601 
602  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
603  UT_REGISTERS_NB, tab_rp_registers);
604  printf("4/4 Too short timeout: ");
605  if (rc == -1 && errno == ETIMEDOUT) {
606  printf("OK\n");
607  } else {
608  printf("FAILED (can fail on slow systems or Windows)\n");
609  }
610 
611  /* Restore original timeout */
612  modbus_set_response_timeout(ctx, &old_response_timeout);
613 
614  /* A wait and flush operation is done by the error recovery code of
615  * libmodbus */
616 
618  printf("\nTEST BAD RESPONSE ERROR:\n");
619 
620  /* Allocate only the required space */
621  tab_rp_registers_bad = (uint16_t *) malloc(
622  UT_REGISTERS_NB_SPECIAL * sizeof(uint16_t));
623  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS,
624  UT_REGISTERS_NB_SPECIAL, tab_rp_registers_bad);
625  printf("* modbus_read_registers: ");
626  if (rc == -1 && errno == EMBBADDATA) {
627  printf("OK\n");
628  } else {
629  printf("FAILED\n");
630  goto close;
631  }
632 
633  free(tab_rp_registers_bad);
634 
636  printf("\nTEST MANUAL EXCEPTION:\n");
637 
638  rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS_SPECIAL,
639  UT_REGISTERS_NB, tab_rp_registers);
640  printf("* modbus_read_registers at special address: ");
641  if (rc == -1 && errno == EMBXSBUSY) {
642  printf("OK\n");
643  } else {
644  printf("FAILED\n");
645  goto close;
646  }
647 
649  printf("\nTEST RAW REQUEST:\n");
650  {
651  const int RAW_REQ_LENGTH = 6;
652  uint8_t raw_req[] = { (use_backend == RTU) ? SERVER_ID : 0xFF,
653  0x03, 0x00, 0x01, 0x0, 0x05 };
654  int req_length;
655  uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
656 
657  req_length = modbus_send_raw_request(ctx, raw_req,
658  RAW_REQ_LENGTH * sizeof(uint8_t));
659 
660  printf("* modbus_send_raw_request: ");
661  if ((use_backend == RTU && req_length == (RAW_REQ_LENGTH + 2)) ||
662  ((use_backend == TCP || use_backend == TCP_PI) &&
663  req_length == (RAW_REQ_LENGTH + 6))) {
664  printf("OK\n");
665  } else {
666  printf("FAILED (%d)\n", req_length);
667  goto close;
668  }
669 
670  printf("* modbus_receive_confirmation: ");
671  rc = modbus_receive_confirmation(ctx, rsp);
672  if ((use_backend == RTU && rc == 15) ||
673  ((use_backend == TCP || use_backend == TCP_PI) &&
674  rc == 19)) {
675  printf("OK\n");
676  } else {
677  printf("FAILED (%d)\n", rc);
678  goto close;
679  }
680  }
681 
682  printf("\nALL TESTS PASS WITH SUCCESS.\n");
683 
684 close:
685  /* Free the memory */
686  free(tab_rp_bits);
687  free(tab_rp_registers);
688 
689  /* Close the connection */
690  modbus_close(ctx);
691  modbus_free(ctx);
692 
693  return 0;
694 }
#define MODBUS_MAX_WRITE_REGISTERS
Definition: modbus.h:81
#define EMBXSBUSY
Definition: modbus.h:108
float modbus_get_float(const uint16_t *src)
Definition: modbus-data.c:77
int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest)
Definition: modbus.c:1059
#define EMBMDATA
Definition: modbus.h:119
#define MODBUS_TCP_MAX_ADU_LENGTH
Definition: modbus-tcp.h:41
void modbus_free(modbus_t *ctx)
Definition: modbus.c:1528
#define MODBUS_MAX_READ_REGISTERS
Definition: modbus.h:80
int modbus_set_error_recovery(modbus_t *ctx, modbus_error_recovery_mode error_recovery)
Definition: modbus.c:1470
#define MODBUS_BROADCAST_ADDRESS
Definition: modbus.h:63
int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest)
Definition: modbus.c:1083
void modbus_set_debug(modbus_t *ctx, int boolean)
Definition: modbus.c:1537
void modbus_close(modbus_t *ctx)
Definition: modbus.c:1520
int modbus_set_slave(modbus_t *ctx, int slave)
Definition: modbus.c:1465
int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)
Definition: modbus.c:1173
#define SERVER_ID
void modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout)
Definition: modbus.c:1489
int modbus_write_register(modbus_t *ctx, int reg_addr, int value)
Definition: modbus.c:1225
#define EMBXILADD
Definition: modbus.h:104
int main(int argc, char *argv[])
#define MODBUS_MAX_WRITE_BITS
Definition: modbus.h:71
modbus_t * ctx
const char * modbus_strerror(int errnum)
Definition: modbus.c:53
void modbus_set_bits_from_bytes(uint8_t *dest, int index, unsigned int nb_bits, const uint8_t *tab_byte)
Definition: modbus-data.c:41
int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *data)
Definition: modbus.c:1290
void modbus_set_float(float f, uint16_t *dest)
Definition: modbus-data.c:89
#define EMBBADDATA
Definition: modbus.h:116
int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data)
Definition: modbus.c:1231
int modbus_receive_confirmation(modbus_t *ctx, uint8_t *rsp)
Definition: modbus.c:473
#define TRUE
Definition: modbus.h:52
modbus_t * modbus_new_rtu(const char *device, int baud, char parity, int data_bit, int stop_bit)
Definition: modbus-rtu.c:917
int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)
Definition: modbus.c:1153
modbus_t * modbus_new_tcp_pi(const char *node, const char *service)
Definition: modbus-tcp.c:689
#define ON
Definition: modbus.h:60
uint8_t modbus_get_byte_from_bits(const uint8_t *src, int index, unsigned int nb_bits)
Definition: modbus-data.c:57
int modbus_connect(modbus_t *ctx)
Definition: modbus.c:1515
#define MODBUS_MAX_READ_BITS
Definition: modbus.h:70
#define MODBUS_TCP_SLAVE
Definition: modbus-tcp.h:36
int modbus_report_slave_id(modbus_t *ctx, uint8_t *dest)
Definition: modbus.c:1410
void modbus_set_response_timeout(modbus_t *ctx, const struct timeval *timeout)
Definition: modbus.c:1494
int modbus_send_raw_request(modbus_t *ctx, uint8_t *raw_req, int raw_req_length)
Definition: modbus.c:204
int modbus_write_and_read_registers(modbus_t *ctx, int write_addr, int write_nb, const uint16_t *src, int read_addr, int read_nb, uint16_t *dest)
Definition: modbus.c:1336
modbus_t * modbus_new_tcp(const char *ip_address, int port)
Definition: modbus-tcp.c:636
int modbus_write_bit(modbus_t *ctx, int coil_addr, int status)
Definition: modbus.c:1218


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