beckhoff TX1200 — 7.4.6 CheckRangeSigned : DINT

Reference programming The function can cause a significant increase in system load, so it should only be used for testing purposes. VAR_INPUT divisor : DWORD; END_VAR Example of CheckDivDWord implementation: IF divisor = 0 THEN CheckDivDWord := 1; ELSE CheckDivDWord := divisor; END_IF 7.4.6 CheckRangeSigned : DINT To check for observance of range boundaries at runtime, the functions CheckRangeSigned 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 signed type.

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

An assignment i:=10*y implicitly produces the following in this example: i := CheckRangeSigned(10*y, -4095, 4095); Even if y for example has the value 1000, then i still has only the value 4095 after this assignment. TX1200 221 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