AT Declaration
Using a clear configuration editor for I/O mapping
We advise against assigning memory addresses as described here, because this can lead to a loss of clarity.
We recommend assigning memory addresses to variables in the configuration editor Edit IO mapping of the device.
The AT
keyword in the variables declaration assigns to a project variable a specific input address, output address, or memory address of the controller which is configured in the device tree.
The AT declaration makes it possible to give an address a meaningful name.
Tip
You can make any necessary changes for the input or output signals at just one location (for example, in the declaration).
For more information, see:
Syntax
<variable name> AT
%
<address>:
<data type>;
<variable name> | Required |
| Required Address in the memory area
|
<memory area prefix> | Required
|
<size prefix> | Optional
|
<memory position> | <position number> Example: |
<position number> | Required The numbering depends on the target system and starts at 0. |
| Optional 0..7 for one byte |
<data type> | Optional The data type should match the size prefix. |
VAR wInput AT %IW0 : WORD; END_VAR | Variable declaration with address information of an input word |
VAR xActuator AT %QW0 : BOOL; END_VAR | Boolean variable declaration Note: In the case of Boolean variables, one byte is allocated internally when a single bit address is not specified. A change in the value of |
VAR xSensor AT %IX7.5 : BOOL; END_VAR | Boolean variable declaration with explicit specification of a single bit address When accessed, only the input bit 7.5 is read. |
VAR xSensor AT %IX* : BOOL; END_VAR | For the address specification, the placeholder Note: This is possible in function blocks. |
Helpful Hints
Important
If you do not explicitly specify a single bit address, then Boolean variables are allocated byte-by-byte.
Important
Individual bit addresses which are mapped to Boolean variables have restrictions. It is not possible to use these variables with VAR_IN_OUT
, REFERENCE TO
, or the ADR
operator.
When you assign a variable to an address, note the following:
You cannot write to variables which are placed at inputs. This will cause a compiler error.
You can make
AT
declarations only for local and global variables, not for input and output variables of POUs.You must not use
AT
declarations in persistent variable lists.If you use
AT
declarations for structure members or function block variables, then all instances use the same memory. This corresponds to the use of "static variables" in classic programming languages such as "C".The memory layout of structures also depends on the target system.
Example
PROGRAM PLC_PRG VAR xVar AT %QW0 : BOOL; END_VAR xVar := TRUE;
When the variable xVar
is written, the output memory range from QX0.0
to QX0.7
is affected.