modbus-rtu-private.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #define ENOTSUP WSAEOPNOTSUPP
  39. /* WIN32: struct containing serial handle and a receive buffer */
  40. #define PY_BUF_SIZE 512
  41. struct win32_ser {
  42. /* File handle */
  43. HANDLE fd;
  44. /* Receive buffer */
  45. uint8_t buf[PY_BUF_SIZE];
  46. /* Received chars */
  47. DWORD n_bytes;
  48. };
  49. #endif /* _WIN32 */
  50. typedef struct _modbus_rtu {
  51. /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" on Mac OS X for
  52. KeySpan USB<->Serial adapters this string had to be made bigger on OS X
  53. as the directory+file name was bigger than 19 bytes. Making it 67 bytes
  54. for now, but OS X does support 256 byte file names. May become a problem
  55. in the future. */
  56. #if defined(__APPLE_CC__)
  57. char device[64];
  58. #else
  59. char device[16];
  60. #endif
  61. /* Bauds: 9600, 19200, 57600, 115200, etc */
  62. int baud;
  63. /* Data bit */
  64. uint8_t data_bit;
  65. /* Stop bit */
  66. uint8_t stop_bit;
  67. /* Parity: 'N', 'O', 'E' */
  68. char parity;
  69. #if defined(_WIN32)
  70. struct win32_ser w_ser;
  71. DCB old_dcb;
  72. #else
  73. /* Save old termios settings */
  74. struct termios old_tios;
  75. #endif
  76. #if HAVE_DECL_TIOCSRS485
  77. int serial_mode;
  78. int rts;
  79. #endif
  80. } modbus_rtu_t;
  81. #endif /* _MODBUS_RTU_PRIVATE_H_ */