Protocol.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Protocol.cpp: implementation of the CProtocol class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Protocol.h"
  6. #include "CommAsyn.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CProtocol::CProtocol()
  16. {
  17. m_pComm=NULL;
  18. }
  19. CProtocol::~CProtocol()
  20. {
  21. }
  22. int CProtocol::ReadMessage(BYTE *pBuf, int len)
  23. {
  24. if( !AfxIsValidAddress(pBuf, len, FALSE ) )
  25. return 0;
  26. if( !m_pComm )
  27. return 0;
  28. if( !::AfxIsValidAddress(m_pComm, sizeof(CCommAsyn), FALSE ) )
  29. {
  30. return 0;
  31. }
  32. int iResult=m_pComm->Read(pBuf,len);
  33. if(iResult>len)
  34. iResult=len;
  35. return iResult;
  36. }
  37. int CProtocol::WriteMessage(BYTE *pBuf, int len)
  38. {
  39. if( !m_pComm ) return 0;
  40. if( !::AfxIsValidAddress(m_pComm, sizeof(CCommAsyn), FALSE ) )
  41. {
  42. return 0;
  43. }
  44. int iResult = m_pComm->Write(pBuf,len);
  45. return iResult;
  46. }
  47. BOOL CProtocol::InitParam(PPORTPARAM pPortParam, CCommAsyn *pComm)
  48. {
  49. return FALSE;
  50. }