I receive data from usb in specific record structure (cant change it). I have method to read buffer to Byte[]. Simple struct union would do the job but c# is broken in that case.
My struct in C is:
I am trying write received data from usb into Byte[] struct field, and read from structure using proper fields. Union like above would do tha thing but c#....
I tried almost everything, amongs the others, something like:
It compiles but after running it complains:
".... because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field." sic!!! WTF?!
Anybody has any piece of advice or solution for that thing?
My struct in C is:
Code:
typedef union { struct { int Value; int ValueFromADC; int Zero; int Temperature; int RefTemperature; unsigned char Metal; unsigned char Range; unsigned char Year; unsigned char Month; unsigned char Day; unsigned char Hour; unsigned char Minute; unsigned char Second; unsigned char MemoryStatus; unsigned char Bank; unsigned char Cell; unsigned char NC;//not used structure element }; unsigned int Data[8]; unsigned char Bytes[32]; }Value_t;
I tried almost everything, amongs the others, something like:
Code:
[StructLayout(LayoutKind.Explicit, Size = 32)] public struct Value_t { ////////////////////////////// [FieldOffset(0)][MarshalAs(UnmanagedType.LPArray, SizeConst=32)] public Byte[] Bytes; ////////////////////////////// [FieldOffset(0)]public Int32 Value; [FieldOffset(4)]public Int32 ValueFromADC; [FieldOffset(8)]public Int32 Zero; [FieldOffset(12)]public Int32 Temperature; [FieldOffset(16)]public Int32 RefTemperature; [FieldOffset(20)]public Byte Metal; [FieldOffset(21)]public Byte Range; [FieldOffset(22)]public Byte Year; [FieldOffset(23)]public Byte Month; [FieldOffset(24)]public Byte Day; [FieldOffset(25)]public Byte Hour; [FieldOffset(26)]public Byte Minute; [FieldOffset(27)]public Byte Second; [FieldOffset(28)]public Byte MemoryStatus; [FieldOffset(29)]public Byte Bank; [FieldOffset(30)]public Byte Cell; [FieldOffset(31)]public Byte NC; };
".... because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field." sic!!! WTF?!
Anybody has any piece of advice or solution for that thing?
Comment