modbus-rtu-private.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright © Stéphane Raimbault <stephane.raimbault@gmail.com>
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. */
  6. #ifndef MODBUS_RTU_PRIVATE_H
  7. #define MODBUS_RTU_PRIVATE_H
  8. #ifndef _MSC_VER
  9. #include <stdint.h>
  10. #else
  11. #include "stdint.h"
  12. #endif
  13. #if defined(_WIN32)
  14. #include <windows.h>
  15. #else
  16. #include <termios.h>
  17. #endif
  18. #define _MODBUS_RTU_HEADER_LENGTH 1
  19. #define _MODBUS_RTU_PRESET_REQ_LENGTH 6
  20. #define _MODBUS_RTU_PRESET_RSP_LENGTH 2
  21. #define _MODBUS_RTU_CHECKSUM_LENGTH 2
  22. #if defined(_WIN32)
  23. #if !defined(ENOTSUP)
  24. #define ENOTSUP WSAEOPNOTSUPP
  25. #endif
  26. /* WIN32: struct containing serial handle and a receive buffer */
  27. #define PY_BUF_SIZE 512
  28. struct win32_ser {
  29. /* File handle */
  30. HANDLE fd;
  31. /* Receive buffer */
  32. uint8_t buf[PY_BUF_SIZE];
  33. /* Received chars */
  34. DWORD n_bytes;
  35. };
  36. #endif /* _WIN32 */
  37. typedef struct _modbus_rtu {
  38. /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" on Mac OS X. */
  39. char *device;
  40. /* Bauds: 9600, 19200, 57600, 115200, etc */
  41. int baud;
  42. /* Data bit */
  43. uint8_t data_bit;
  44. /* Stop bit */
  45. uint8_t stop_bit;
  46. /* Parity: 'N', 'O', 'E' */
  47. char parity;
  48. #if defined(_WIN32)
  49. struct win32_ser w_ser;
  50. DCB old_dcb;
  51. #else
  52. /* Save old termios settings */
  53. struct termios old_tios;
  54. #endif
  55. #if HAVE_DECL_TIOCSRS485
  56. int serial_mode;
  57. #endif
  58. #if HAVE_DECL_TIOCM_RTS
  59. int rts;
  60. int rts_delay;
  61. int onebyte_time;
  62. void (*set_rts)(modbus_t *ctx, int on);
  63. #endif
  64. /* To handle many slaves on the same link */
  65. int confirmation_to_ignore;
  66. } modbus_rtu_t;
  67. #endif /* MODBUS_RTU_PRIVATE_H */