Subrange types, L-force | plc designer – Lenze PLC Designer PLC Designer (R2-x) User Manual
Page 530
L-force | PLC Designer
Data types in PLC Designer
528
DMS 3.2 EN 02/2011 TD29
11.2.7
Subrange types
A subrange type is a type whose range of values is only a subset of that of the basic
type. The declaration can be carried out in the data types register, but a variable can
also be directly declared with a subrange type:
Syntax for the declaration in the 'Data types' register:
TYPE <Name> : <Inttype> (<ug>..<og>) END_TYPE;
<Name>
must be a valid IEC identifier,
<Inttype> is one of the data types SINT, USINT, INT, UINT, DINT, UDINT, BYTE, WORD, DWORD (LINT,
ULINT, LWORD).
<ug>
Is a constant which must be compatible with the basic type and which sets the lower
boundary of the range types. The lower boundary itself is included in this range.
<og>
Is a constant that must be compatible with the basic type, and sets the upper boundary of
the range types. The upper boundary itself is included in this basic type.
Examples:
TYPE
SubInt : INT (-4095..4095);
END_TYPE
Direct declaration of a variable with a subrange type:
VAR
i : INT (-4095..4095);
ui : UINT (0..10000);
END_VAR
If a constant is assigned to a subrange type (in the declaration or in the
implementation) that does not fall into this range (e.g. 1:=5000), an error message is
issued.
In order to check for observance of range boundaries at runtime, the functions
CheckRangeSigned or CheckRangeUnsigned must be introduced. In these, boundary
violations can be captured by the appropriate method and means (e.g. the value can
be cut out or an error flag can be set.). They are implicitly called as soon as a variable is
written as belonging to a subrange type constructed from either a signed or an
unsigned type.