Skip to main content

Alarms in Library Projects

As a library developer, you can define alarm conditions for a function block or an alarm structure type.

Create an Alarm Group Template for the variables of such POUs. Configure the alarm definitions in it. The alarm group template is located in the POUs view or in the device tree at the same level as the object of the POU. When you use the POU in an application, the alarm definitions are instantiated in the Alarm Configuration object. The alarms are then checked at runtime.

Tip

Always use the alarm group template when a function block with alarm states is instantiated multiple times. Compared to alarm definitions per instance in an alarm group, the generated code is noticeably smaller and compilation is significantly faster.

As an application developer, you use library POUs with alarm definitions to create an alarm configuration.CODESYS supports you throughout the entire development of your application.

  1. Select your application and click Add Object → Alarm Configuration.

    The Alarm Configuration object is now displayed below your application in the device tree.

  2. In the editor of the alarm configuration, on the Alarm Instances tab, click the Create or update alarm instances button.

    In a generation cycle, the compiler creates alarm instances for all instances of function blocks with alarm definitions.

    Figure 6. Alarm Configuration
    Alarm Configuration


    You can then continue editing the alarm configuration and, for example, deselect individual alarm instances.

    When the IEC code is compiled, a check is performed to see whether the alarm instances are complete and correct. This keeps the application code consistent with the alarm configuration. The result is output in Messages. If you do not want this check, then clear the Search for new alarm instances during compilation option in the alarm configuration.

Tip

With the attribute pragma {attribute 'alarm_creation_default'}, you define whether alarm instances are generated by default for an instance.

For more information, see the following: Alarm Configuration, Alarm Group Template, ???

Defining alarm classes centrally in library

You can define alarm classes centrally in a separate library. The advantage of this is that you can centrally define, change, and manage the properties and behavior of the alarm classes. The alarm classes are then referenced in implementation libraries, which consist of function blocks with the respective alarm group templates.

Alarm classes from other libraries must be listed with namespaces in order to avoid ambiguities with local alarm classes of the same name.

Because there is currently only one alarm memory, configuration in the alarm group is not necessary. The alarm class determines whether or not an alarm is saved.

_vis_img_library_alarmclass.png

The behavior of alarm classes can be centrally defined in libraries if library alarm classes are implemented, which can then be referenced in implementation libraries.

Note

The previously predefined Error, Info, and Warning alarm classes below the alarm configuration can be deleted if only alarm classes from libraries should be used.

Using function blocks with an alarm group template in a library

The alarm conditions for variables of the type can be defined in the alarm group templates.

  1. Select your application.

    Click Add Object → Alarm Group Template and specify a name in the Add Alarm Group Template dialog.

    The new alarm group template object AGT_FB_DoIT is created below your application.

    Hint: The object can also be stored under POUs.

  2. In Type for alarm definition, select the type (function block or structure) for which you want to define alarms.

    FB_DoIt

  3. Under Details, define an alarm for the type:

    • Under Details, program an alarm condition.

    • Under Class, specify an alarm class, ideally one from an alarm class library.

    _vis_img_alarm_group_template.png

Function block with inheritance

If you have a base function block which extends other function blocks, then you can also create an alarm group template for this base function block and define alarms there.

Alternatively, you could also create an alarm group template for a derived function block. It is also possible to access the variables of the base function block so that you can program alarm definitions for the inherited variables.

_vis_img_library_alarmgroup.png

Creating and updating alarm instances

You can update the alarm configuration so that all declared instances across the application are listed there.

  1. In CODESYS, open the Alarm Configuration object below the application.

  2. Click the Create or update alarm instances button.

    All instances with alarm group templates of the application are currently listed in the Alarm Instances table.

For more information, see the following: Using API Calls to Control Alarms Programmatically and Using API Calls to Trigger Events Programmatically

Checking the project

You can enable or disable the generation of alarms for instances. By default, all alarm instances are added to the alarm configuration. Under the Create column, you can deselect individual instances so that no alarm evaluation is done for a specific instance.

If you want to divide the alarm instances into different groups, then you can make the assignment in the Alarm Group column. The alarm groups must first be created below the alarm configuration.

For more information, see the following: Alarm Configuration and alarm_creation_default