modbus-tcp.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright © 2001-2010 Stéphane Raimbault <stephane.raimbault@gmail.com>
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1+
  5. */
  6. #ifndef MODBUS_TCP_H
  7. #define MODBUS_TCP_H
  8. #include "modbus.h"
  9. MODBUS_BEGIN_DECLS
  10. #if defined(_WIN32) && !defined(__CYGWIN__)
  11. /* Win32 with MinGW, supplement to <errno.h> */
  12. #include <winsock2.h>
  13. #if !defined(ECONNRESET)
  14. #define ECONNRESET WSAECONNRESET
  15. #endif
  16. #if !defined(ECONNREFUSED)
  17. #define ECONNREFUSED WSAECONNREFUSED
  18. #endif
  19. #if !defined(ETIMEDOUT)
  20. #define ETIMEDOUT WSAETIMEDOUT
  21. #endif
  22. #if !defined(ENOPROTOOPT)
  23. #define ENOPROTOOPT WSAENOPROTOOPT
  24. #endif
  25. #if !defined(EINPROGRESS)
  26. #define EINPROGRESS WSAEINPROGRESS
  27. #endif
  28. #endif
  29. #define MODBUS_TCP_DEFAULT_PORT 502
  30. #define MODBUS_TCP_SLAVE 0xFF
  31. /* Modbus_Application_Protocol_V1_1b.pdf Chapter 4 Section 1 Page 5
  32. * TCP MODBUS ADU = 253 bytes + MBAP (7 bytes) = 260 bytes
  33. */
  34. #define MODBUS_TCP_MAX_ADU_LENGTH 260
  35. MODBUS_API modbus_t* modbus_new_tcp(const char *ip_address, int port);
  36. MODBUS_API int modbus_tcp_listen(modbus_t *ctx, int nb_connection);
  37. MODBUS_API int modbus_tcp_accept(modbus_t *ctx, int *s);
  38. MODBUS_API modbus_t* modbus_new_tcp_pi(const char *node, const char *service);
  39. MODBUS_API int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection);
  40. MODBUS_API int modbus_tcp_pi_accept(modbus_t *ctx, int *s);
  41. MODBUS_END_DECLS
  42. #endif /* MODBUS_TCP_H */