I have a device, which send me messages like this [CommandID][Data][Data][CRC]. If CRC not equal i will skip this command, because i know the command lenght. But what i have to do if any byte will lose in transmission?
Asked
Active
Viewed 104 times
0
-
You do not want to toss the entire message. See the accepted answer for fixed-length messages: http://stackoverflow.com/questions/16177947/identification-of-packets-in-a-byte-stream For variable-length messages, there is probably a start or sync byte that has to be hunted. – sawdust Nov 11 '15 at 07:27
-
1The protocol is not good enough to protect you from lost bytes. It requires at least a unique start byte so that you can resynchronize. And a ACK/NAK style handshake so you can tell the transmitter to resend the message. You'll have to implement a handler for the ErrorReceived event and put an end to it when you get a SerialError.Overrun or RXOver. – Hans Passant Nov 11 '15 at 09:18
1 Answers
1
Your CRC check will fail. And you must query again. I'm preferring to query 3-5 times before failing. Hardware unstable and very good chanel/device can fail.

stoarch
- 44
- 4
-
Device don't send me command by request from PC. It send me command by external interrupt – Nodon Nov 11 '15 at 05:23
-
Nothing different. You harvest bytes and when it completes transmission - calculate CRC. If you have error - discard it and wait for next one. – stoarch Sep 03 '16 at 09:49