ProtocolModbus.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // ProtocolPMC916.h: interface for the CProtocolModbus class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_DAIKIN_H__DAIKIN__INCLUDED_)
  5. #define AFX_DAIKIN_H__DAIKIN__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #define DEBUG_PROTOCOL 1
  10. #include "Protocol.h"
  11. class CProtocolModbus : public CProtocol
  12. {
  13. public:
  14. virtual BOOL InitParam(PPORTPARAM pPortParam, CCommAsyn *pComm);
  15. virtual int WorkMain(
  16. int nAddr, //地址
  17. int nVer, //版本号
  18. int nCid1, //控制标识码
  19. int nCid2, //命令信息
  20. WORD wLenId, //INFO字节长度
  21. int nCmdID, //命令ID
  22. int nDataLen, //请求数据长度
  23. int nCmdPos, //变量索引
  24. int nCmdLen, //变量长度
  25. char chMsg[80], //读到的变量值
  26. char *byDataFlag); //保留未用
  27. virtual int WriteCommand(
  28. int nCommPort, //端口
  29. int nAddr, //地址
  30. int nVer, //版本号
  31. int nCid1, //控制标识码
  32. int nCid2, //命令信息
  33. WORD wLenId, //INFO字节长度
  34. int nCmdType, //命令类型
  35. int nSetValue); //设定值
  36. virtual int WriteCommand(
  37. int nCommPort, //端口
  38. int nAddr, //地址
  39. int nSetType, //设定类型
  40. int nSetIndex, //设定值索引,只针对特殊变量(例如:空调制冷、制热温度)
  41. int nSetValue); //设定值
  42. CProtocolModbus();
  43. virtual ~CProtocolModbus();
  44. protected:
  45. HANDLE m_hSemComm;
  46. CRITICAL_SECTION m_csReadFinished;
  47. CRITICAL_SECTION m_csWrFinished;
  48. protected:
  49. virtual int RequestStatus(
  50. int nAddr, //地址
  51. int nVer, //版本号
  52. int nCid1, //控制标识码
  53. int nCid2, //命令信息
  54. WORD wLenId, //INFO字节长度
  55. int nCmdID, //命令ID
  56. int nDataLen, //请求数据长度
  57. int nCmdPos, //变量索引
  58. int nCmdLen, //变量长度
  59. char chMsg[80], //读到的变量值
  60. char *byDataFlag);
  61. virtual int ResponseStatus(int nDataLen, int iCmdPos, int iCmdLen, char chMsg[80], char *byDataFlag);//nDataLen 是INFO字节长度
  62. private:
  63. void GetNotvalue(const char *pSrc, char *pDest, int iLen);
  64. WORD GetDataLength(const WORD wLENID, char chLength[4]);
  65. UINT GetCheckSum(char *pBuf, char chDest[4], int len);
  66. char GetLCheckSum(char *pBuf, int len);
  67. char GetEvenCheckSum(char *pBuf, int nLen);
  68. virtual int RequestSetParam(
  69. int nCommPort, //端口
  70. int nAddr, //地址
  71. int nVer, //版本号
  72. int nCid1, //控制标识码
  73. int nCid2, //命令信息
  74. WORD wLenId, //INFO字节长度
  75. int nCmdType, //命令类型
  76. int nSetValue); //设定值
  77. virtual int ResponseSetParam(
  78. int nCommPort, //端口
  79. int nAddr, //地址
  80. int nVer, //版本号
  81. int nCid1, //控制标识码
  82. int nCid2, //命令信息
  83. WORD wLenId, //INFO字节长度
  84. int nCmdType, //命令类型
  85. int nSetValue); //设定值
  86. virtual int RequestRemoteCtrl(
  87. int nCommPort, //端口
  88. int nAddr, //地址
  89. int nSetType, //设定类型
  90. int nSetIndex, //设定值索引,只针对特殊变量(例如:空调制冷、制热温度)
  91. int nSetValue); //设定值
  92. virtual int ResponseRemoteCtrl(
  93. int nCommPort, //端口
  94. int nAddr, //地址
  95. int nSetType, //设定类型
  96. int nSetIndex, //设定值索引,只针对特殊变量(例如:空调制冷、制热温度)
  97. int nSetValue); //设定值
  98. };
  99. extern int DigitToBinary(WORD wdSource, char* pDes, int iBit);
  100. extern void bin2str(char *str, const unsigned char *bin, int binlen);
  101. extern BYTE GetCheckCode(const char * pSendBuf, int nEnd);//获得校验码
  102. extern char ByteToAscii(BYTE btSrc);
  103. extern WORD AsciiToBYTE(BYTE btSrc);
  104. extern char lowercase2uppercase(BYTE btSrc);
  105. //static unsigned char LRC(unsigned char *auchMsg, unsigned short usDataLen);
  106. #endif // !defined(AFX_PROTOCOLPMC916_H__3A4B4E9B_C165_4415_8EC3_3F5AA66B53C9__INCLUDED_)