modbus_new_tcp_pi.txt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. modbus_new_tcp_pi(3)
  2. ====================
  3. NAME
  4. ----
  5. modbus_new_tcp_pi - create a libmodbus context for TCP Protocol Independent
  6. SYNOPSIS
  7. --------
  8. *modbus_t modbus_new_tcp_pi(const char *'node', const char *'service');*
  9. DESCRIPTION
  10. -----------
  11. The _modbus_new_tcp_pi()_ function shall allocate and initialize a modbus_t
  12. structure to communicate with a Modbus TCP IPv4 or Ipv6 server.
  13. The _node_ argument specifies the host name or IP address of the host to connect
  14. to, eg. '192.168.0.5' , '::1' or 'server.com'.
  15. The _service_ argument is the service name/port number to connect to. To use the
  16. default Modbus port use the string "502". On many Unix systems, it’s
  17. convenient to use a port number greater than or equal to 1024 because it’s not
  18. necessary to have administrator privileges.
  19. RETURN VALUE
  20. ------------
  21. The _modbus_new_tcp_pi()_ function shall return a pointer to a *modbus_t* structure
  22. if successful. Otherwise it shall return NULL and set errno to one of the values
  23. defined below.
  24. ERRORS
  25. ------
  26. *EINVAL*::
  27. The node string is empty or has been truncated. The service string is empty or
  28. has been truncated.
  29. EXAMPLE
  30. -------
  31. [source,c]
  32. -------------------
  33. modbus_t *ctx;
  34. ctx = modbus_new_tcp_pi("::1", "1502");
  35. if (ctx == NULL) {
  36. fprintf(stderr, "Unable to allocate libmodbus context\n");
  37. return -1;
  38. }
  39. if (modbus_connect(ctx) == -1) {
  40. fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
  41. modbus_free(ctx);
  42. return -1;
  43. }
  44. -------------------
  45. SEE ALSO
  46. --------
  47. linkmb:modbus_new_tcp[3]
  48. linkmb:modbus_new_rtu[3]
  49. linkmb:modbus_free[3]
  50. AUTHORS
  51. -------
  52. The libmodbus documentation was written by Stéphane Raimbault
  53. <stephane.raimbault@gmail.com>