| 1 | # modbus_read_input_registers |
| 2 | |
| 3 | ## Name |
| 4 | |
| 5 | modbus_read_input_registers - read many input registers |
| 6 | |
| 7 | ## Synopsis |
| 8 | |
| 9 | ```c |
| 10 | int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest); |
| 11 | ``` |
| 12 | |
| 13 | ## Description |
| 14 | |
| 15 | The *modbus_read_input_registers()* function shall read the content of the `nb` |
| 16 | input registers to address `addr` of the remote device. The result of the |
| 17 | reading is stored in `dest` array as word values (16 bits). |
| 18 | |
| 19 | The `dest` array must be allocated with at least `nb * sizeof(uint16_t)` bytes. |
| 20 | It is the caller's responsibility to ensure the buffer is large enough to hold |
| 21 | all the registers to be read. |
| 22 | |
| 23 | The function uses the Modbus function code 0x04 (read input registers). The |
| 24 | holding registers and input registers have different historical meaning, but |
| 25 | nowadays it's more common to use holding registers only. |
| 26 | |
| 27 | ## Return value |
| 28 | |
| 29 | The function shall return the number of read input registers if |
| 30 | successful. Otherwise it shall return -1 and set errno. |
| 31 | |
| 32 | ## Errors |
| 33 | |
| 34 | - *EINVAL*, the `ctx` or `dest` argument is NULL, or `nb` is less than 1. |
| 35 | - *EMBXILVAL*, too many input registers requested (nb > MODBUS_MAX_READ_REGISTERS). |
| 36 | |
| 37 | ## See also |
| 38 | |
| 39 | - [modbus_read_input_bits](modbus_read_input_bits.md) |
| 40 | - [modbus_write_register](modbus_write_register.md) |
| 41 | - [modbus_write_registers](modbus_write_registers.md) |