多线程,多接收模式串口类LsComm
2010-06-23 20:40:59 来源:WEB开发网主要是选择模式然后执行: 下面看看this->ExecuteByAutoSignalRecvMode();
void CReadComThread::ExecuteByAutoSignalRecvMode()
{
DWORD dwMask=0;
HANDLE WaitHandles[3]; //监听事件数组
DWORD dwSignaledHandle;
WaitHandles[0] = this->m_pPort->GetCloseHandle();
WaitHandles[1] = this->m_ReadOverlapped.hEvent;
WaitHandles[2] = this->m_BreakOverlapped.hEvent;
this->m_pPort->GetSerialPort()->SetMask(EV_ERR | EV_RLSD | EV_RING );
if(!SetBreakEvent(dwMask))
goto EndThread;
//设置读事件
if(!SetReadEvent(this->m_ReadOverlapped))
goto EndThread;
//设置comEvent
for(;;)
{
dwSignaledHandle=::WaitForMultipleObjects(3,WaitHandles,false,INFINITE);
switch(dwSignaledHandle)
{
case WAIT_OBJECT_0:
goto EndThread;
break;
case WAIT_OBJECT_0+1:
if(!this->HandleReadEvent(this->m_ReadOverlapped))
goto EndThread;
if(!this->SetReadEvent(this->m_ReadOverlapped))
goto EndThread;
break;
case WAIT_OBJECT_0+2:
if(!this->HandleBreakEvent(dwMask))
goto EndThread;
if(!this->SetBreakEvent(dwMask))
goto EndThread;
break;
default:
//goto EndThread;
break;
}
}
EndThread:
this->m_pPort->GetSerialPort()->Purge(PURGE_RXABORT | PURGE_RXCLEAR);
::CloseHandle(this->m_ReadOverlapped.hEvent);
::CloseHandle(this->m_BreakOverlapped.hEvent);
return ;
}
更多精彩
赞助商链接