modbus_new_tcp_pi.txt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 function shall return a pointer to a *modbus_t* structure if
  23. 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. *ENOMEM*::
  31. Out of memory. Possibly, the application hits its memory limit and/or whole
  32. system is running out of memory.
  33. EXAMPLE
  34. -------
  35. [source,c]
  36. -------------------
  37. modbus_t *ctx;
  38. ctx = modbus_new_tcp_pi("::1", "1502");
  39. if (ctx == NULL) {
  40. fprintf(stderr, "Unable to allocate libmodbus context\n");
  41. return -1;
  42. }
  43. if (modbus_connect(ctx) == -1) {
  44. fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
  45. modbus_free(ctx);
  46. return -1;
  47. }
  48. -------------------
  49. SEE ALSO
  50. --------
  51. linkmb:modbus_new_tcp[3]
  52. linkmb:modbus_tcp_pi_listen[3]
  53. linkmb:modbus_free[3]
  54. AUTHORS
  55. -------
  56. The libmodbus documentation was written by Stéphane Raimbault
  57. <stephane.raimbault@gmail.com>