Using Nested Data Structures
You can 'nest' data structures within other data structures. This is useful for creating a sub-group of values. For example, if a Logic program needs to use the values of 3 different pumps, it may have a data structure for a pump. The PUMP data structure contains definitions for CurrentState: REAL; and UpdateTime: TIME; variables. The variables for each of the pumps will be set to use the PUMP data structure.
The Logic program also needs to use the name of the engineer that last calibrated each pump, and the time at which the calibration took place. To achieve this, another data structure is created:
STRUCT Calibration_Struct
CalibDate: DATE_AND_TIME;
Engineer: STRING;
END_STRUCT;
The Calibration_Struct data structure is included within the TYPE and END_TYPE definition, and is positioned above the PUMP data structure. (Data structures that are to be nested within other data structures have to be entered above the non-nested data structures).
The PUMP data structure is then altered to include the Calibration_Struct data structure:
STRUCT PUMP
Calibration: Calibration_Struct;
CurrentState: REAL;
UpdateTime: TIME;
END_STRUCT;
So, in the PUMP data structure (shown above), the Calibration : Calibration_Struct; line embeds the Calibration_Struct data structure within the PUMP data structure.
The VAR variables list then needs to include the PUMP data structure. The Calibration_Struct data structure is not needed as a variable as it is included in the PUMP data structures:
VAR
Pump1Data: PUMP;
Pump2Data: PUMP;
Pump3Data: PUMP;
END_VAR
In the Logic program, references to the values of the pumps will use the following format:
<Name of variable>.<name of field>
For example, Pump1Data.CurrentState is a reference to the current state value of Pump 1.
To reference the calibration values, use the following format:
<Name of variable>.<name of nested data structure>.<name of field>
For example, Pump1Data.Calibration_Struct.Engineer is a reference to the name of the engineer that calibrated Pump 1.