1MODBUS_MAPPING_NEW(3)          libmodbus Manual          MODBUS_MAPPING_NEW(3)
2
3
4

NAME

6       modbus_mapping_new - allocate four arrays of bits and registers
7

SYNOPSIS

9       modbus_mapping_t modbus_mapping_new(int nb_bits, int nb_input_bits, int
10       nb_registers, int nb_input_registers);*
11

DESCRIPTION

13       The modbus_mapping_new() function shall allocate four arrays to store
14       bits, input bits, registers and inputs registers. The pointers are
15       stored in modbus_mapping_t structure. All values of the arrays are
16       initialized to zero.
17
18       This function is equivalent to a call of the
19       modbus_mapping_new_start_address(3) function with all start addresses
20       to 0.
21
22       If it isn’t necessary to allocate an array for a specific type of data,
23       you can pass the zero value in argument, the associated pointer will be
24       NULL.
25
26       This function is convenient to handle requests in a Modbus
27       server/slave.
28

RETURN VALUE

30       The function shall return the new allocated structure if successful.
31       Otherwise it shall return NULL and set errno.
32

ERRORS

34       ENOMEM
35           Not enough memory
36

EXAMPLE

38           /* The first value of each array is accessible from the 0 address. */
39           mb_mapping = modbus_mapping_new(BITS_ADDRESS + BITS_NB,
40                                           INPUT_BITS_ADDRESS + INPUT_BITS_NB,
41                                           REGISTERS_ADDRESS + REGISTERS_NB,
42                                           INPUT_REGISTERS_ADDRESS + INPUT_REGISTERS_NB);
43           if (mb_mapping == NULL) {
44               fprintf(stderr, "Failed to allocate the mapping: %s\n",
45                       modbus_strerror(errno));
46               modbus_free(ctx);
47               return -1;
48           }
49

SEE ALSO

51       modbus_mapping_free(3) modbus_mapping_new_start_address(3)
52

AUTHORS

54       The libmodbus documentation was written by Stéphane Raimbault
55       <stephane.raimbault@gmail.com>
56
57
58
59libmodbus v3.1.6                  02/04/2022             MODBUS_MAPPING_NEW(3)
Impressum