© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
LordKalma (CT7ALW)

❔ 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:

#define AETHER_X6100CTRL_BB_FRAME_IQ_SAMPLES_COUNT 512
#define AETHER_X6100CTRL_BB_FRAME_MAGIC 0xAA5555AA

typedef struct
{
    bool resync : 1;
    bool tx : 1;
    bool chg : 1;
    bool vext : 1;
    uint32_t reserved : 28;
} aether_x6100ctrl_bb_frame_flags_t;

typedef struct AETHER_X6100CTRL_PACKED
{
    uint32_t magic; /*!< Every frame starts with AETHER_X6100CTRL_BB_FRAME_MAGIC */
    aether_x6100ctrl_fcomplex_t bb_iq_samples[AETHER_X6100CTRL_BB_FRAME_IQ_SAMPLES_COUNT];
    aether_x6100ctrl_bb_frame_flags_t flags;
    uint8_t reserved_1;
    uint8_t tx_power;
    uint8_t vswr;
    uint8_t alc_level;
    uint8_t vext;
    uint8_t vbat;
    uint8_t batcap;
    uint8_t reserved_2;
    uint32_t atu_params;
    uint32_t reserved_3;
    uint32_t reserved_4;
    uint32_t reserved_5;
    uint32_t reserved_6;
    uint32_t crc;
} aether_x6100ctrl_bb_frame_t;
#define AETHER_X6100CTRL_BB_FRAME_IQ_SAMPLES_COUNT 512
#define AETHER_X6100CTRL_BB_FRAME_MAGIC 0xAA5555AA

typedef struct
{
    bool resync : 1;
    bool tx : 1;
    bool chg : 1;
    bool vext : 1;
    uint32_t reserved : 28;
} aether_x6100ctrl_bb_frame_flags_t;

typedef struct AETHER_X6100CTRL_PACKED
{
    uint32_t magic; /*!< Every frame starts with AETHER_X6100CTRL_BB_FRAME_MAGIC */
    aether_x6100ctrl_fcomplex_t bb_iq_samples[AETHER_X6100CTRL_BB_FRAME_IQ_SAMPLES_COUNT];
    aether_x6100ctrl_bb_frame_flags_t flags;
    uint8_t reserved_1;
    uint8_t tx_power;
    uint8_t vswr;
    uint8_t alc_level;
    uint8_t vext;
    uint8_t vbat;
    uint8_t batcap;
    uint8_t reserved_2;
    uint32_t atu_params;
    uint32_t reserved_3;
    uint32_t reserved_4;
    uint32_t reserved_5;
    uint32_t reserved_6;
    uint32_t crc;
} aether_x6100ctrl_bb_frame_t;


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
struct
like this?

Thanks
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

✅ Need help in reading data from Serial Port
C#CC# / help
2y ago
C++ struct initializing in C#
C#CC# / help
3y ago
✅ STJ cannot deserialize record struct with TimeOnly
C#CC# / help
3y ago
getting data from mongodb to c#
C#CC# / help
3y ago