5 modbus_mapping_new - allocate four arrays of bits and registers
10 modbus_mapping_t* modbus_mapping_new(int nb_bits, int nb_input_bits, int nb_registers, int nb_input_registers);
15 The *modbus_mapping_new()* function shall allocate four arrays to store bits,
16 input bits, registers and inputs registers. The pointers are stored in
17 modbus_mapping_t structure. All values of the arrays are initialized to zero.
19 This function is equivalent to a call of the
20 [modbus_mapping_new_start_address](modbus_mapping_new_start_address.md) function
21 with all start addresses to `0`.
23 If it isn't necessary to allocate an array for a specific type of data, you can
24 pass the zero value in argument, the associated pointer will be NULL.
26 This function is convenient to handle requests in a Modbus server/slave.
30 The function shall return the new allocated structure if successful. Otherwise
31 it shall return NULL and set errno.
35 - *ENOMEM*, not enough memory.
40 /* The first value of each array is accessible from the 0 address. */
41 mb_mapping = modbus_mapping_new(
42 BITS_ADDRESS + BITS_NB,
43 INPUT_BITS_ADDRESS + INPUT_BITS_NB,
44 REGISTERS_ADDRESS + REGISTERS_NB,
45 INPUT_REGISTERS_ADDRESS + INPUT_REGISTERS_NB
47 if (mb_mapping == NULL) {
49 stderr, "Failed to allocate the mapping: %s\n",
50 modbus_strerror(errno)
59 - [modbus_mapping_free](modbus_mapping_free.md)
60 - [modbus_mapping_new_start_address](modbus_mapping_new_start_address.md)