Beckhoff Automation GmbH & Co. KG TX1200 — 7.4.7 CheckRangeUnsigned : UDINT

Reference programming NOTICE Value of variable/continuous loop If neither of the functions CheckRangeSigned or CheckRangeUnsigned [ } 222] is present, no type checking of subrange types occurs during runtime! The variable i could then take on any value between –32768 and 32767 at any time! If a function CheckRangeSigned or CheckRangeUnsigned is is implemented as shown above, a continuous loop can develop with the use subrange types in a FOR loop. This occurs exactly if the area indicated for the FOR loop is just as large or larger than that subrange types! Example: VAR ui : UINT (0..10000); END_VAR FOR ui:=0 TO 10000 DO ...

END_FOR The FOR loop is not left, because ui cannot became larger than 10000. Likewise, the contents of the CheckRange functions are to be considered when using increment values in the FOR loop! 7.4.7 CheckRangeUnsigned : UDINT To check for observance of range boundaries at runtime, the functions 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 a unsigned type. VAR_INPUT value, lower, upper: UDINT; END_VAR Example:

IIn the case of a variable belonging to a unsigned subrange type, the function CheckRangeUnsigned is called; it could be programmed as follows to trim a value to the permissible range: FUNCTION CheckRangeUnsigned : UDINT VAR_INPUT value, lower, upper: UDINT; END_VAR IF (value CheckRangeUnsigned := lower; ELSIF(value > upper) THEN CheckRangeUnsigned := upper; ELSE CheckRangeUnsigned := value; END_IF In calling up the function automatically, the function name CheckRangeUnsigned is obligatory, as is the interface specification: return value and three parameters of type UDINT When called, the function is parameterized as follows: TX1200 222 Version:

1.3 value the value to be assigned to the range type lower the lower boundary of the range upper the upper boundary of the range Return value the value that is assigned to the range type