I’m trying to receive a record in binary from a PIC programmed in C.
The data sent is structured so:
typedef struct{int32 num1;
float num2,num3,num4,num5;
...
}RecordStructure;
typedef union{RecordStructure Record; char Array[48];} My_Rec_Structure;
My question is this:
Do the first 4 bytes/chars belong to the int32 num1, the next 4 to float num2 and so on?
If so I’m having major issues with transmission; if not, how do I discern where the data ended up?
How data is aligned within a struct can vary between compilers as well as the pragmas used to force a particular alignment.
If this compiler aligns items on a double word boundary then the first 4 bytes, num1, should line up with the first 4 bytes of the char Array, the second four bytes, num2, with the second four bytes of the char Array, etc.
If possible what you can do is to use a debugger to examine the data when it is received. And in the data that is sent you put a specific hex digit sequence so that you can know whether things are lining up as you think or not.
So on the PIC the data sent in the struct might be:
Then send that across to see what it looks like. and whether the num1 value is the same.
If you then modify the data for instance if myRecord.num3 = 1.0 you will be able to see if things line up or not.