POU ‘CheckRangeUnsigned’ΒΆ

Function for monitoring the range limits of a subrange type of type UDINT.

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

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 obtain the feature for monitoring functions, do not edit the declaration section. However, you are permitted to add local variables.

When the function is called, it receives the following input parameters:

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.

Hint

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 endless loops. For example, an endless 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 of an endless 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.

See also