kernelcruzezhou.blog.chinaunix.net
so927
全部博文(56)
2013年(1)
2012年(9)
2011年(10)
2010年(7)
2009年(7)
2008年(22)
zt1234
agame
tianchun
Phyllis6
bzhao
whl1233
xueting2
teaco77
xiao_代
liuqiyu_
分类: WINDOWS
2008-08-20 19:27:16
CCESeries *ceSeries = (CCESeries*)lparam; DWORD evtMask; BYTE * readBuf = NULL;//读取的字节 DWORD actualReadLen=0;//实际读取的字节数 DWORD willReadLen; DWORD dwReadErrors; COMSTAT cmState; // 清空缓冲,并检查串口是否打开。 ASSERT(ceSeries->m_hComm !=INVALID_HANDLE_VALUE); //清空串口 PurgeComm(ceSeries->m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR ); SetCommMask (ceSeries->m_hComm, EV_RXCHAR | EV_CTS | EV_DSR ); while (TRUE) { if (WaitCommEvent(ceSeries->m_hComm,&evtMask,0)) { SetCommMask (ceSeries->m_hComm, EV_RXCHAR | EV_CTS | EV_DSR ); //表示串口收到字符 if (evtMask & EV_RXCHAR) { ClearCommError(ceSeries->m_hComm,&dwReadErrors,&cmState); willReadLen = cmState.cbInQue ; if (willReadLen <= 0) { continue; } readBuf = new BYTE[willReadLen]; ReadFile(ceSeries->m_hComm, readBuf, willReadLen, &actualReadLen,0); //如果读取的数据大于0, if (actualReadLen>0) { //触发读取回调函数 ceSeries->m_OnSeriesRead(ceSeries->m_pPortOwner,readBuf,actualReadLen); } } } //如果收到读线程退出信号,则退出线程 if (WaitForSingleObject(ceSeries->m_hReadCloseEvent,500) == WAIT_OBJECT_0) { break; } } return 0;
上一篇:wince下INI的操作更新
下一篇:短信PDU模式解码
登录 注册