The operator is an extension of the IEC 61131-3 standard.
ADR
yields the 32-bit address (or the 64-bit address, if possible) of its argument. You
can pass this address to the manufacturer functions or assign them to a pointer in
the project.
Syntax
VAR <address name> : DWORD | LWORD | POINTER TO < basis data type> | __XWORD ; END_VAR <address name> := ADR( <variable name> );
Example
FUNCTION_BLOCK FB_Adress VAR piAddress1: POINTER TO INT; iVar1 : INT := 5; lwAddress2 : LWORD; iVar2 : INT := 10; xwAddress3 : _XWORD; iVar3 : INT; END_VAR piAddress1 := ADR(iVar1); // piNumber is assigned to address of iVar1 lwAddress2 := ADR(iVar2); // works for 64 bit run time system xwAddress3 := ADR(iVar3); // works for 32 bit and 64 bit systems




NOTICE

Different from CODESYS V2.3 Gateway Server, you can use the ADR
operator with function names, program names, function block names, and method names.
Therefore, ADR
replaces the INDEXOF
operator.
When using function pointers, note that you can pass a function pointer to external libraries, but it is not possible to call a function pointer from within CODESYS. To enable a system call (runtime system), you must set the respective object property (“Build” tab) for the function object.




CAUTION

When you use an online change, the contents of addresses can shift. As a result, POINTER TO
variables could point to an invalid memory area. To avoid problems, you should make
sure that the value of pointers is updated in every cycle.




CAUTION

Do not return Pointer-TO
variables of functions and methods to the caller or assign them to global variables.
-
See also: ⮫ POINTER TO