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.另一种方法,给每包加上包头和包尾,根据包头包尾确认包接收完
这种方式最好,加一个超时机制,以防数据只收到一部分通信中断,收包不全的情况,应通过超时机制将这些包丢弃或做特殊处理