Assuming agreement
00 00 00 0 04 0 f e ff ff
4 bytes in front of the said how long is the whole data here behind the 04 said four bytes
The last two bytes ff ff for crc16
If the transmission is flawed, 04 into 5
So that did not receive complete, wait for the next arrival data, assuming that the received another right
00 00 00 0 04 0 f e ff ff
At this time that such data is a complete
00 00 00 05 (misinformation) 0 0 f e ff ff 00
Crc16 calibration failure, give up this data, then the problem is behind all the data are wrong, how to solve?
This case should be closed serial ports open again? What better way? Thank you very much!
CodePudding user response:
Personally feel that a closed a: receive correct, request a data; Errors in the received check data, request retransmission,CodePudding user response:
Define a frame head and tail frame, through to search frame head positioning, you define this agreement is not goodCodePudding user response:
First, the protocol definition itself has a problem, reliable communication definition should be mark head + length (data) + check + tail signSecond, if communication slowly, you can set the timeout in the software, such as can be set if there is no data to within 50 ms, can maintain the frame has been sent, can receive treatment,
15 years of experience in industrial serial communication programming c + +!
CodePudding user response:
Communication protocol: start logo + command + data length n + + calibration, by agreement detection function can judge whether the data has been received and an error is detected data, can according to the mechanism to ignore or request retransmission,CodePudding user response:
Do a circular queue, you receive an error when the data is not lost, the next time the received data on tail error data, and find a 00 00 00 04 again if find the right data, then throw in the former part of the data,