Appendix 10.7.5 FUNCTION CheckDivDWord : DWORD If you define functions in your project with the name CheckDivDWord, you can use them to check the value of the divisor if you use the operator DIV [ } 313] , for example to avoid a division by 0. The name of the function is defined and may have only this identifier. NOTE System load CheckBound function may cause increased system load. Please use CheckBounds only for test purposes. VAR_INPUT divisor : DWORD; END_VAR Example of CheckDivDWord implementation: IF divisor = 0 THEN CheckDivDWord := 1; ELSE CheckDivDWord := divisor; END_IF 10.7.6 FUNCTION CheckRangeSigned :
DINT In order 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; TwinCAT 2 PLC Control 337 Version: 1.0