SerialPort_global.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * @file SerialPort_global.h
  3. * @author itas109 (itas109@qq.com) \n\n
  4. * Blog : https://blog.csdn.net/itas109 \n
  5. * Github : https://github.com/itas109 \n
  6. * QQ Group : 129518033
  7. * @brief global difine of CSerialPort 串口全局定义
  8. * @date 2020-04-29
  9. * @copyright The CSerialPort is Copyright (C) 2021 itas109. \n
  10. * Contact: itas109@qq.com \n\n
  11. * You may use, distribute and copy the CSerialPort under the terms of \n
  12. * GNU Lesser General Public License version 3, which is displayed below.
  13. */
  14. #ifndef __CSERIALPORT_GLOBAL_H__
  15. #define __CSERIALPORT_GLOBAL_H__
  16. // enum is not a class or namespace error
  17. // https://stackoverflow.com/questions/5188554/my-enum-is-not-a-class-or-namespace
  18. #include "osplatformutil.h"
  19. #include <iostream>
  20. #ifdef I_OS_WIN
  21. #if defined(__MINGW32__) || defined(__MINGW64__)
  22. typedef long long int64; ///< long long定义方式可以用于gcc/g++,不受平台限制,但不能用于VC6.0
  23. #else
  24. typedef __int64 int64; ///< __int64是Win32平台编译器64位长整型的定义方式,不能用于Linux
  25. #endif
  26. #define DLL_EXPORT __declspec(dllexport) ///< define DLL_EXPORT windows 定义windows导出函数
  27. #elif defined I_OS_UNIX
  28. //typedef long long int64; ///< 64 bit signed unix 定义Unix int64
  29. #define DLL_EXPORT __attribute__((visibility("default"))) ///< define DLL_EXPORT unix 定义Unix导出函数
  30. #else
  31. // Not support
  32. #endif // I_OS_WIN
  33. #ifdef _UNICODE
  34. #ifndef UNICODE
  35. #define UNICODE
  36. #endif
  37. #endif
  38. #ifdef UNICODE
  39. #ifndef _UNICODE
  40. #define _UNICODE
  41. #endif
  42. #endif
  43. namespace itas109
  44. {
  45. /**
  46. * @brief the read and write serial port mode enum 读写串口模式
  47. *
  48. */
  49. enum OperateMode
  50. {
  51. AsynchronousOperate, ///< Asynchronous 异步
  52. SynchronousOperate ///< Synchronous 同步
  53. };
  54. /**
  55. * @brief the BaudRate enum 波特率
  56. * @warning because baudrate is number, so it can be any value(includr follow definitions).
  57. * 因为波特率为数值类型,所以理论上可以为任意值(包括下列定义)
  58. */
  59. enum BaudRate
  60. {
  61. BaudRate110 = 110, ///< 110
  62. BaudRate300 = 300, ///< 300
  63. BaudRate600 = 600, ///< 600
  64. BaudRate1200 = 1200, ///< 1200
  65. BaudRate2400 = 2400, ///< 2400
  66. BaudRate4800 = 4800, ///< 4800
  67. BaudRate9600 = 9600, ///< 9600 recommend 推荐
  68. BaudRate14400 = 14400, ///< 14400
  69. BaudRate19200 = 19200, ///< 19200
  70. BaudRate38400 = 38400, ///< 38400
  71. BaudRate56000 = 56000, ///< 56000
  72. BaudRate57600 = 57600, ///< 57600
  73. BaudRate115200 = 115200, ///< 115200
  74. BaudRate921600 = 921600 ///< 921600
  75. };
  76. /**
  77. * @brief the DataBits enum 数据位
  78. * @warning
  79. * by QextSerialPort:\n
  80. * 5 data bits cannot be used with 2 stop bits 5位数据位不能使用2位停止位\n
  81. * 1.5 stop bits can only be used with 5 data bits 1.5位停止位不能使用5位数据位\n
  82. * 8 data bits cannot be used with space parity on POSIX systems POSIX系统8位数据位不能使用0校验
  83. * @warning windows Number of bits/byte, 4-8 windows数据位范围为4 - 8
  84. *
  85. */
  86. enum DataBits
  87. {
  88. DataBits5 = 5, ///< 5 data bits 5位数据位
  89. DataBits6 = 6, ///< 6 data bits 6位数据位
  90. DataBits7 = 7, ///< 7 data bits 7位数据位
  91. DataBits8 = 8 ///< 8 data bits 8位数据位
  92. };
  93. /**
  94. * @brief the Parity enum 校验位
  95. * @warning windows 0-4=None,Odd,Even,Mark,Space
  96. *
  97. */
  98. enum Parity
  99. {
  100. ParityNone = 0, ///< No Parity 无校验
  101. ParityOdd = 1, ///< Odd Parity 奇校验
  102. ParityEven = 2, ///< Even Parity 偶校验
  103. ParityMark = 3, ///< Mark Parity 1校验
  104. ParitySpace = 4, ///< Space Parity 0校验
  105. };
  106. /**
  107. * @brief the StopBits enum 停止位
  108. * @warning 1.5 stop bit only for the Windows platform 1.5位停止位仅对windows有效
  109. * @warning windows 0,1,2 = 1, 1.5, 2
  110. *
  111. */
  112. enum StopBits
  113. {
  114. StopOne = 0, ///< 1 stop bit 1位停止位
  115. StopOneAndHalf = 1, ///< 1.5 stop bit 1.5位停止位 - This is only for the Windows platform
  116. StopTwo = 2 ///< 2 stop bit 2位停止位
  117. };
  118. /**
  119. * @brief the FlowControl enum 流控制
  120. *
  121. */
  122. enum FlowControl
  123. {
  124. FlowNone = 0, ///< No flow control 无流控制
  125. FlowHardware = 1, ///< Hardware(RTS / CTS) flow control 硬件流控制
  126. FlowSoftware = 2 ///< Software(XON / XOFF) flow control 软件流控制
  127. };
  128. /**
  129. * @brief the SerialPort error code 串口错误代码
  130. *
  131. */
  132. enum SerialPortError
  133. {
  134. SystemError = -1, ///< system error 系统错误(如空指针、内存访问异常等)
  135. NoError = 0, ///< No error occurred 没有错误
  136. DeviceNotFoundError, ///< device not found 未找到设备
  137. PermissionError, ///< permission error 权限错误
  138. OpenError, ///< open error 打开串口错误
  139. ParityError, ///< parity error 校验位错误
  140. FramingError, ///<
  141. BreakConditionError, ///<
  142. WriteError, ///< write error 写数据错误
  143. ReadError, ///< read error 读数据错误
  144. ResourceError, ///<
  145. UnsupportedOperationError, ///<
  146. UnknownError, ///< unknown error 未知错误
  147. TimeoutError, ///< time out error 超时
  148. NotOpenError, ///< not open serial port error 串口未打开
  149. InvalidParameterError ///< invalid parameter error 无效的参数
  150. };
  151. } // namespace itas109
  152. #endif //__CSERIALPORT_GLOBAL_H__