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

Page 1037

Advertising
background image

L-force | PLC Designer

Programming Reference

DMS 4.1 EN 03/2011 TD29

1035

Direct declaration of a variable with a subrange type:

VAR
i : INT (-4095..4095);
ui : UINT (0..10000);
END_VAR


If a value is assigned to a subrange type (in the declaration or in the implementation)
but does not match this range (for example i:=5000 in the upper shown declaration
example), an error message will be issued.

Check Functions
In order to check the range limits during runtime the functions CheckRangeSigned or
CheckRangeUnsigned must be available to the application. Therefore add the object
"POUs for implicit checks" to the application using the Add Object dialog. Mark the
checkbox related to the type CheckRangeSigned or CheckRangeUnsigned, choose an
implementation language and confirm your settings with Open, whereon the selected
function will be opened in the editor corresponding to the implementation language
selected. Independently of that choice the declaration part is preset and may not be
modified except for adding further local variables! A proposal default implementation
of the function that might be modified is given in the ST Editor.
The purpose of this check function is the proper treatment of violations of the
subrange (for example by setting a detected error flag or changing the value). The
function will be called implicitly as soon as a variable of subrange type is assigned.

Attention: In order to maintain the check functionality do not change the
declaration part of an implicit check function!

Example:
The assignment of a variable belonging to a signed subrange type entail an implicit call
to CheckRangeSigned. The default implementation of that function trimming a value
to the permissible range is provided as follows:
Declaration part:

// Implicitly generated code : DO NOT EDIT
FUNCTION CheckRangeSigned : DINT
VAR_INPUT
value, lower, upper: DINT;
END_VAR

Advertising