// CommAsyn.cpp: implementation of the CCommAsyn class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CommAsyn.h" #include #include "ProtocolModbus.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CCommAsyn::CCommAsyn() { m_pProtocol=NULL; } CCommAsyn::~CCommAsyn() { if(m_pProtocol) { delete m_pProtocol; m_pProtocol=NULL; } } BOOL CCommAsyn::CloseComm() { return this->CloseComm(); } BOOL CCommAsyn::InitParam(PPORTPARAM pPortParam) { if(m_pProtocol) { delete m_pProtocol; m_pProtocol=NULL; } m_pProtocol=new CProtocolModbus(); return m_pProtocol->InitParam(pPortParam,this); } int CCommAsyn::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) //保留未用 { return m_pProtocol->WorkMain(nAddr, nVer, nCid1, nCid2, wLenId, nCmdID, nDataLen, nCmdPos, nCmdLen, chMsg, byDataFlag); } int CCommAsyn:: WriteCommand( int nCommPort, //端口 int nAddr, //地址 int nVer, //版本号 int nCid1, //控制标识码 int nCid2, //命令信息 WORD wLenId, //INFO字节长度 int nCmdType, //命令类型 int nSetValue) //设定值 { return m_pProtocol->WriteCommand( nCommPort, nAddr, nVer, nCid1, nCid2, wLenId, nCmdType, nSetValue ); } int CCommAsyn:: WriteCommand( int nCommPort, //端口 int nAddr, //地址 int nSetType, //设定类型 int nSetIndex, //设定值索引,只针对特殊变量(例如:空调制冷、制热温度) int nSetValue) //设定值 { return m_pProtocol->WriteCommand( nCommPort, nAddr, nSetType, nSetIndex, nSetValue ); }