谁写过 API 串口 程序啊!我现在遇到关于 API 串口 程序问题,用重叠方式读写操作 ,就是在接收的时候怎么判断一帧数据接收完?我想了很多办法都不行啊?fState=ReadFile(pDoc->m_hCom,pDoc->m_OptionP.sReceive,dwsLen2,&length,&pDoc->m_osRead);
if(!fState)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(pDoc->m_osRead.hEvent, 2000);
while(!GetOverlappedResult(pDoc->m_hCom,&pDoc->m_osRead,&dwBytesRead,TRUE))
{
dwError=GetLastError();
if(dwError==ERROR_IO_INCOMPLETE)
continue;
pDoc->m_OptionP.bOt[2]=TRUE;
}
}
else
{
pDoc->m_OptionP.bOt[2]=TRUE;//通知视图
}
}还有 我看资料说用 WaitCommEvent(pDoc->m_hCom, &dwMask, &os) 检测 MASK 事件;ClearCommError(m_hCom,&dwErrorFlags,&ComStat);
switch(dwErrorFlags)
{
case CE_BREAK: // MSDN : The hardware detected a break condition.
break;
case CE_FRAME: // MSDN : The hardware detected a framing error.
break;
case CE_IOE: // MSDN : An I/O error occurred during communications with the device.
break;
case CE_MODE: // MSDN : The requested mode is not supported, or the hFile parameter is invalid. If this value is specified, it is the only valid error.
break;
case CE_OOP: // MSDN : Windows Me/98/95: A parallel device signaled that it is out of paper.
break;
case CE_OVERRUN: // MSDN : A character-buffer overrun has occurred. The next character is lost.
break;
case CE_PTO: // MSDN : Windows Me/98/95: A time-out occurred on a parallel device.
break;
case CE_RXOVER: // MSDN : An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.
break;
case CE_RXPARITY: // MSDN : The hardware detected a parity error.
break;
case CE_TXFULL: // MSDN : The application tried to transmit a character, but the output buffer was full.
break;
}这里面也没有定义接收数据帧 完成 事件啊 ?只有发送最后一个完成 CE_RXPARITY 事件!我又想了检测超时的办法,但是连接收都接收不到啊!怎么检测接收超时事件?COMMTIMEOUTS TimeOuts;
TimeOuts.ReadIntervalTimeout=6;
TimeOuts.ReadTotalTimeoutMultiplier=1;
TimeOuts.ReadTotalTimeoutConstant=2000;
SetCommTimeouts(m_hCom, &TimeOuts);这样设置对不对?
if(!fState)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(pDoc->m_osRead.hEvent, 2000);
while(!GetOverlappedResult(pDoc->m_hCom,&pDoc->m_osRead,&dwBytesRead,TRUE))
{
dwError=GetLastError();
if(dwError==ERROR_IO_INCOMPLETE)
continue;
pDoc->m_OptionP.bOt[2]=TRUE;
}
}
else
{
pDoc->m_OptionP.bOt[2]=TRUE;//通知视图
}
}还有 我看资料说用 WaitCommEvent(pDoc->m_hCom, &dwMask, &os) 检测 MASK 事件;ClearCommError(m_hCom,&dwErrorFlags,&ComStat);
switch(dwErrorFlags)
{
case CE_BREAK: // MSDN : The hardware detected a break condition.
break;
case CE_FRAME: // MSDN : The hardware detected a framing error.
break;
case CE_IOE: // MSDN : An I/O error occurred during communications with the device.
break;
case CE_MODE: // MSDN : The requested mode is not supported, or the hFile parameter is invalid. If this value is specified, it is the only valid error.
break;
case CE_OOP: // MSDN : Windows Me/98/95: A parallel device signaled that it is out of paper.
break;
case CE_OVERRUN: // MSDN : A character-buffer overrun has occurred. The next character is lost.
break;
case CE_PTO: // MSDN : Windows Me/98/95: A time-out occurred on a parallel device.
break;
case CE_RXOVER: // MSDN : An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.
break;
case CE_RXPARITY: // MSDN : The hardware detected a parity error.
break;
case CE_TXFULL: // MSDN : The application tried to transmit a character, but the output buffer was full.
break;
}这里面也没有定义接收数据帧 完成 事件啊 ?只有发送最后一个完成 CE_RXPARITY 事件!我又想了检测超时的办法,但是连接收都接收不到啊!怎么检测接收超时事件?COMMTIMEOUTS TimeOuts;
TimeOuts.ReadIntervalTimeout=6;
TimeOuts.ReadTotalTimeoutMultiplier=1;
TimeOuts.ReadTotalTimeoutConstant=2000;
SetCommTimeouts(m_hCom, &TimeOuts);这样设置对不对?
解决方案 »
- 关于tree控件, 如果使得失去焦点后的选中项颜色保持选中项的颜色
- 关于收到http请求后的页面重定向的问题
- 怎么发分?
- 急!在线求助:如基于微软接口实现"打印当前页"功能
- 在内存中绘制CBitmap为何全为黑色的?
- 手头没资料,哪位知道CDHTMLDIALOG类如何动态载入服务器的主页?
- 如何禁止其他运行进程(高分求助)!!在线等待!!
- 在一个thread中如何修改对话框中编辑框的内容??在线等待!!!
- 如何用vc编写一个截获本机http或者tcp的数据包,然后进行分析?
- 怎样通知其它应用程序(比如"我的电脑")某类型文件图标已经改变?
- 运行时函数memcpy()出错,求助!
- [难]如何用纯C++写一个进程外的COM?搞不定了!!
http://download.csdn.net/source/1339593
肯定有个方法来检测 接收数据帧 完成,例如检测 接收信号为高电平时长,过长就可以判定是接收完成了!但是好像 API 并没有给出 这样的检测手段 ,不知怎么判断字符间传输超时?怎么捕捉这个事件?有哪些函数?