modbus-rtu-private.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright © 2001-2011 Stéphane Raimbault <stephane.raimbault@gmail.com>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef _MODBUS_RTU_PRIVATE_H_
  19. #define _MODBUS_RTU_PRIVATE_H_
  20. #ifndef _MSC_VER
  21. #include <stdint.h>
  22. #else
  23. #include "stdint.h"
  24. #endif
  25. #if defined(_WIN32)
  26. #include <windows.h>
  27. #else
  28. #include <termios.h>
  29. #endif
  30. #define _MODBUS_RTU_HEADER_LENGTH 1
  31. #define _MODBUS_RTU_PRESET_REQ_LENGTH 6
  32. #define _MODBUS_RTU_PRESET_RSP_LENGTH 2
  33. #define _MODBUS_RTU_CHECKSUM_LENGTH 2
  34. /* Time waited beetween the RTS switch before transmit data or after transmit
  35. data before to read */
  36. #define _MODBUS_RTU_TIME_BETWEEN_RTS_SWITCH 10000
  37. #if defined(_WIN32)
  38. #if !defined(ENOTSUP)
  39. #define ENOTSUP WSAEOPNOTSUPP
  40. #endif
  41. /* WIN32: struct containing serial handle and a receive buffer */
  42. #define PY_BUF_SIZE 512
  43. struct win32_ser {
  44. /* File handle */
  45. HANDLE fd;
  46. /* Receive buffer */
  47. uint8_t buf[PY_BUF_SIZE];
  48. /* Received chars */
  49. DWORD n_bytes;
  50. };
  51. #endif /* _WIN32 */
  52. typedef struct _modbus_rtu {
  53. /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" on Mac OS X. */
  54. char *device;
  55. /* Bauds: 9600, 19200, 57600, 115200, etc */
  56. int baud;
  57. /* Data bit */
  58. uint8_t data_bit;
  59. /* Stop bit */
  60. uint8_t stop_bit;
  61. /* Parity: 'N', 'O', 'E' */
  62. char parity;
  63. #if defined(_WIN32)
  64. struct win32_ser w_ser;
  65. DCB old_dcb;
  66. #else
  67. /* Save old termios settings */
  68. struct termios old_tios;
  69. #endif
  70. #if HAVE_DECL_TIOCSRS485
  71. int serial_mode;
  72. #endif
  73. #if HAVE_DECL_TIOCM_RTS
  74. int rts;
  75. int onebyte_time;
  76. #endif
  77. /* To handle many slaves on the same link */
  78. int confirmation_to_ignore;
  79. } modbus_rtu_t;
  80. #endif /* _MODBUS_RTU_PRIVATE_H_ */