Operator ‘ADR’ΒΆ

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>
END_VAR

<address name> := ADR( <variable name> );

Example

FUNCTION_BLOCK FB_Address
VAR
        piAddress1: POINTER TO INT;
        iNumber1: INT := 5;
        lwAddress2
        iNumber2: INT := 10;
END_VAR

piAddress1 := ADR(iNumber1); // piNumber is assigned to address of iNumber1
lwAddress2 := ADR(iNumber2); // 64 bit runtime system

Hint

In contrast to CoDeSys V2.3, 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