❔ Deserialize serial data to struct (port from C)
Hello,
I'm not sure how you do this in C#:
I have this code I'm porting to C#. It's basically a stream from a serial port that needs to be de-serialized into a struct.
This is the C code for the struct:
You can explore the code better if you want on this header file and this C file. This is a bit of an on-going work that's a bit rough. Since I want to move to C# and all the code is doing is writing and reading to serial, I thought I could just do away with the base C(++) library.
What tools in C# do you use to define and de-serialize a
struct
like this?
Thanks5 Replies
This is for hardware control for sending/ recieving radio signals right?
I've done a bit of this before for hobby stuff, not professional so take this with a big pinch of salt. You might get struggle using C# for this work. Radio sigal sending and recieving relies on quite precise timings that garbage collected languages might not work reliably for. Languages like C and C++ are really the ideal tool for this kind of job.
Having said that, if you want to try out C#, I'd take a look at https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter.deserialize?view=net-7.0 - it says obsolete beacuse of potential security risks, but I think it's the only choice you have, and hopefully you are reading from hardware you trust 😛
BinaryFormatter.Deserialize Method (System.Runtime.Serialization.Fo...
Deserializes a stream into an object graph.
it's for controlling the actual radio 🙂 but yeah, thanks for the tip 🙂
So you want to transmit or recieve a struct that looks like the one you posted through the radio module?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.