1 modbus_read_registers(3)
2 ========================
7 modbus_read_registers - read many registers
12 *int modbus_read_registers(modbus_t *'ctx', int 'addr', int 'nb', uint16_t *'dest');*
17 The *modbus_read_registers()* function shall read the content of the _nb_
18 holding registers to the address _addr_ of the remote device. The result of
19 reading is stored in _dest_ array as word values (16 bits).
21 You must take care to allocate enough memory to store the results in _dest_
22 (at least _nb_ * sizeof(uint16_t)).
24 The function uses the Modbus function code 0x03 (read holding registers).
29 The function shall return the number of read registers
30 if successful. Otherwise it shall return -1 and set errno.
36 Too many registers requested
48 ctx = modbus_new_tcp("127.0.0.1", 1502);
49 if (modbus_connect(ctx) == -1) {
50 fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
55 rc = modbus_read_registers(ctx, 0, 10, tab_reg);
57 fprintf(stderr, "%s\n", modbus_strerror(errno));
61 for (i=0; i < rc; i++) {
62 printf("reg[%d]=%d (0x%X)\n", i, tab_reg[i], tab_reg[i]);
72 linkmb:modbus_write_register[3]
73 linkmb:modbus_write_registers[3]
78 The libmodbus documentation was written by Stéphane Raimbault
79 <stephane.raimbault@gmail.com>