modbus_mapping_new_start_address.txt 2.6 KB

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