CODESYS ยท Track 05 ยท hardware abstraction

The device tree

CODESYS keeps your logic and your hardware apart. The device tree describes the physical setup: the target, its fieldbus and the I/O modules. An I/O mapping ties each physical channel to a variable. Your program reads the variable instead of the channel directly. When you swap the target, the logic stays the same and you change the mapping.

๐ŸŒฒ device tree๐Ÿ”— I/O mappingportable logic
01 ยท Swap the target, keep the logic

Connect variables to physical channels

The tree shows a target with an EtherCAT master and an 8-point input module; the table maps its channels to your variables (xStartPB, xLevelHiโ€ฆ). Press ๐Ÿ”„ Re-target to move the project to a different vendor's controller. Watch the target and channel addresses change while your variable names stay identical.

I/O mapping: your variables and physical channels

Variable (your logic)Channel (this target)

The variable names didn't change when you switched targets. Your POUs, languages and logic refer to those names; the device tree and mapping hold the hardware configuration. Re-target the project, remap its channels, then download the same program. This is how the separation described in Track 01 lets you move a program between controllers.

02 ยท The layers of the tree

From target down to a pin

๐ŸŽฏ Target / device is the controller you're running on. Changing it re-points the project to that controller, and CODESYS recompiles for the new runtime.

๐Ÿ”Œ Fieldbus master is added under the target: EtherCAT, PROFINET or Modbus, for example. It imports device descriptions (ESI/GSDML) for the slaves below it (Track 06).

๐Ÿ“Ÿ Slave / module is an I/O block, drive or sensor on the bus. Its channels are exposed so you can map them to program variables.

๐Ÿ”— The mapping binds a channel to a variable. Together with the device tree above it, it holds the hardware-specific part of your project; your POUs do not change.

03 ยท Check yourself

What moves on a re-target?

You re-target a finished project from a Raspberry Pi to an industrial controller. What needs attention?