Using a clear configuration editor for I/O mapping
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 PLC that is configured in the device
tree. The AT declaration makes it possible to give an 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).
Syntax
<variable name> AT % <address> : <data type>;
|
<variable name> |
Required |
|
% <address> |
Required Address in the memory area % <memory area prefix> <size prefix> <memory position> |
|
<memory area prefix> |
Required
|
|
<size prefix> |
Optional
|
|
<memory position> |
<position number> . <bit position number> Example: %IB2.4 stands for the 5th bit of the 3rd byte |
|
<position number> |
Required The numbering depends on the target system and starts at 0. |
|
. <bit position number> |
Optional 0..7 for one byte |
|
<data type> |
Optional The data type should match the size prefix. |
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. |
Helpful hints
If you do not specify a single bit address explicitly, then Boolean variables are allocated byte-by-byte.
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 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.
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.