多线程,多接收模式串口类LsComm
2010-06-23 20:40:59 来源:WEB开发网4.串口的读取过程
分两种:查询读取和线程自动读取
(1) 查询读取
DWORD CComPort::GetInput(void* pBuf,DWORD Count,DWORD dwMilliseconds)
{
//不能在自动模式下getinput
if(this->GetReceiveMode()==CComPort::AutoReceiveByBreak||
this->GetReceiveMode()==CComPort::AutoReceiveBySignal)
{
::AfxMessageBox("Can''t use GetInput methord in this mode!");
return 0;
}
if(this->IsOverlapped())
{
ASSERT(this->m_pReadThread);
DWORD dwBytes = this->m_pReadThread->ReadInput(pBuf,Count,dwMilliseconds);
this->m_pPort->TerminateOutstandingReads();
return dwBytes;
}
else
return this->m_pPort->Read(pBuf,Count);
}
主要是调用m_pPort->Read(pBuf,Count);然后调用API函数ReadFile
(2) 线程等待处理
主要过程:在线程CreadComThread的Execute中
void CReadComThread::Execute()
{
if(this->m_pPort->GetReceiveMode()==CComPort::ManualReceiveByQuery)
{
this->ExecuteByManualQueryRecvMode();
}
else if(this->m_pPort->GetReceiveMode()==CComPort::ManualReceiveByConst)
{
this->ExecuteByManualConstRecvMode();
}
else if(this->m_pPort->GetReceiveMode()==CComPort::AutoReceiveBySignal)
{
this->ExecuteByAutoSignalRecvMode();
}
else//中断模式
{
this->ExecuteByAutoBreakRecvMode();
}
}
更多精彩
赞助商链接