标题:串口读取不到数据,求解, 谢谢各位大侠,急
取消只看楼主
yyfq521
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2009-9-25
结帖率:0
 问题点数:0 回复次数:0 
串口读取不到数据,求解, 谢谢各位大侠,急
网上的例子,就是读取不到数据 ,请高手指点,谢谢!!!!
void CRS485CommDlg::OnReceive()  
{
OVERLAPPED m_osRead;
memset(&m_osRead,0,sizeof(OVERLAPPED));
m_osRead.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);

COMSTAT ComStat;
DWORD dwErrorFlags;

char str[100];
memset(str,'\0',100);
DWORD dwBytesRead=100;//读取的字节数
BOOL bReadStat;

ClearCommError(hCom,&dwErrorFlags,&ComStat);
dwBytesRead = min(dwBytesRead, (DWORD)ComStat.cbInQue);
bReadStat = ReadFile(hCom,str,dwBytesRead,&dwBytesRead,&m_osRead);
if(!bReadStat)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_osRead.hEvent, 2000);
}
}
PurgeComm(hCom, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
m_disp = str;
UpdateData(FALSE);
}
搜索更多相关主题的帖子: void 
2012-09-05 09:38



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-380713-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.076404 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved