Addresses

Caution

If you use pointers to addresses, then the contents of addresses can be moved during an online change. If you use absolute addresses, then the contents of addresses does not change during an online change.

When defining an address, you use specific character strings to express memory position and size.

Syntax:

%<memory range prefix><size prefix><number|.number|.number....>

The following memory range prefixes are supported:
I input memory range (physical inputs from input drives, sensors)
Q output memory range (physical outputs for output drives, actuators)
M flag memory range
The following size prefixes are supported:
X (single) bit
None (single) bit
B BYTE (8 bits)
W WORD (16 bits)
D DWORD (32 bits)

Examples

%QX7.5

%Q7.5

output bit 7.5
%IW215 input word 215
%QB7 output byte 7
%MD48 double word at memory position 48 in flag memory
%IW2.5.7.1 Interpretation depends on the current controller configuration (see below).
ivar AT %IW0: WORD; example of a variable declaration with an address

See also

You ensure that the address is valid as follows:

To assign a valid address in an application, you must know the required position (applicable memory range) in the process map: input memory range (I), output memory range (Q), and flag memory range (M) — see above. In addition, you must define the required size: BIT, BYTE, WORD, DWORD (see above: X, B, W, D)

The current device configuration and device settings (hardware structure, device description, I/O settings) play a decisive part. Please note specifically the differences in the interpretation of bit addresses for devices with byte addressing mode and devices with word-oriented IEC addressing. For example, the first element of the bit address %IX5.5 addresses byte 5 in a byte-addressed device and it achieves word 5 in a word-addressed device. Moreover, addressing with word or byte addresses is independent of device type. Word 5 is always addressed with %IW5 and byte 5 always with byte address %IB5.

Regardless of size and addressing mode, you can address different memory cells therefore with the same address information.

The following table shows the comparison of byte addressing and word-oriented IEC addressing for bits, bytes, words, and dwords. It also shows the the overlapping memory ranges that are present in the case of byte addressing (see also the example below the table).

Please note that the syntax in IEC addressing mode is always word-oriented: word number before point and bit number after point.

n = byte number

Memory range overlapping in the case of byte addressing — example:

Given: D0 contains B0 - B3, W0 contains B0 and B1, W1 contains B1 and B2, and W2 contains B2 and B3 -> To avoid overlapping, you must not use W1 or D1, D2, D3 for addressing.

Hint

When you do not define a single bit address explicitly, CODESYS allocates Boolean values in bytes.

Example: Changing the value of varbool1 AT %QW0 affects the range QX0.0 to QX0.7.