'\" t
.\" Title: modbus_mapping_new
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot
.\" Date: 10/15/2022
.\" Manual: libmodbus Manual
.\" Source: libmodbus v3.1.6
.\" Language: English
.\"
.TH "MODBUS_MAPPING_NEW" "3" "10/15/2022" "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 \- allocate four arrays of bits and registers
.SH "SYNOPSIS"
.sp
\fBmodbus_mapping_t\fR modbus_mapping_new(int \fInb_bits\fR, int \fInb_input_bits\fR, int \fInb_registers\fR, int \fInb_input_registers\fR);*
.SH "DESCRIPTION"
.sp
The \fBmodbus_mapping_new()\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
This function is equivalent to a call of the \fBmodbus_mapping_new_start_address\fR(3) function with all start addresses to 0\&.
.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 function shall return the new allocated structure if successful\&. Otherwise it shall return NULL and set errno\&.
.SH "ERRORS"
.PP
\fBENOMEM\fR
.RS 4
Not enough memory
.RE
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
/* The first value of each array is accessible from the 0 address\&. */
mb_mapping = modbus_mapping_new(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_free\fR(3) \fBmodbus_mapping_new_start_address\fR(3)
.SH "AUTHORS"
.sp
The libmodbus documentation was written by Stéphane Raimbault