// ProtocolPMC916.h: interface for the CProtocolModbus class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_DAIKIN_H__DAIKIN__INCLUDED_) #define AFX_DAIKIN_H__DAIKIN__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define DEBUG_PROTOCOL 1 #include "Protocol.h" class CProtocolModbus : public CProtocol { public: virtual BOOL InitParam(PPORTPARAM pPortParam, CCommAsyn *pComm); virtual int WorkMain( int nAddr, //地址 int nVer, //版本号 int nCid1, //控制标识码 int nCid2, //命令信息 WORD wLenId, //INFO字节长度 int nCmdID, //命令ID int nDataLen, //请求数据长度 int nCmdPos, //变量索引 int nCmdLen, //变量长度 char chMsg[80], //读到的变量值 char *byDataFlag); //保留未用 virtual int WriteCommand( int nCommPort, //端口 int nAddr, //地址 int nVer, //版本号 int nCid1, //控制标识码 int nCid2, //命令信息 WORD wLenId, //INFO字节长度 int nCmdType, //命令类型 int nSetValue); //设定值 virtual int WriteCommand( int nCommPort, //端口 int nAddr, //地址 int nSetType, //设定类型 int nSetIndex, //设定值索引,只针对特殊变量(例如:空调制冷、制热温度) int nSetValue); //设定值 CProtocolModbus(); virtual ~CProtocolModbus(); protected: HANDLE m_hSemComm; CRITICAL_SECTION m_csReadFinished; CRITICAL_SECTION m_csWrFinished; protected: virtual int RequestStatus( int nAddr, //地址 int nVer, //版本号 int nCid1, //控制标识码 int nCid2, //命令信息 WORD wLenId, //INFO字节长度 int nCmdID, //命令ID int nDataLen, //请求数据长度 int nCmdPos, //变量索引 int nCmdLen, //变量长度 char chMsg[80], //读到的变量值 char *byDataFlag); virtual int ResponseStatus(int nDataLen, int iCmdPos, int iCmdLen, char chMsg[80], char *byDataFlag);//nDataLen 是INFO字节长度 private: void GetNotvalue(const char *pSrc, char *pDest, int iLen); WORD GetDataLength(const WORD wLENID, char chLength[4]); UINT GetCheckSum(char *pBuf, char chDest[4], int len); char GetLCheckSum(char *pBuf, int len); char GetEvenCheckSum(char *pBuf, int nLen); virtual int RequestSetParam( int nCommPort, //端口 int nAddr, //地址 int nVer, //版本号 int nCid1, //控制标识码 int nCid2, //命令信息 WORD wLenId, //INFO字节长度 int nCmdType, //命令类型 int nSetValue); //设定值 virtual int ResponseSetParam( int nCommPort, //端口 int nAddr, //地址 int nVer, //版本号 int nCid1, //控制标识码 int nCid2, //命令信息 WORD wLenId, //INFO字节长度 int nCmdType, //命令类型 int nSetValue); //设定值 virtual int RequestRemoteCtrl( int nCommPort, //端口 int nAddr, //地址 int nSetType, //设定类型 int nSetIndex, //设定值索引,只针对特殊变量(例如:空调制冷、制热温度) int nSetValue); //设定值 virtual int ResponseRemoteCtrl( int nCommPort, //端口 int nAddr, //地址 int nSetType, //设定类型 int nSetIndex, //设定值索引,只针对特殊变量(例如:空调制冷、制热温度) int nSetValue); //设定值 }; extern int DigitToBinary(WORD wdSource, char* pDes, int iBit); extern void bin2str(char *str, const unsigned char *bin, int binlen); extern BYTE GetCheckCode(const char * pSendBuf, int nEnd);//获得校验码 extern char ByteToAscii(BYTE btSrc); extern WORD AsciiToBYTE(BYTE btSrc); extern char lowercase2uppercase(BYTE btSrc); //static unsigned char LRC(unsigned char *auchMsg, unsigned short usDataLen); #endif // !defined(AFX_PROTOCOLPMC916_H__3A4B4E9B_C165_4415_8EC3_3F5AA66B53C9__INCLUDED_)