modbus_set_socket.txt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. modbus_set_socket(3)
  2. ====================
  3. NAME
  4. ----
  5. modbus_set_socket - set socket of the context
  6. SYNOPSIS
  7. --------
  8. *void modbus_set_socket(modbus_t *'ctx', int 'socket')*
  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. There is no return values.
  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>