I have data streaming in from a serial device. I have this as a hex string, where the data packets always begin with F4
.
i am using:
while (_serialPort.BytesToRead > 0)
{
var chunk = new byte[_serialPort.BytesToRead];
_serialPort.Read(chunk, 0, chunk.Length);
_text += BitConverter.ToString(chunk);
}
And as it is BytesToRead
, the chunk variable is always different. How should i be splitting out the packets as they come in?
I am thinking:
If string contains F4
,
start pushing data into buffer.
At next F4
, stop, process existing buffer and start to fill again.
Is this a viable approach? What is the best way to approach this?