用WaitCommEvent 监视串口的事件。
解决方案 »
- 完成端口发送文件的同步问题
- 谁有codeproject网站的账号,帮忙下一份代码
- 2009年12月,马上进入2010年,大家可以想想过去1年的收获!
- 【紧急啊~~~~高分征集答案】如何输出表中的所有元素~forstner算子提取特征点
- 明明执行了视图的OnDraw函数,但视图却显示不出来,怎么办?OnDraw函数是我在视图类中手动调用的
- 请教一个简单问题
- ATL程序编译错,请大虾指点迷津!
- 多文档应用程序
- 请问高手,为什么javascipt能执行ATL HTML CONTROL的方法却得不到ATL HTML CONTROL发出的消息
- 同样的程序,为什么在64位系统上使用的内存会比32位上的多?
- 对话框的怪问题
- 比较难的一个问题: 用什么方法得到一个多播组的成员数量?
function:
CommWatchProc
describ:
监视串口数据
********************************************************/
UINT CommWatchProc( LPVOID lpData )
{
DWORD dwEvtMask ;
//NPTTYINFO npTTYInfo = (NPTTYINFO) lpData ;
OVERLAPPED os ;
int nLength ;
//BYTE abIn[ MAXBLOCK + 1] ;
CComStatus * pCom = (CComStatus *)lpData; memset( &os, 0, sizeof( OVERLAPPED ) ) ; // create I/O event used for overlapped read os.hEvent = CreateEvent( NULL, // no security
TRUE, // explicit reset req
FALSE, // initial event reset
NULL ) ; // no name
if (os.hEvent == NULL)
{
MessageBox( NULL, "Failed to create event for thread!", "TTY Error!",
MB_ICONEXCLAMATION | MB_OK ) ;
return ( FALSE ) ;
} if (!SetCommMask( pCom->m_hCom, EV_RXCHAR | EV_RXFLAG ))
return ( FALSE ) ;
char buf[256];
while ( pCom->m_bConnected )
{
dwEvtMask = 0 ; WaitCommEvent( pCom->m_hCom, &dwEvtMask, NULL ); if ((dwEvtMask & EV_RXCHAR) == EV_RXCHAR)
{
/* do
{*/
if ((nLength = ReadCommBlock( *pCom, (LPSTR) buf, 255 ))!=0)
{
//WriteTTYBlock( hTTYWnd, (LPSTR) abIn, nLength ) ;
buf[nLength]='\0';
//ShowMessage(buf);
// force a paint //UpdateWindow( hTTYWnd ) ;
}
// }
// while ( nLength > 0 ) ;
}
} // get rid of event handle CloseHandle( os.hEvent ) ; // clear information in structure (kind of a "we're done flag")// THREADID( npTTYInfo ) = 0 ;
// HTHREAD( npTTYInfo ) = NULL ; return( TRUE ) ;
} // end of CommWatchProc()