怎么判断串口已发送完毕?(qt5, c++)
2 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
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 ; } |
当年话下
TA贡献1890条经验 获得超9个赞
写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;
}
添加回答
举报
0/150
提交
取消