What is the best way to watchdog serial input?
I'm trying to figure the best clean way to watchdog serial input between characters. Take the following code for example...
If a $23 doesnt come in then the code just moves on. If a $23 does come in, then I want to grab the next 3 bytes. If only two come in, then its stuck waiting for the last byte that never shows up. Whats the best way to get out of that and just move on?
Thanks
x := FDS.RxCheck
if x == $23
x := FDS.rx
y := FDS.rx
z := FDS.rx
If a $23 doesnt come in then the code just moves on. If a $23 does come in, then I want to grab the next 3 bytes. If only two come in, then its stuck waiting for the last byte that never shows up. Whats the best way to get out of that and just move on?
Thanks

Comments
SerialReadBuffer[0] := ser.rx 'waits here for first byte (1F) from master Repeat 6 'look for more, else return SerialReadBuffer[ii] := ser.rxtime(2)You also add the option to only read further if you see the packet header.
IF ser.rx == $1F Repeat 3 'look for more, else return SerialReadBuffer[ii] := ser.rxtime(2) ParseSerialReadBufferWhen watching for some external device to send data, you can't always be certain that the complete packet will be received. The other device could malfunction, you can have a bad connection, etc. Having the code only stick at the top of the code makes sure that no matter what you receive, you cannot stick somewhere that will screw with your code if something doesn't go as planned.
Thanks!
I modified the driver to watch of an end of message character and once the character was received, a message counter was incremented. Only once a full message was received would it get parsed.
I thought this approach had some advantages to watching the incoming message one character at a time.
If your communication protocol includes an end of message character you might want to get the technique some consideration.