modbus_new_tcp_pi.txt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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". A NULL value can be used to
  15. listen any addresses in server mode.
  16. The _service_ argument is the service name/port number to connect to. To use the
  17. default Modbus port use the string "502". On many Unix systems, it’s
  18. convenient to use a port number greater than or equal to 1024 because it’s not
  19. necessary to have administrator privileges.
  20. RETURN VALUE
  21. ------------
  22. The *modbus_new_tcp_pi()* function shall return a pointer to a *modbus_t* structure
  23. if successful. Otherwise it shall return NULL and set errno to one of the values
  24. defined below.
  25. ERRORS
  26. ------
  27. *EINVAL*::
  28. The node string is empty or has been truncated. The service string is empty or
  29. has been truncated.
  30. EXAMPLE
  31. -------
  32. [source,c]
  33. -------------------
  34. modbus_t *ctx;
  35. ctx = modbus_new_tcp_pi("::1", "1502");
  36. if (ctx == NULL) {
  37. fprintf(stderr, "Unable to allocate libmodbus context\n");
  38. return -1;
  39. }
  40. if (modbus_connect(ctx) == -1) {
  41. fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
  42. modbus_free(ctx);
  43. return -1;
  44. }
  45. -------------------
  46. SEE ALSO
  47. --------
  48. linkmb:modbus_new_tcp[3]
  49. linkmb:modbus_tcp_pi_listen[3]
  50. linkmb:modbus_free[3]
  51. AUTHORS
  52. -------
  53. The libmodbus documentation was written by Stéphane Raimbault
  54. <stephane.raimbault@gmail.com>