当前位置: 代码迷 >> QT开发 >> Qt 如何判断串口读取完
  详细解决方案

Qt 如何判断串口读取完

热度:98   发布时间:2016-04-25 03:34:35.0
Qt 怎么判断串口读取完
我用串口接收数据,每次缓存58个字节读取一次,
read0: 32 bytes 
read0: 32 bytes 
read0: 58 bytes 
read0: 0 bytes 
read0: 32 bytes 
read0: 32 bytes 
read0: 58 bytes 
read0: 0 bytes 
read0: 32 bytes 
read0: 32 bytes 
read0: 58 bytes 
read0: 0 bytes 
read0: 32 bytes 
read0: 32 bytes 
read0: 58 bytes 
read0: 0 bytes 

每次接收完数据后会读取一个0 bytes,数据发送是连续的,我想问这样子怎么判断数据已经读取完毕,
qt 串口数据读取

------解决方案--------------------
1.如果知道包长的话,根据包长度来确认数据接收完

2.另一种方法,给每包加上包头和包尾,根据包头包尾确认包接收完

这种方式最好,加一个超时机制,以防数据只收到一部分通信中断,收包不全的情况,应通过超时机制将这些包丢弃或做特殊处理
  相关解决方案