In the variables declaration, the code AT
assigns a project variable to a specific input address, output address, or memory
address of the PLC that is configured in the device tree. You can also define the
assignment of variables to an address in the “I/O Mapping” dialog of the device in the PLC configuration.
Syntax
<variable name> AT <address> : <data type>; <address> : %<memory area prefix> ( <size prefix> )? <memory position>
The AT declaration allows you to give the address a meaningful name. You can make any necessary changes for the input or output signals at just one location, for example in the declaration.
Examples
|
Variable declaration with address information of an input word |
|
Boolean variable declaration Note: For Boolean variables, one byte is allocated internally if a single bit address
is not specified. A change in the value of |
|
Boolean variable declaration with explicit specification of a single bit address On access, only the input bit 7.5 is read. |
|
For the address specification, the placeholder Note: This is possible in function blocks. |
If you assign a variable to an address, note the following:
-
You cannot write to variables that are placed at inputs. This will cause a compiler error.
-
You can perform AT declarations only for local and global variables, not for input/output variables of POUs.
-
Furthermore, AT declarations cannot be used in persistent variable lists.
-
If you use AT declarations for structure components 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.




NOTICE

If you do not specify a single bit address explicitly, then Boolean variables are allocated byte-by-byte.
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.