C#C
C#2y ago
kianyuen

How to stream bytes from SerialPort (System.IO.Ports) into a chart.

I'm using WPF on .NET Framework 4.8.

The packet that I'm trying to catch is sent at 250Hz.
I was under the assumption
My current basic implementation is as follow:
On port.DataReceived, I will collect the data then store it to another buffer to further process it later (to deal with potential last unfinished packet by just queueing them).
            SerialPort spL = (SerialPort)sender;
            byte[] buf = new byte[spL.BytesToRead];
            spL.Read(buf, 0, buf.Length);
            _receiveBuffer.AddRange(buf);

I personally think this is hacky and non-efficient, is there a better existing approach that I'm not aware of?
Was this page helpful?