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

Page 1041

Advertising
background image

L-force | PLC Designer

Programming Reference

DMS 4.1 EN 03/2011 TD29

1039

Pointers
As an extension to the IEC 61131-3 standard it is possible to use pointers.
Pointers save the addresses of variables, programs, function blocks, methods and
functions while an application program is running. A pointer can point to any of those
objects and to any data type, even to user-defined data types. Notice the possibility of
using an implicit pointer check function.
Syntax of a pointer declaration:
<identifier>: POINTER TO <data type | function block | program | method | function>;
Dereferencing a pointer means to obtain the value currently stored at the address to
which it is pointing A pointer can be dereferenced by adding the content operator "^"
after the pointer identifier; see for example "pt^" in the example below.
The Address Operator ADR can be used to assign the address of a variable to a pointer.
Example:

VAR
pt:POINTER TO INT; (* declaration of pointer pt *)
var_int1:INT := 5; (* declaration of variables var_int1 and var_int2 *)
var_int2:INT;
END_VAR
pt := ADR(var_int1); (* address of varint1 is assigned to pointer pt *)
var_int2:= pt^; (* value 5 of var_int1 gets assigned to var_int2 via dereferencing
of pointer pt; *)


Function pointers
In contrast to »PLC Designer« V2.3 also function pointers are supported, replacing the
INDEXOF operator. This pointers can be passed to external libraries, but there is no
possibility to call a function pointer within
an application in the programming system!
The runtime function for registration of callback functions (system library function)
expects the function pointer, and, depending on the callback for which the registration
was requested, then the respective function will be called implicitly by the runtime
system (for example at STOP). In order to enable such a system call (runtime system)
the respective property (category "Build") must be set for the function object.
The ADR operator can be used on function names, program names, function block
names and method names. Since functions can move after online change, the result is
not the address of the function, but the address of a pointer to the function. This
address is valid as long as the function exists on the target.

Advertising