📄 comportbase.cpp
字号:
//---------------------------------------------------------------------------
// Pixelworks Inc. Company Confidential Strictly Private
//
// $Archive: /SwTools/FlashUpgrader/ComPortBase.cpp $
// $Revision: 1.1.1.1 $
// $Author: KevinM $
// $Date: 2003/09/29 18:19:04 $
//
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Copyright 1997 (c) Pixelworks Inc.
//
// Pixelworks owns the sole copyright to this software. Under international
// copyright laws you (1) may not make a copy of this software except for
// the purposes of maintaining a single archive copy, (2) may not derive
// works herefrom, (3) may not distribute this work to others. These rights
// are provided for information clarification, other restrictions of rights
// may apply as well.
//
// This is an unpublished work.
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>>>>> WARRANTEE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Pixelworks Inc. MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THE USE OF
// THIS SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
// PURPOSE.
// --------------------------------------------------------------------------
#include "stdafx.h"
#include "ComPortBase.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
CComPortBase::CComPortBase()
{
m_pWnd = NULL;
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
CComPortBase::~CComPortBase()
{
}
BEGIN_MESSAGE_MAP(CComPortBase, CCommunication)
//{{AFX_MSG_MAP(CComPortBase)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
BOOL CComPortBase::Create(CWnd *pWnd)
{
m_pWnd = pWnd;
ASSERT(m_pWnd);
if (m_eComm == ccUSB)
{
// Don't need to do anything for USB
}
else
{
if (FALSE == CCommunication::Initialize(pWnd->m_hWnd))
{
TRACE("Initialize Communications Object failed\n");
return FALSE;
}
}
return TRUE;
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
BOOL CComPortBase::SetBaudRate(int nBaudRate)
{
return CCommunication::SetBaudRate(nBaudRate);
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
BOOL CComPortBase::SetComPort(int nPort)
{
BOOL bRet = TRUE;
#ifdef BUILD_USB_CONFIG
if (nPort == -1) // If this is USB
{
m_eComm = ccUSB;
if (m_pUsb)
{
delete m_pUsb;
}
m_pUsb = new CPWUsb;
bRet = m_pUsb->Initialize(10);
}
else // This is serial
#endif
{
m_eComm = ccSERIAL;
try
{
if (GetPortOpen())
{
CCommunication::SetPortOpen(FALSE);
}
bRet = CCommunication::SetCommPort(nPort);
if (bRet)
{
bRet = CCommunication::SetPortOpen(TRUE);
}
}
catch(CException *pExc)
{
TRACE("Caught Exception\n");
pExc->Delete();
bRet = FALSE;
}
}
return bRet;
}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
BOOL CComPortBase::CloseComPort()
{
#ifdef BUILD_USB_CONFIG
if (m_eComm == ccUSB)
{
if (m_pUsb)
{
delete m_pUsb;
m_pUsb = NULL;
}
}
else
#endif
{
try
{
if (CCommunication::GetPortOpen())
{
CCommunication::SetPortOpen(FALSE);
}
}
catch(CException *pExc)
{
TRACE("Caught Exception\n");
pExc->Delete();
return FALSE;
}
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CComPortBase message handlers
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
void CComPortBase::OnComPortMessage(long wParam, long lParam)
{
switch(wParam)
{
case vbMSCommEvReceive:
{
CByteArray byteArray;
GetInput(byteArray);
ReceivedData(byteArray);
}
break;
default:
TRACE("Unknown value. wParam= %d\n", wParam);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -