SerialInterface.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef __SERIALINTERFACE_BY_ZEROT_
  2. #define __SERIALINTERFACE_BY_ZEROT_
  3. #ifdef SERIAL_IMPL
  4. #define SERIALDLLEXPORT _declspec(dllexport)
  5. #else
  6. #define SERIALDLLEXPORT _declspec(dllimport)
  7. #endif
  8. // 接口纯虚类,实现多态;
  9. class SERIALDLLEXPORT CSerialInterface
  10. {
  11. // [in]:
  12. public:
  13. // 打开串口;
  14. virtual BOOL OpenSerialPort(
  15. const int &iCommPort,
  16. const int &iRate,
  17. const int &iDataBit,
  18. const int &iStopBit,
  19. const int &iParity,
  20. const int &iReqTime,
  21. const int &iInterval ) = 0;
  22. // 关闭串口;
  23. virtual BOOL CloseSerialPort( const int &iCommPort ) = 0;
  24. // 自动采集;
  25. virtual int AutoCollect(const int &iCommPort) = 0;
  26. // 停止自动采集;
  27. virtual void StopCollect(const int &iCommPort) = 0;
  28. // 自动接收;
  29. virtual void AutoScatter(const int &iCommPort) = 0;
  30. // 停止自动接收;
  31. virtual void StopScatter(const int &iCommPort) = 0;
  32. // 发送读请求命令;
  33. // iRequestType : 命令的类型 , == 0 是设置, == 1 是读取;
  34. virtual void SendRequest( const int &iCommPort, const int &iAddr, BYTE *szCmd,const int &iLen, const int &iRequestType ) = 0;
  35. // 读取请求回复数据;
  36. virtual void ReadRespone( const int &iCommPort, const int &iAddr ) = 0;
  37. // 添加读请求命令(其中:szMark,只为多命令设备使用,如果设备只有一个命令,szMark可以省略不写);
  38. virtual void InserCommand(
  39. const int &iCommPort,
  40. const int &iAddr,
  41. BYTE *szCommand,
  42. const int &iLen,
  43. char *szMark,
  44. bool bRecv = true,
  45. const int &iSNum = -1) = 0;
  46. // 删除读请求命令;
  47. virtual void DeleteRequestCommannd( const int &iCommPort,const int &iAddr, BYTE *szCommand, const int &iLen ) = 0;
  48. // [out]
  49. public:
  50. // 获取变量的值;
  51. // iCommPort: 串口号;
  52. // iAddr: 地址;
  53. // szMark: 命令特征码;
  54. // iIndex: 返回数据索引;(0开始)
  55. // iCutLen: 从索引开始截取的长度;
  56. // iSBit: 起始位;(默认 -1,表示不取位) // 纠正:不用设置默认值,如果是取位,iConvertType 就能表示数据转换类型是不是取位;
  57. // iEBit: 终止位;(默认 -1,表示不取位)
  58. // szValue: 返回的值(经数据处理);
  59. // iConvertType:数据转换处理类型;
  60. virtual void GetAnalogValue(
  61. const int &iCommPort,
  62. const int &iAddr,
  63. char *szMark,
  64. const int &iIndex,
  65. const int &iCutLen,
  66. const int &iSBit,
  67. const int &iEBit,
  68. char *szValue,
  69. const int &iConvertType) = 0;
  70. // 获取变量的值;
  71. // iCommPort: 串口号;
  72. // iAddr: 地址;
  73. // szMark: 命令特征码;
  74. // iIndex: 返回数据索引;(0开始)
  75. // iCutLen: 从索引开始截取的长度;
  76. // iSBit: 起始位;(默认 -1,表示不取位) // 纠正:不用设置默认值,如果是取位,iConvertType 就能表示数据转换类型是不是取位;
  77. // iEBit: 终止位;(默认 -1,表示不取位)
  78. // szValue: 要设置的值(经数据处理);
  79. // iConvertType:设置值的数据转换处理类型;
  80. virtual void SetAnalogValue(
  81. const int &iCommPort,
  82. const int &iAddr,
  83. char *szMark,
  84. const int &iIndex,
  85. const int &iCutLen,
  86. const int &iSBit,
  87. const int &iEbit,
  88. char *szSetValue,
  89. const int &iCovertType) = 0;
  90. };
  91. #endif