using screen program as serial terminal. output line by line.

PaulS:
That whole sketch is based on the erroneous assumptions that all the data that is a packet will arrive very quickly, and that there will be a significant pause between packets.

Not robust code at all.

but, but...
It worked reliably in all my use cases over years :wink:

But yes, I do see your point:
this was always from the Arduino GUI serial monitor, keyboard input.
I was not aware of this dependency. Thanks for pointing that out.

I made up my mind to use a (ring)buffer and an ´end of data package´ code.
I´m inclined to use linefeed as end token, but must check first if this is not asking for trouble again...

Talking about LF: I´m thinking about dropping any CR. Hope that would eliminate another dependency.
Not sure about that, though.

Thanks for sound advice.