1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- // CommAsyn.cpp: implementation of the CCommAsyn class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "CommAsyn.h"
- #include <atlconv.h>
- #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, //设备地址
- BYTE Start, //起始位
- BYTE StartAddr[2], //起始地址
- int nRegNum, //读取的寄存器个数
- BYTE FuncCode[2],
- int nDataLen,
- BYTE byWithAddrFlag,
- char chMsg[80])
- {
- return m_pProtocol->WorkMain( nAddr, Start, StartAddr, nRegNum, FuncCode, nDataLen, byWithAddrFlag,chMsg);
- }
- int CCommAsyn::WriteCommand(char DataBuffer[80], int nDataLen)
- {
- return m_pProtocol->WriteCommand( DataBuffer, nDataLen);
- }
|