modbus-rtu-private.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include <stdint.h>
  20. #if defined(_WIN32)
  21. #include <windows.h>
  22. #else
  23. #include <termios.h>
  24. #endif
  25. #define _MODBUS_RTU_HEADER_LENGTH 1
  26. #define _MODBUS_RTU_PRESET_REQ_LENGTH 6
  27. #define _MODBUS_RTU_PRESET_RSP_LENGTH 2
  28. #define _MODBUS_RTU_CHECKSUM_LENGTH 2
  29. #if defined(_WIN32)
  30. /* WIN32: struct containing serial handle and a receive buffer */
  31. #define PY_BUF_SIZE 512
  32. struct win32_ser {
  33. /* File handle */
  34. HANDLE fd;
  35. /* Receive buffer */
  36. uint8_t buf[PY_BUF_SIZE];
  37. /* Received chars */
  38. DWORD n_bytes;
  39. };
  40. #endif /* _WIN32 */
  41. typedef struct _modbus_rtu {
  42. /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" on Mac OS X for
  43. KeySpan USB<->Serial adapters this string had to be made bigger on OS X
  44. as the directory+file name was bigger than 19 bytes. Making it 67 bytes
  45. for now, but OS X does support 256 byte file names. May become a problem
  46. in the future. */
  47. #if defined(__APPLE_CC__)
  48. char device[64];
  49. #else
  50. char device[16];
  51. #endif
  52. /* Bauds: 9600, 19200, 57600, 115200, etc */
  53. int baud;
  54. /* Data bit */
  55. uint8_t data_bit;
  56. /* Stop bit */
  57. uint8_t stop_bit;
  58. /* Parity: 'N', 'O', 'E' */
  59. char parity;
  60. #if defined(_WIN32)
  61. struct win32_ser w_ser;
  62. DCB old_dcb;
  63. #else
  64. /* Save old termios settings */
  65. struct termios old_tios;
  66. #endif
  67. } modbus_rtu_t;
  68. #endif /* _MODBUS_RTU_PRIVATE_H_ */