© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
12 replies
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);
            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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ AdditionalText to Bytes or stream
C#CC# / help
4y ago
✅ SerialPort performance
C#CC# / help
2y ago
✅ System.IO.FileNotFoundException
C#CC# / help
2y ago
System.IO.FileLoadException
C#CC# / help
3y ago