rs232_windows.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2011 Petr Stetiar <[email protected]>, Gaben Ltd.
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use,
  8. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following
  11. * conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #ifndef __LIBRS232_WINDOWS_H__
  27. #define __LIBRS232_WINDOWS_H__
  28. #include <windows.h>
  29. #ifndef CBR_460800
  30. #define CBR_460800 460800
  31. #endif
  32. struct rs232_windows_t {
  33. HANDLE fd;
  34. COMMTIMEOUTS old_tm;
  35. DCB old_dcb;
  36. unsigned int r_timeout;
  37. unsigned int w_timeout;
  38. unsigned int r_buffer;
  39. unsigned int w_buffer;
  40. OVERLAPPED oWait;
  41. unsigned char wait_progress;
  42. DWORD wait_mask;
  43. };
  44. #define GET_PORT_TIMEOUTS(fd, t) \
  45. memset(t, 0, sizeof(COMMTIMEOUTS)); \
  46. if (!GetCommTimeouts(fd, t)) { \
  47. DBG("GetCommTimeouts() %s\n", last_error()); \
  48. return RS232_ERR_UNKNOWN; \
  49. }
  50. #define SET_PORT_TIMEOUTS(fd, t) \
  51. if (!SetCommTimeouts(fd, t)) { \
  52. DBG("SetCommTimeouts() %s\n", last_error()); \
  53. return RS232_ERR_UNKNOWN; \
  54. }
  55. #define GET_PORT_STATE(fd, pdcb) \
  56. memset(pdcb, 0, sizeof(DCB)); \
  57. if (!GetCommState(fd, pdcb)) { \
  58. DBG("GetCommState() %s\n", last_error()); \
  59. return RS232_ERR_UNKNOWN; \
  60. }
  61. #define SET_PORT_STATE(fd, pdcb) \
  62. if (!SetCommState(fd, pdcb)) { \
  63. DBG("SetCommState() %s\n", last_error()); \
  64. return RS232_ERR_UNKNOWN; \
  65. }
  66. #endif /* __LIBRS232_WINDOWS_H__ */