为了账号安全,请及时绑定邮箱和手机立即绑定

怎么判断串口已发送完毕?(qt5, c++)?

/ 猿问

怎么判断串口已发送完毕?(qt5, c++)?

慕侠2389804 2019-04-11 11:07:05

怎么判断串口已发送完毕?(qt5, c++)


查看完整描述

2 回答

?
慕桂英3389331
12345678910111213141516171819202122232425262728293031323334写6个 异步延迟等待1秒肯定能写完 然后判断 重叠结构判断写的数据 跟 真正写的数据 是不是相等 bool CComControl::Send(BYTE* pBuff,DWORD dwBytesSend){     if (!PortOpened()) return false;         BOOL wRes;    DWORD dwBytesW;    wRes = WriteFile(m_hCom,pBuff,dwBytesSend,&dwBytesW,&m_ovWrite);    if (!wRes)    {        if (GetLastError() == ERROR_IO_PENDING)        {            WaitForSingleObject(m_ovWrite.hEvent,1000);            wRes = GetOverlappedResult(m_hCom,&m_ovWrite,&dwBytesW,false);            if (!wRes || dwBytesW !=dwBytesSend)            {                ClearInOut();                                 return false;            }        }        else        {            ClearInOut();                         return false;        }    }     return true;}

 



查看完整回答
反对 回复 2019-04-15
?
当年话下

写6个 异步延迟等待1秒肯定能写完 然后判断 重叠结构
判断写的数据 跟 真正写的数据 是不是相等

bool CComControl::Send(BYTE* pBuff,DWORD dwBytesSend)
{

if (!PortOpened()) return false;

BOOL wRes;
DWORD dwBytesW;
wRes = WriteFile(m_hCom,pBuff,dwBytesSend,&dwBytesW,&m_ovWrite);
if (!wRes)
{
if (GetLastError() == ERROR_IO_PENDING)
{
WaitForSingleObject(m_ovWrite.hEvent,1000);
wRes = GetOverlappedResult(m_hCom,&m_ovWrite,&dwBytesW,false);
if (!wRes || dwBytesW !=dwBytesSend)
{
ClearInOut();

return false;
}
}
else
{
ClearInOut();

return false;
}
}

return true;
}



查看完整回答
反对 回复 2019-04-15

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信