Hi Louis,
just to summarize:
- you get messages whose length vary from a handful of bytes to hundreds at a low serial speed
- you don't have a termination character
- you don't know in advance the message length (this is not completely clear, I'm guessing from your description)
- you want to read them asap
I recommend you to take some time to decode the message header and get the message length.
Your idea about reading until no more bytes available (I would add: after waiting some tens of ms) is not bad, but it must be tested thoroughly, because it may fail sometimes.
To be honest, also reading the message header is not completely error free, unless the header itself contains some error-checking information; the golden rule here is: never wait forever some event, always make sure a timeout is setup.
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021