I am rather new to Codesys and I'm trying to figure out how to get the status of an alarm.
This to interlock the start of a device until the alarm has been acknowledged...
I am not sure if IAlarm.GetState (METH) can be used for this purpose. If yes then could someone please briefly explain how to use this?
Then you can go through this list to get the state of all the (filtered) alarms.
See below the code which you could use. This is all based on the example from forge.
Create a program:
// This example shows how to access alarms via structured text.PROGRAMPLC_PRGVARxInit:BOOL:=TRUE;udiResult:UDINT;fbAlarmFilterCriteriaAll:FB_AlarmFilterCriteriaAll;fbAlarmManagerClient:FB_AlarmManagerClient;itfAlarmManagerClient:IAlarmManagerClient:=fbAlarmManagerClient;xAlarm1:BOOL;xAlarm2:BOOL;xWarning:BOOL;iNrOfAlarmsInAlarmList:INT;iNrOfActiveAlarmsInAlarmList:INT;paitfAlarm:POINTERTOARRAY[0..0]OFAlarmManager.IAlarm;iAlarmIndex:INT;eAlarmState:AlarmManager.AlarmState;END_VAR
See below some details about the function blocks:
One function block should implement the IAlarmFilterCriteria interface. This can be empty except a few methods.
The other function block should implement IAlarmManagerClient and get a reference to the FB which implements the IAlarmFilterCriteria
FUNCTION_BLOCKFB_AlarmManagerClientIMPLEMENTSAlarmManager.IAlarmManagerClientVAR_INPUTitfAlarmFilterCriteria:AlarmManager.IAlarmFilterCriteria;END_VARMethodimplementation(othersrelatedtotheinterfaceareempty)METHODGetFilterCriteria:AlarmManager.IAlarmFilterCriteria// see VAR_INPUT for filterGetFilterCriteria:=itfAlarmFilterCriteria;
Off course you have to add the AlarmManager to your application and add some alarms to it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am rather new to Codesys and I'm trying to figure out how to get the status of an alarm.
This to interlock the start of a device until the alarm has been acknowledged...
I am not sure if IAlarm.GetState (METH) can be used for this purpose. If yes then could someone please briefly explain how to use this?
https://content.helpme-codesys.com/en/libs/AlarmManager/4.1.0.0/Interfaces/pou-IAlarm/GetState.html
Thx & grtz,
Kris
Last edit: kris-samoy 2024-06-03
Hi,
I'm trying to accomplish the same, have you had any success?
Kristian
You are right, that you can use the GetState method, but it is not that simple. You first have to get a list of (filtered) alarms from the AlarmManager. You can find an example in Forge how to do this. See https://forge.codesys.com/prj/codesys-example/alarm-manager/home/Home/
Then you can go through this list to get the state of all the (filtered) alarms.
See below the code which you could use. This is all based on the example from forge.
Create a program:
See below some details about the function blocks:
One function block should implement the IAlarmFilterCriteria interface. This can be empty except a few methods.
The other function block should implement IAlarmManagerClient and get a reference to the FB which implements the IAlarmFilterCriteria
Off course you have to add the AlarmManager to your application and add some alarms to it.