多线程,多接收模式串口类 LsComm 之二
2006-07-21 11:15:53 来源:WEB开发网2. zkf00:中断接收函数OnComBreak怎么用? 答:试验了一下 void OnComBreak(LPVOID pSender,DWORD dwMask,COMSTAT stat)
3. greatim:DataWaiting 是有什么用的??在例子程序里没有引用到。而且在 Open 的函数里,CreateEvent 被屏蔽了,是否代表 DataWaiting 这函数不能使用呢? DataWaiting 和 Attech 有什么关系?
{
//deal with the break of com here
switch(dwMask)
{
case EV_BREAK:
{
break;
}
case EV_CTS: //在这里处理CTS信号
{
break;
}
}
}
答:因为 DataWaiting 是 PJ Naughter 写的,请仔细看他的源码: BOOL CSerialPort::DataWaiting(DWORD dwTimeout)
这好像与 Attach 没什么关系吧?
{
ASSERT(IsOpen());
ASSERT(m_hEvent);
//Setup to wait for incoming data
DWORD dwOldMask;
GetMask(dwOldMask);
SetMask(EV_RXCHAR);//1.设置接收中断事件
//Setup the overlapped structure
OVERLAPPED o;
o.hEvent = m_hEvent;
//Assume the worst;
BOOL bSuccess = FALSE;
DWORD dwEvent;
bSuccess = WaitEvent(dwEvent, o);//2. 设置监听
if (!bSuccess)
{//3.dwTimeOut为所等待的时间,有数据收到,返回发现数据
if (WaitForSingleObject(o.hEvent, dwTimeout) == WAIT_OBJECT_0)
{
DWORD dwBytesTransferred;
GetOverlappedResult(o, dwBytesTransferred, FALSE);
bSuccess = TRUE;
}
}
//Reset the event mask
SetMask(dwOldMask);
return bSuccess;
}
更多精彩
赞助商链接