'\" t
.\" Title: modbus_mapping_new_start_address
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1
.\" Date: 02/28/2020
.\" Manual: libmodbus Manual
.\" Source: libmodbus v3.1.6
.\" Language: English
.\"
.TH "MODBUS_MAPPING_NEW_S" "3" "02/28/2020" "libmodbus v3\&.1\&.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_mapping_new_start_address \- allocate four arrays of bits and registers accessible from their starting addresses
.SH "SYNOPSIS"
.sp
\fBmodbus_mapping_t\fR modbus_mapping_new_start_address(int \fIstart_bits\fR, int \fInb_bits\fR, int \fIstart_input_bits\fR, int \fInb_input_bits\fR, int \fIstart_registers\fR, int \fInb_registers\fR, int \fIstart_input_registers\fR, int \fInb_input_registers\fR);*
.SH "DESCRIPTION"
.sp
The \fImodbus_mapping_new_start_address()\fR function shall allocate four arrays to store bits, input bits, registers and inputs registers\&. The pointers are stored in modbus_mapping_t structure\&. All values of the arrays are initialized to zero\&.
.sp
The different starting addresses make it possible to place the mapping at any address in each address space\&. This way, you can give access to values stored at high addresses without allocating memory from the address zero, for eg\&. to make available registers from 10000 to 10009, you can use:
.sp
.if n \{\
.RS 4
.\}
.nf
mb_mapping = modbus_mapping_new_start_address(0, 0, 0, 0, 10000, 10, 0, 0);
.fi
.if n \{\
.RE
.\}
.sp
With this code, only 10 registers (uint16_t) are allocated\&.
.sp
If it isn\(cqt necessary to allocate an array for a specific type of data, you can pass the zero value in argument, the associated pointer will be NULL\&.
.sp
This function is convenient to handle requests in a Modbus server/slave\&.
.SH "RETURN VALUE"
.sp
The \fImodbus_mapping_new_start_address()\fR function shall return the new allocated structure if successful\&. Otherwise it shall return NULL and set errno\&.
.SH "ERRORS"
.PP
ENOMEM
.RS 4
Not enough memory
.RE
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
/* The first value of each array is accessible at the defined address\&.
The end address is ADDRESS + NB \- 1\&. */
mb_mapping = modbus_mapping_new_start_address(BITS_ADDRESS, BITS_NB,
INPUT_BITS_ADDRESS, INPUT_BITS_NB,
REGISTERS_ADDRESS, REGISTERS_NB,
INPUT_REGISTERS_ADDRESS, INPUT_REGISTERS_NB);
if (mb_mapping == NULL) {
fprintf(stderr, "Failed to allocate the mapping: %s\en",
modbus_strerror(errno));
modbus_free(ctx);
return \-1;
}
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBmodbus_mapping_new\fR(3) \fBmodbus_mapping_free\fR(3)
.SH "AUTHORS"
.sp
The libmodbus documentation was written by Stéphane Raimbault