Absolute Addresses of Operands

Adress Operator ADR:

For particular blocks or in case of accessing operands via pointers, the absolute address of an operand must be determined. To do this, the Automation Builder provides the address operator ADR.

The address operator ADR is described in the documentation for the Automation Builder (see CODESYS Documentation / ADR operator). The following description describes only the peculiarities of bit operands.

The addresses provided by the address operator can be used as inputs for blocks that require absolute addresses (such as xxx_MOD_MAST, COM_SND). If these blocks shall be applied to internal variables, it must be guaranteed that the variables are set to successive addresses. This is achieved by declaring ARRAYs and STRINGs.

The address operator ADR provides the address of an operand in one double word DWORD (i.e., 32 bits). The address operator returns the address of the first byte of a variable (byte address). For the user-definable variables, variables of the type BOOL are stored as byte.

Bit Address Operator BITADR:

For inputs, outputs and variables of the addressable flag area (%M area) or addressable PERSISTENT area (%R area), operands of the type BOOL occupy one bit. The address of this type of variables cannot be determined with the operator ADR.

When processing the statement: dwAddress := ADR(%MX0.0.0); the following error message appears:

Error 4031:

PLC_PRG(xx): ADR is not allowed for bits! Use BITADR instead.

BITADR returns the bit offset within the area %I, %Q or %M as DWORD.

The following table shows the position of the operands within the memory (considering %MD0.0 and %MD0.1 as example). Here you get information about which addresses the operator ADR returns and which offsets BITADR returns.

Note

The addresses shown are example addresses and thus can have other values.

Position of operands within memory and values of operators ADR and BITADR:

Byte SINT / BYTE Word INT / WORD Double word DINT / DWORD Bit (byte-oriented) BOOL ADR BITADR
%MB0.0 %MW0.0 %MD0.0 %MX0.0.0 16#08000000 8
%MX0.0.1 9
%MX0.0.2 10
%MX0.0.3 11
%MX0.0.4 12
%MX0.0.5 13
%MX0.0.6 14
%MX0.0.7 15
%MB0.1 %MX0.1.0 16#08000001 0
%MX0.1.1 1
%MX0.1.2 2
%MX0.1.3 3
%MX0.1.4 4
%MX0.1.5 5
%MX0.1.6 6
%MX0.1.7 7
%MB0.2 %MW0.1 %MX0.2.0 16#08000002 24
%MX0.2.1 25
%MX0.2.2 26
%MX0.2.3 27
%MX0.2.4 28
%MX0.2.5 29
%MX0.2.6 30
%MX0.2.7 31
%MB0.3 %MX0.3.0 16#08000003 16
%MX0.3.1 17
%MX0.3.2 18
%MX0.3.3 19
%MX0.3.4 20
%MX0.3.5 21
%MX0.3.6 22
%MX0.3.7 23
%MB0.4 %MW0.2 %MD0.1 %MX0.4.0 16#08000004 40
%MX0.4.7 47
%MB0.5 %MX0.5.0 16#08000005 32
%MX0.5.7 39
%MB0.6 %MW0.3 %MX0.6.0 16#08000006 56
%MX0.6.7 63
%MB0.7 %MX0.7.0 16#08000007 48
%MX0.7.7 55