Say I have the following structure that is filled with information about an Axis:
TYPE AxisInfo :
STRUCT
AxisStatus : ARRAY [0..3] OF BYTE;
DriveStatis : ARRAY [0..3] OF BYTE;
FeedRate : ARRAY [0..3] OF BYTE;
Inputs : BYTE;
Outputs : BYTE;
Extra : BYTE;
CurPosW: UDINT;
CurPosX: UDINT;
CurPosY: UDINT;
CurPosZ: UDINT;
CurVelX: UDINT;
CurVelY: UDINT;
CurVelZ: UDINT;
ComPos : UDINT;
SetVel : UDINT;
DacVel : UDINT;
WinchErrPos : UDINT;
XYZErrPos : UDINT;
EnFaults : UDINT;
ActFaults : UDINT;
BpFaults : UDINT;
BpTimeLeft : UDINT;
This Structure holds 82 bytes in total. I will have 8 of these structures running at all time (since I have 8 axis). That amounts to 656 bytes combined with all the structures.
Now, I have a variable called Buffer :
Buffer: ARRAY [0..1023] OF BYTE;
I would like to be able to fill up this buffer with each of the 8 structures, in order. For instance:
Buffer[0] := AxisStatus[0]; //this is for the 1st axis
Buffer[1] := AxisStatus[1]; //this is for the 1st axis
….
Buffer[78] := BpTimeLeft; //this is for the 1st axis
…
Buffer[648] := BpFaults;
Buffer[652] := BpTimeLeft; //this is for the 8th axis
Is there a way in ST on the PLC, to iterate over members of a structure and then place those members into a buffer and making sure they are in proper places? Do you know of any tricks to do this?
I ask this because I can do it in the following method,
For axisIndex:=1 to 8 DO
Buffer[0] := AxisStatus[0];
Buffer[1] := AxisStatus[1];
…
Buffer[78] := BpTimeLeft; this is for the 1st axis
END_FOR
but I have to type out every line for which the buffer needs to get allocated to, and then have to do some trick after I have filled the buffer with the first axis to avoid it overwriting the first 82 bytes. There must be some way to do it automatically in case I change the members of the struct in the future.?