还想问一下:什么原因会导致从串口读到的数据在视图中显示越来越慢?!

xyshine 2002-12-28 10:31:53
还有,从写命令到串口到串口收到回应大概需要多长时间,我每隔100毫秒读一次够吗?
...全文
29 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzzjjhh 2002-12-29
  • 打赏
  • 举报
回复
你可以不停的收啊,用事件激活
xyshine 2002-12-29
  • 打赏
  • 举报
回复
以下是我的通信程序,有问题吗?

void CMainFrame::OnTimer(UINT nIDEvent)
{
DWORD readnum=Communication();
if(readnum==0)
{
iLinkCount++;
if(iLinkCount==50)
{
KillTimer(timeID);
UINT ooo=this->MessageBox("RS232 ERROR","´íÎó",MB_RETRYCANCEL|MB_ICONSTOP);
if(ooo==IDRETRY)
timeID=SetTimer(3,100,NULL);

iLinkCount=0;

}

return;
}

iLinkCount=0;
byte mCheck=0;
for(int i=0;i<=m_Count;i++)
{
mCheck+=inbuff[i];
}
if(mCheck!=0xFF)
return;
m_Count=inbuff[0];
UpdateWindow();
switch(m_Count)
{
case 0x01: LinkResult();break;
case 0x2e: LPUCheck();break;
case 0x3e: LPUCheck();break;
case 0xE1: wait();break;
case 0x13: {SelfCheck();break;
case 0x46: MFDWrongCheck();break;
case 0x52: RoundKey();break;
case 0x61: VideoFold();break;
case 0x71: MFDFixCheck();break;
case 0xf2: Wrong();break;
default: return;
}

CFrameWnd::OnTimer(nIDEvent);
}




int CMainFrame::Communication()
{
for(int i=0;i<15;i++)
inbuff[i]=0;

DWORD nBytesRead,nBytesWrite;
p_outbuff=&outbuff[0];
if(!WriteFile(handle,p_outbuff,3,&nBytesWrite,NULL))
{
nBytesWrite=0;
return 0;
}
if(nBytesWrite!=3)
return 0;

p_inbuff=&inbuff[0];
if(!ReadFile(handle,p_inbuff,1,&nBytesRead,NULL))
{
nBytesRead=0;
return 0;
}

if(nBytesRead==0)
return 0;
m_Count=inbuff[0];
m_Count&=0x0F;
p_inbuff++;
if(!m_Count)
return true;

if(!ReadFile(handle,p_inbuff,m_Count,&nBytesRead,NULL))
{
nBytesRead=0;
return 0;
}
if(nBytesRead!=m_Count)
{
return 0;
}

//PurgeComm(handle,PURGE_RXCLEAR);
return true;
}

2,643

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧