CommAsyn.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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(int nCommPort,
  43. int nAddr,
  44. char szCmd[32],
  45. char chSendMsg[32],
  46. int nDataLen,
  47. char chMsg[UPS_KE_HUA_MAX_MSG])
  48. {
  49. return m_pProtocol->WorkMain(nCommPort,
  50. nAddr,
  51. szCmd,
  52. chSendMsg,
  53. nDataLen,
  54. chMsg);
  55. }
  56. int CCommAsyn:: WriteCommand(char DataBuffer[80], int nDataLen)
  57. {
  58. return m_pProtocol->WriteCommand( DataBuffer, nDataLen);
  59. }