modbus-rtu-private.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright © 2001-2010 Stéphane Raimbault <stephane.raimbault@gmail.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program 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
  12. * GNU Lesser Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _MODBUS_RTU_PRIVATE_H_
  18. #define _MODBUS_RTU_PRIVATE_H_
  19. #define _MODBUS_RTU_HEADER_LENGTH 1
  20. #define _MODBUS_RTU_PRESET_REQ_LENGTH 6
  21. #define _MODBUS_RTU_PRESET_RSP_LENGTH 2
  22. #define _MODBUS_RTU_CHECKSUM_LENGTH 2
  23. #ifdef NATIVE_WIN32
  24. #define WIN32_LEAN_AND_MEAN
  25. #include <windows.h>
  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 /* NATIVE_WIN32 */
  37. typedef struct _modbus_rtu {
  38. /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" on Mac OS X for
  39. KeySpan USB<->Serial adapters this string had to be made bigger on OS X
  40. as the directory+file name was bigger than 19 bytes. Making it 67 bytes
  41. for now, but OS X does support 256 byte file names. May become a problem
  42. in the future. */
  43. #ifdef __APPLE_CC__
  44. char device[64];
  45. #else
  46. char device[16];
  47. #endif
  48. /* Bauds: 9600, 19200, 57600, 115200, etc */
  49. int baud;
  50. /* Data bit */
  51. uint8_t data_bit;
  52. /* Stop bit */
  53. uint8_t stop_bit;
  54. /* Parity: 'N', 'O', 'E' */
  55. char parity;
  56. #ifdef NATIVE_WIN32
  57. struct win32_ser w_ser;
  58. DCB old_dcb;
  59. #else
  60. /* Save old termios settings */
  61. struct termios old_tios;
  62. #endif
  63. } modbus_rtu_t;
  64. #endif /* _MODBUS_RTU_PRIVATE_H_ */