1MODBUS_MAPPING_NEW_S(3) libmodbus Manual MODBUS_MAPPING_NEW_S(3)
2
3
4
6 modbus_mapping_new_start_address - allocate four arrays of bits and
7 registers accessible from their starting addresses
8
10 modbus_mapping_t modbus_mapping_new_start_address(int start_bits, int
11 nb_bits, int start_input_bits, int nb_input_bits, int start_registers,
12 int nb_registers, int start_input_registers, int nb_input_registers);*
13
15 The modbus_mapping_new_start_address() function shall allocate four
16 arrays to store bits, input bits, registers and inputs registers. The
17 pointers are stored in modbus_mapping_t structure. All values of the
18 arrays are initialized to zero.
19
20 The different starting adresses make it possible to place the mapping
21 at any address in each address space. This way, you can give access to
22 values stored at high adresses without allocating memory from the
23 address zero, for eg. to make available registers from 10000 to 10009,
24 you can use:
25
26 mb_mapping = modbus_mapping_new_start_address(0, 0, 0, 0, 10000, 10, 0, 0);
27
28 With this code, only 10 registers (uint16_t) are allocated.
29
30 If it isn’t necessary to allocate an array for a specific type of data,
31 you can pass the zero value in argument, the associated pointer will be
32 NULL.
33
34 This function is convenient to handle requests in a Modbus
35 server/slave.
36
38 The modbus_mapping_new_start_address() function shall return the new
39 allocated structure if successful. Otherwise it shall return NULL and
40 set errno.
41
43 ENOMEM
44 Not enough memory
45
47 /* The first value of each array is accessible at the defined address.
48 The end address is ADDRESS + NB - 1. */
49 mb_mapping = modbus_mapping_new_start_address(BITS_ADDRESS, BITS_NB,
50 INPUT_BITS_ADDRESS, INPUT_BITS_NB,
51 REGISTERS_ADDRESS, REGISTERS_NB,
52 INPUT_REGISTERS_ADDRESS, INPUT_REGISTERS_NB);
53 if (mb_mapping == NULL) {
54 fprintf(stderr, "Failed to allocate the mapping: %s\n",
55 modbus_strerror(errno));
56 modbus_free(ctx);
57 return -1;
58 }
59
61 modbus_mapping_new(3) modbus_mapping_free(3)
62
64 The libmodbus documentation was written by Stéphane Raimbault
65 <stephane.raimbault@gmail.com>
66
67
68
69libmodbus v3.1.6 01/19/2023 MODBUS_MAPPING_NEW_S(3)