modbus_mapping_offset_new.txt 2.0 KB

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