<< Click to Display Table of Contents >> Navigation: »No topics above this level« Types |
mapp Services V5.16
Customized data types can be declared in TYPE declaration sections.
TYPE [ { <Scope> } ]
// Type declarations
END_TYPE
•NC_GLOBAL: Type visible across all interpreter instances, e.g. all axis groups
•IP_GLOBAL: Type visible within the interpreter instance, e.g. one axis group
•LOCAL: Type visible within the file
The default scope of declared types is determined according to the file extension and the most recent #pragma SCOPE.
Declared types can only be used for data and functions declared within the same or a local scope.
NC_GLOBAL types remain in memory until the PLC restarts, even if the file containing their declarations is unloaded (e.g. using command UNLOAD).
Type declaration files (.TYP) can be started as regular programs (e.g. using MC_BR_MoveProgram) that only perform loading. Alternatively, they can be loaded using directive #pragma LOAD or #include.
#include 'defs.typ'
VAR {AT PLC}
Context : AppContextType; (* AppContextType defined in defs.typ *)
END_VAR
Initial values can be specified in a type declaration. The initial value is used when a variable of that type is created.
If a type defines minimum and maximum values, the minimum value will be applied as the initial value of a variable.
TYPE
Array5Type : ARRAY[0..4] OF DINT := [1, 2, 3, 4, 5];
RangeType : DINT (-100..100);
END_TYPE
VAR
A: Array5Type; (* A initialized to [1, 2, 3, 4, 5] *)
R: RangeType; (* R initialized to -100 *)
END_VAR