ADR

The operator is an extension of the IEC 61131-3 standard.

ADR delivers the address of its argument in a PVOID or, depending on the runtime system, in a DWORD (32-bit systems) or LWORD (32 and 64-bit systems). To ensure independence from the runtime system architecture, it is recommended to use PVOID as data type.

CAUTION

Shifting the contents of addresses by Online Change

If you use an online change, contents of addresses may shift. As a result, POINTER variables could point to an invalid memory area. In order to avoid problems, make sure that TwinCAT updates the value of pointers when an online change takes place.

Syntax:

VAR
    <address name> : PVOID | DWORD | LWORD | __XWORD | POINTER TO < basis data type>;
END_VAR
<address name> := ADR(<variable name>);

Samples:

ST:

nVar := ADR(bVAR);

FBD:

ADR 1:

Sample with different data types:

FUNCTION_BLOCK FB_Address
VAR
    nVar      : INT := 10;
    pNumber   : POINTER TO INT;
    nAddress1 : PVOID;
    nAddress2 : DWORD;
    nAddress3 : LWORD;
    nAddress4 : __XWORD;
END_VAR
pNumber   := ADR(nVar);   // pNumber wird der Adresse von nVar zugewiesen
nAddress1 := ADR(nVar);   // PVOID   : für 32- und 64-Bit-Systeme
nAddress2 := ADR(nVar);   // DWORD   : nur für 32-Bit-Systeme
nAddress3 := ADR(nVar);   // LWORD   : für 32- und 64-Bit-Systeme
nAddress4 := ADR(nVar);   // __XWORD : für 32- und 64-Bit-Systeme

See also: