modbus_mapping_new.txt 1.6 KB

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