Example: MacroModules
Product: CODESYS Application Composer
This example shows how to use macro modules. With a valid license for the CODESYS Application Composer, this example generates new macro modules from the module tree.
Description
The example describes a building which contains rooms. These rooms have switches and lights, each of which is available in two variants. The lights (blinking or steady) can be linked to switches or -buttons. A switch or-button can be linked to several lights. For example, if a light is equipped with both a switch and buttons, then the switch behaves as a main switch which must be pressed before the lights can be operated with the push-buttons. If only switches are installed, then these switch the referencing light. A blinking light automatically switches between on and off when it is switched on.
Module declarations
Function block declarations
Device tree
Module tree
![]() |
For more information, see: Command: Create macro-module.
Additional information
In the model tree, select the module instance for whose subtree you want to create the module.
In the context menu, click the Create macro-module command.
The New macro-module dialog opens.
Define the name, description, and category of the new macro module.
Define which slots, I/Os, and parameters are directly part of the macro module.
For example, it is possible to hide slots or to reserve them automatically. Frequently recurring constellations of tree connections can be combined into one module. When the macro module is inserted, the entire assembly and the parameterization of the entire subtree are done by the CODESYS Application Composer.
In the example, the visualization is already extended by one macro module. To use this, you need to create and instantiate the RoomUnitMacro_OneLightOneInverter
macro module as a module from the Room2
instance. This macro module should include the constellation "one room with one light and one switch".
After a generation cycle by the CODESYS Application Composer, you can then use the application with the visualization.
![]() |
Another application example is the draft in the form of subtrees of two different control settings for a motor. For example, while one control setting is responsible for low overshoot, the other one could primarily follow the target in order to achieve the specified value as fast as possible.
Both subtrees with parameter sets could each be combined within one macro module. When creating the module tree, you can then use the desired control module without having to complete all of the subtree configuration or without even seeing the subtree.
System requirements and restrictions
Programming system | CODESYS Development System (version 3.5.17.0 or higher) |
Runtime system | CODESYS Control Win (version 3.5.17.0) |
Add-on components | CODESYS Application Composer |
Note
DOWNLOAD Projects