Skip to main content

POU: CheckLRangeSigned

Function for monitoring the range limits of a subrange type of type LINT

For an implementation example of range monitoring, see the help page for the CheckRangeSigned function.

Monitoring range limits

This monitoring function is responsible for the appropriate handling violations to range limits. Examples of reactions to violations include setting error flags and changing values. The functions are called implicitly when a value is assigned to a subrange type variable.

Caution

To get the feature for monitoring functions, do not edit the declaration part. However, you are permitted to add local variables.

. When the function is called, it receives the following input parameters:
  • value: Value that should be assigned to the subrange type variables

  • lower: Lower range limit

  • upper: Upper range limit

The return value is the assignment value as long as it is within the valid range. If not, then either the upper or lower limit is returned, depending on which threshold was violated.

For example, the assignment i := 10*y is replaced implicitly by i := CheckRangeSigned(10*y, -4095, 4095);

If y is "1000", then "10*1000=10000" is not assigned to i like in the original code. Instead, the upper range limit of "4095" is assigned.

The same is true for CheckRangeUnsigned function.

Important

If functions are not available, then the subrange is not checked for the respective variables at runtime. In this case, you can assign any value between -2147483648 and +2147483648 (or between 0 and 4294967295) to a variable of subrange type DINT/UDINT. You can assign any value between -9223372036854775808 and +9223372036854775807 (or between 0 and 18446744073709551615) to a variable of a subrange type LINT/ULINT.

Caution

Linking area monitoring functions can lead to infinite loops. For example, an infinite loop can occur if the counter variable of a FOR loop is a subrange type and the counting range for the loop exits the defined subrange.

Example 535. Example of an infinite loop:
VAR
        ui : UINT (0..10000);
 ...
END_VAR
FOR ui:=0 TO 10000 DO
        ...
END_FOR

The program never exits the FOR loop because the CheckRangeSigned monitoring function prevents ui from being set to a value greater than 10000.