A struct type allows you to declare a composite type from existing data types. For example:
Type (* Enumerated type for the motor state *) MotorDriveState : (Stopped, Running ); (* The motor drive *) MotorDrive : Struct State : MotorDriveState; CurrentInAmps : REAL; StartStopCount : UDINT; TotalRunTime : TIME; End_Struct; End_Type
The MotorDrive structure declares a 17 byte block of memory laid out as follows:
Offset | Length | Member |
---|---|---|
0 | 1 | State (Enumerated) |
1 | 4 | CurrentInAmps (REAL) |
5 | 4 | StartStopCount (UDINT) |
9 | 8 | TotalRunTime (TIME) |
Within your code you can access structure members using the period (.) character. For example:
Var M1, M2 : MotorDrive End_Var (* Initialize the state of M1 *) M1.State := MotorDriveState#Stopped; M1.CurrentInAmps := 0; M1.StartStopCount := 0; M1.TotalRunTime := T#0s;
IEC 61131-3 Second Edition: Table 12.5.
IEC 61131-3 Third Edition: Table 11.6.
To learn about other derived data types, for example ARRAY.
To learn about the built-in elementary types for example REAL, or TIME.
To learn about other common language elements.
For the meaning of terms used in Fernhill SCADA.