CommAsyn.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // CommAsyn.cpp: implementation of the CCommAsyn class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "CommAsyn.h"
  6. #include <atlconv.h>
  7. #include "ProtocolModbus.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CCommAsyn::CCommAsyn()
  17. {
  18. m_pProtocol=NULL;
  19. }
  20. CCommAsyn::~CCommAsyn()
  21. {
  22. if(m_pProtocol)
  23. {
  24. delete m_pProtocol;
  25. m_pProtocol=NULL;
  26. }
  27. }
  28. BOOL CCommAsyn::CloseComm()
  29. {
  30. return this->CloseComm();
  31. }
  32. BOOL CCommAsyn::InitParam(PPORTPARAM pPortParam)
  33. {
  34. if(m_pProtocol)
  35. {
  36. delete m_pProtocol;
  37. m_pProtocol=NULL;
  38. }
  39. m_pProtocol=new CProtocolModbus();
  40. return m_pProtocol->InitParam(pPortParam,this);
  41. }
  42. int CCommAsyn::WorkMain(SETBASEPARAM SetBasePara, int nDataLen, int iCmdPos, int iCmdLen, char chMsg[10])
  43. {
  44. return m_pProtocol->WorkMain( SetBasePara, nDataLen, iCmdPos, iCmdLen, chMsg);
  45. }
  46. int CCommAsyn:: WriteCommand(char DataBuffer[80], char ResDataBuffer[2])
  47. {
  48. return m_pProtocol->WriteCommand(DataBuffer, ResDataBuffer);
  49. }