L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 1038

Advertising
background image

L-force | PLC Designer

Programming Reference

1036

DMS 4.1 EN 03/2011 TD29

Implementation part:

// Implicitly generated code : Only an Implementation suggestion
IF (value < lower) THEN
CheckRangeSigned := lower;
ELSIF(value > upper) THEN
CheckRangeSigned := upper;
ELSE
CheckRangeSigned := value;
END_IF


When called the function gets the following input parameters:
• value: the value to be assigned to the range type
• lower: the lower boundary of the range
• upper: the upper boundary of the range
As long as the assigned value is within the range, the output of the function is the
value itself. Otherwise -in correspondence to the range violation- either the upper or
the lower boundary of the range will be returned.
The assignment i:=10*y will now be replaced implicitly by

i := CheckRangeSigned(10*y, -4095, 4095);

If y has the value "1000" for example, the variable i will not be assigned to
"10*1000=10000" as provided by the original implementation, but to the upper
boundary of the range, that is "4095".

The same applies to function CheckRangeUnsigned.

Note: If neither of the functions CheckRangeSigned or CheckRangeUnsigned is
present, no type checking of subrange types occurs during runtime! In this case
variable i could get any value between –32768 and 32767 at any time!
Attention: The use of the functions CheckRangeSigned and CheckRangeUnsigned
may result in an endless loop, for example if a subrange type is used as increment of
a FOR loop that does not match the subrange.

Advertising