MODBUS_MAPPING_NEW(3)
π MODBUS_MAPPING_NEW π
okay bestie, welcome to the libmodbus Manual β this is the MODBUS_MAPPING_NEW(3) page and it's literally the moment your server stops being a fake and starts holding actual data. sit down, grab a strawberry π, we're doing this.
β¨ NAME β¨
modbus_mapping_new β allocate four arrays of bits and registers π
πΈ SYNOPSIS πΈ
modbus_mapping_t modbus_mapping_new(int nb_bits, int nb_input_bits, int
nb_registers, int nb_input_registers);*
π¦ DESCRIPTION π¦
so the way that modbus_mapping_new() works is: it allocates four arrays, and they're for bits, input bits, registers and input registers. the pointers to all of them get stored in the modbus_mapping_t structure. and every single value in those arrays? initialized to zero. clean slate, no crumbs, periodt.
this function is equivalent to calling modbus_mapping_new_start_address(3) with all the start addresses set to 0. like, same energy, just the shortcut version. π
and listen β if you don't actually need an array for one specific type of data, you can just pass the zero value in that argument and the associated pointer will be NULL. no drama, no wasted memory, we love a minimalist queen. β¨
this function is convenient to handle requests in a Modbus server/slave. that's the whole vibe. it's the thing you call so your server can actually answer people instead of ghosting them. π
π RETURN VALUE π
if it slays, the function shall return the new allocated structure. π«Ά
if it does not slay? it shall return NULL and set errno. that's your cue to go check what went wrong, bestie. π
π ERRORS π
ENOMEMβ Not enough memory. there is no more room in the club, the bouncer said no. π
π₯ EXAMPLE π₯
/* 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\n",
modbus_strerror(errno));
modbus_free(ctx);
return -1;
}
like look at that error handling, we check for NULL and everything. main character energy. π
π SEE ALSO π
go read those too, iykyk. π
π AUTHORS π
The libmodbus documentation was written by StΓ©phane Raimbault <stephane.raimbault@gmail.com> β thank you for the lore, icon. π
and that's the page fr fr π this waslibmodbus v3.1.6, dated11/17/2025, and it's theMODBUS_MAPPING_NEW(3)page β go allocate something iconic, bestie. π¦β¨πΈ
π¦ where this page comes from
- debian bookworm: libmodbus-dev 3.1.6-2.1+deb12u1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms