modbus_set_socket.txt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. modbus_set_socket(3)
  2. ====================
  3. NAME
  4. ----
  5. modbus_set_socket - set socket of the context
  6. SYNOPSIS
  7. --------
  8. *int modbus_set_socket(modbus_t *'ctx', int 's');*
  9. DESCRIPTION
  10. -----------
  11. The *modbus_set_socket()* function shall set the socket or file descriptor in
  12. the libmodbus context. This function is useful for managing multiple client
  13. connections to the same server.
  14. RETURN VALUE
  15. ------------
  16. The function shall return 0 if successful. Otherwise it shall return -1 and set errno.
  17. EXAMPLE
  18. -------
  19. [source,c]
  20. -------------------
  21. ctx = modbus_new_tcp("127.0.0.1", 1502);
  22. server_socket = modbus_tcp_listen(ctx, NB_CONNECTION);
  23. FD_ZERO(&rdset);
  24. FD_SET(server_socket, &rdset);
  25. /* .... */
  26. if (FD_ISSET(master_socket, &rdset)) {
  27. modbus_set_socket(ctx, master_socket);
  28. rc = modbus_receive(ctx, query);
  29. if (rc != -1) {
  30. modbus_reply(ctx, query, rc, mb_mapping);
  31. }
  32. }
  33. -------------------
  34. SEE ALSO
  35. --------
  36. linkmb:modbus_get_socket[3]
  37. AUTHORS
  38. -------
  39. The libmodbus documentation was written by Stéphane Raimbault
  40. <stephane.raimbault@gmail.com>