Whether or not you can configure an I/O mapping to project variables or even to the entire function blocks depends on the type of device. Configuring an I/O map means linking input and output channels of the device with variables of the project. We also use the term "mapping" for this.
Pay attention in general to the following for the mapping of inputs and outputs of a device to variables in CODESYS:
-
You do not have write access to variables that are mapped to an input.
-
You can map an existing variable to one input only.
-
You can directly generate new global implicit variables in the I/O map and map them to a device channel.
-
The memory layout of structures is specified by the device.
-
You can change addresses and fix values in the I/O map.
-
For each variable that is assigned to an I/O channel in the⮫ “Tab: <device name> I/O Mapping ” dialog, you can cause "force variables" to be generated during the compilation of the application (see further below). Using these variables you can, for example during the commissioning of a plant, force a value on the input or output via a visualization/HMI.
-
Changes in the I/O map can be transferred to the controller with an online change.
-
If a pointer to a device input is used, the access is considered to be a write access, for example
pTest := ADR(input);. When the code is generated, this leads to a compiler warning: "...invalid assignment target". If you require a construct of this kind, you have to first copy the input valueinputto a variable with write access. -
An I/O address can also be linked with a variable via the "AT declaration" in the IEC code. Since a device configuration often changes again, however, we recommend that you make the assignments only in the device editor.
If you use the AT declaration, note the following:
-
An AT declaration is permissible only with local or global variables, not with input or output variables of function blocks.
-
Implicit "force variables" for I/Os (see below) cannot be generated for AT declarations.
-
If you use an AT declaration with structure variables or function block variables, all instances will access the same memory location. This then corresponds to the use of "static variables" in classic programming languages such as "C".
-




NOTICE

If a pointer to a device input is used, then the access (for example, pTest := ADR(input);) applies as write access. When the code is generated, this leads to a compiler warning:
"...invalid assignment target".
If you require a construct of this kind, you have to first copy the input value (input) to a variable with write access.
As an alternative, you can assign a variable to an address in the programming code using the AT declaration. In view of possible changes of the device configuration, however, we recommend that you make the assignments only in the device editor.
You can export the I/O mapping configuration of a device to a csv file or import it from such a file.
For more information, see: ⮫ “Command: Export mappings to CSV ”
For more information, see: ⮫ Encryption with Certificates