开发学院软件开发VC 多线程,多接收模式串口类LsComm 阅读

多线程,多接收模式串口类LsComm

 2010-06-23 20:40:59 来源:WEB开发网   
核心提示:主要是选择模式然后执行: 下面看看this->ExecuteByAutoSignalRecvMode();void CReadComThread::ExecuteByAutoSignalRecvMode(){DWORD dwMask=0;HANDLE WaitHandles[3]; //监听事件数组DWORD d

主要是选择模式然后执行: 下面看看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 ;
}

上一页  1 2 3 4 5 6 7  下一页

Tags:线程 接收 模式

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接