modbus_connect.txt 965 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. modbus_connect(3)
  2. =================
  3. NAME
  4. ----
  5. modbus_connect - establish a Modbus connection
  6. SYNOPSIS
  7. --------
  8. *int modbus_connect(modbus_t *'ctx');*
  9. DESCRIPTION
  10. -----------
  11. The *modbus_connect()* function shall establish a connection to a Modbus server,
  12. a network or a bus using the context information of libmodbus context given in
  13. argument.
  14. RETURN VALUE
  15. ------------
  16. The function shall return 0 if successful. Otherwise it shall return -1 and set
  17. errno to one of the values defined by the system calls of the underlying
  18. platform.
  19. EXAMPLE
  20. -------
  21. [source,c]
  22. -------------------
  23. modbus_t *ctx;
  24. ctx = modbus_new_tcp("127.0.0.1", 502);
  25. if (modbus_connect(ctx) == -1) {
  26. fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
  27. modbus_free(ctx);
  28. return -1;
  29. }
  30. -------------------
  31. SEE ALSO
  32. --------
  33. linkmb:modbus_close[3]
  34. AUTHORS
  35. -------
  36. The libmodbus documentation was written by Stéphane Raimbault
  37. <stephane.raimbault@gmail.com>