rkb771
Member
- Joined
- Jun 21, 2022
- Messages
- 6
- Programming Experience
- Beginner
I am using .NET 6 for a project where I am reading some data from serial. The
Can anyone please give me some pointer on how
Thank you very much for your time. Any help is appreciated.
Note: I am using
SerialPort.ReadExisting
is my choice of method for reading serial data. This method returns the data as string but I need the data as byte array. I know of System.Text.Encoding.ASCII.GetBytes
but my confusion is that I don't understand if it just casts the data to a new type or converts the data to a new type. I don't want any conversion, I need a simple reinterpretation of the received raw data (like pointer cast in C/C++). The reason is that the received data is binary which may include anything of ASCII text, integer or float (raw 4 byte binary) which will be post-processed later. Any wrongly assumed conversion on, say, the float data will just mess up things.Can anyone please give me some pointer on how
GetBytes
method behaves? If it's appropriate for my case? If not, what are my alternatives other than using a small C dll to pointer cast the memory?Thank you very much for your time. Any help is appreciated.
Note: I am using
ReadExisting
method to queue all received data to be processed by fixed format (custom). I know that I can set [URL='https://learn.microsoft.com/en-us/dotnet/api/system.io.ports.serialport.receivedbytesthreshold?view=dotnet-plat-ext-8.0']ReceivedBytesThreshold[/URL]
to set a fixed chunk size for easy formatting. But docs says that DataReceived
event is fired for EOF character as well, which I couldn't find much information on. So, if this "EOF" is a particular character in this case, it just might appear in the binary data and set off an untimely event.