modbus_mapping_new.txt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. modbus_mapping_new(3)
  2. =====================
  3. NAME
  4. ----
  5. modbus_mapping_new - allocate four arrays of bits and registers
  6. SYNOPSIS
  7. --------
  8. *modbus_mapping_t* modbus_mapping_new(int 'nb_bits', int 'nb_input_bits', int 'nb_registers', int 'nb_input_registers');*
  9. DESCRIPTION
  10. -----------
  11. The *modbus_mapping_new()* function shall allocate four arrays to store bits,
  12. input bits, registers and inputs registers. The pointers are stored in
  13. modbus_mapping_t structure. All values of the arrays are initialized to zero.
  14. This function is equivalent to a call of the
  15. linkmb:modbus_mapping_new_start_address[3] function with all start addresses to
  16. `0`.
  17. If it isn't necessary to allocate an array for a specific type of data, you can
  18. pass the zero value in argument, the associated pointer will be NULL.
  19. This function is convenient to handle requests in a Modbus server/slave.
  20. RETURN VALUE
  21. ------------
  22. The function shall return the new allocated structure if successful. Otherwise
  23. it shall return NULL and set errno.
  24. ERRORS
  25. ------
  26. *ENOMEM*::
  27. Not enough memory
  28. EXAMPLE
  29. -------
  30. [source,c]
  31. -------------------
  32. /* The first value of each array is accessible from the 0 address. */
  33. mb_mapping = modbus_mapping_new(BITS_ADDRESS + BITS_NB,
  34. INPUT_BITS_ADDRESS + INPUT_BITS_NB,
  35. REGISTERS_ADDRESS + REGISTERS_NB,
  36. INPUT_REGISTERS_ADDRESS + INPUT_REGISTERS_NB);
  37. if (mb_mapping == NULL) {
  38. fprintf(stderr, "Failed to allocate the mapping: %s\n",
  39. modbus_strerror(errno));
  40. modbus_free(ctx);
  41. return -1;
  42. }
  43. -------------------
  44. SEE ALSO
  45. --------
  46. linkmb:modbus_mapping_free[3]
  47. linkmb:modbus_mapping_new_start_address[3]
  48. AUTHORS
  49. -------
  50. The libmodbus documentation was written by Stéphane Raimbault
  51. <stephane.raimbault@gmail.com>