- Create a "Standard project" and select CODESYS Control Win V3 as the device.
- Define the target system by means of the Network scan.
Insert an Alarm configuration in the device tree.
Here the Error, Info, and Warning alarm classes are created automatically, as well as the AlarmStorage object. In addition, a AlarmManagerTask is also created.- Create a global variable list GVL with the variable g_sAlarmID.
- Create a new FB named FB_AlarmNotifiable and implement the interface AlarmManager.IAlarmNotifiable.
The method the Execute method is created automatically with the FB:
Adapt the Execute method as follows:
Declaration
//{warning 'add method implementation '} (* Executes the action.*) METHOD Execute VAR_INPUT (* The currently processed alarm state transition. This will be evaluated in order to determine, whether the action has to be executed or not*) eCurrTransition : ALARMMANAGER.AlarmStateTransition; (* The alarm, for which the action has to be performed*) itfAlarm : ALARMMANAGER.IAlarm; (* An optional pointer to a structure variable containing additional parameter*) pbyAdditionalData : POINTER TO BYTE; END_VAR VAR itfAlarmGroup : ALARMMANAGER.IAlarmGroup; END_VAR
Implementation
itfAlarmGroup := itfAlarm.GetAlarmGroup(); GVL.g_sAlarmID := itfAlarmGroup.GetStringID(itfAlarm.GetID());
Adapt the POU PLC_PRG as follows:
Declaration
VAR xAlarm : BOOL; fbAlarmNotifiable : FB_AlarmNotifiable; END_VAR
Implementierung
// no implementation
- Insert a new alarm group in the Alarm configuration and configure an alarm as follows:
In order for the fbAlarmNotifiable instance to also be called at an alarm, the Error alarm class must still be notified about it.
Load the project to the controller and start it.
Set the xAlarm variable to TRUE in the POU PLC_PRG.
Now the global variable GVL.g_sAlarmID will pass the MyAlarmId that was set up in the alarm configuration.