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

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

 2010-06-23 20:40:59 来源:WEB开发网   
核心提示:4.串口的读取过程分两种:查询读取和线程自动读取(1) 查询读取DWORD CComPort::GetInput(void* pBuf,DWORD Count,DWORD dwMilliseconds){//不能在自动模式下getinputif(this->GetReceiveMode()==CComPort::

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();
  }
}

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

Tags:线程 接收 模式

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接