'\" t .\" Title: modbus_read_registers .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 10/18/2014 .\" Manual: Libmodbus Manual .\" Source: libmodbus 3.0.6 .\" Language: English .\" .TH "MODBUS_READ_REGISTER" "3" "10/18/2014" "libmodbus 3\&.0\&.6" "Libmodbus Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" modbus_read_registers \- read many registers .SH "SYNOPSIS" .sp \fBint modbus_read_registers(modbus_t *\fR\fB\fIctx\fR\fR\fB, int \fR\fB\fIaddr\fR\fR\fB, int \fR\fB\fInb\fR\fR\fB, uint16_t *\fR\fB\fIdest\fR\fR\fB);\fR .SH "DESCRIPTION" .sp The \fImodbus_read_registers()\fR function shall read the content of the \fInb\fR holding registers to the address \fIaddr\fR of the remote device\&. The result of reading is stored in \fIdest\fR array as word values (16 bits)\&. .sp You must take care to allocate enough memory to store the results in \fIdest\fR (at least \fInb\fR * sizeof(uint16_t))\&. .sp The function uses the Modbus function code 0x03 (read holding registers)\&. .SH "RETURN VALUE" .sp The \fImodbus_read_registers()\fR function shall return the number of read registers if successful\&. Otherwise it shall return \-1 and set errno\&. .SH "ERRORS" .PP EMBMDATA .RS 4 Too many registers requested .RE .SH "EXAMPLE" .sp .if n \{\ .RS 4 .\} .nf modbus_t *ctx; uint16_t tab_reg[64]; int rc; int i; ctx = modbus_new_tcp("127\&.0\&.0\&.1", 1502); if (modbus_connect(ctx) == \-1) { fprintf(stderr, "Connection failed: %s\en", modbus_strerror(errno)); modbus_free(ctx); return \-1; } rc = modbus_read_registers(ctx, 0, 10, tab_reg); if (rc == \-1) { fprintf(stderr, "%s\en", modbus_strerror(errno)); return \-1; } for (i=0; i < rc; i++) { printf("reg[%d]=%d (0x%X)\en", i, tab_reg[i], tab_reg[i]); } modbus_close(ctx); modbus_free(ctx); .fi .if n \{\ .RE .\} .SH "SEE ALSO" .sp \fBmodbus_write_register\fR(3) \fBmodbus_write_registers\fR(3) .SH "AUTHORS" .sp The libmodbus documentation was written by St\('ephane Raimbault <\m[blue]\fBstephane\&.raimbault@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2> .SH "NOTES" .IP " 1." 4 stephane.raimbault@gmail.com .RS 4 \%mailto:stephane.raimbault@gmail.com .RE