modbus_mapping_new.txt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 _modbus_mapping_offset_new()_ function
  15. with all offsets set to zero.
  16. If it isn't necessary to allocate an array for a specific type of data, you can
  17. pass the zero value in argument, the associated pointer will be NULL.
  18. This function is convenient to handle requests in a Modbus server/slave.
  19. RETURN VALUE
  20. ------------
  21. The function shall return the new allocated structure if successful. Otherwise
  22. it shall return NULL and set errno.
  23. ERRORS
  24. ------
  25. *ENOMEM*::
  26. Not enough memory
  27. EXAMPLE
  28. -------
  29. [source,c]
  30. -------------------
  31. /* The first value of each array is accessible from the 0 address. */
  32. mb_mapping = modbus_mapping_new(BITS_ADDRESS + BITS_NB,
  33. INPUT_BITS_ADDRESS + INPUT_BITS_NB,
  34. REGISTERS_ADDRESS + REGISTERS_NB,
  35. INPUT_REGISTERS_ADDRESS + INPUT_REGISTERS_NB);
  36. if (mb_mapping == NULL) {
  37. fprintf(stderr, "Failed to allocate the mapping: %s\n",
  38. modbus_strerror(errno));
  39. modbus_free(ctx);
  40. return -1;
  41. }
  42. -------------------
  43. SEE ALSO
  44. --------
  45. linkmb:modbus_mapping_free[3]
  46. AUTHORS
  47. -------
  48. The libmodbus documentation was written by Stéphane Raimbault
  49. <stephane.raimbault@gmail.com>