How to create an alarm popup that will appear when an alarm is triggered

Hi all,

I am trying to figure out how to get a popup to open once an alarm is triggered. Then I will need to have that alarm message be read in the popup. Any help would be greatly appreciated as I am new to ignition.

Thanks,

Alex

I have a test alarm made for an OPC tag. I also have a popup window made too. So I need to know how to get the popup to show as soon as the alarm tag is a 1 (active) and show said alarm in the popup.

You will need to monitor for changes to active alarms yourself for using system.alarm.queryStatus

E. G.
Define a new script library with this, and call this function within a gateway timer script which increments a memory tag. Then in a client tag change script, monitor this tag for changes and open your popup using system.gui.openPopup.

See script in future post

Is there a way I can do that in Vision or does it have to be only the project library? Also do you know of any sources or examples to make a client timer script? Never made one before so I am confused on how it all comes together.

Or do you have any sudo code you could give me for this action?

You should have a look at the Inductive University as it covers all areas of using Ignition.

The reason to use a gateway script to run the system.alarm.queryStatus function is to avoid executing this too often as it’s expensive in terms of CPU time.

Script Library

This needs to be defined in the project that’s set as the gateway scripting project. This is the project that any gateway-scoped scripts use (gateway timer scripts) This can be found under:
http://<gateway ip>:8088/web/config/system.settings

image

The gateway script itself should be created here:
image
e.g. under shared.alarms

This is the script:

# define in shared.alarms

alarms_prev_ds = None
alarms_ds = None

def checkNewAlarm():
	global alarms_ds, alarms_prev_ds
	alarms_prev_ds = alarms_ds
	alarms_ds = system.alarm.queryStatus(state=['ActiveUnacked']).dataset
	
	# check if the function has been called before and has therefore set alarms_prev_ds, if not, then return true if there are any active alarms 
	if alarms_prev_ds is None:
		if alarms_ds.rowCount > 0:
			return True
		else:
			return False
	
	# else if the previous dataset isn't None, compare the two to check for differences
	else:
		# get a `set` of EventIds from both the previous and current alarm datasets so that we can easily find the differences
		alarms_prev_ids = set([alarms_prev_ds.getValueAt(row, 'EventId') for row in range(alarms_prev_ds.rowCount)])
		alarms_ids = set([alarms_ds.getValueAt(row, 'EventId') for row in range(alarms_ds.rowCount)])
		
		# use the difference of sets to find if there are any new alarms in the current alarms dataset
		alarms_new_ids = alarms_ids - alarms_prev_ids
		
		if len(alarms_new_ids) > 0:
			return True
		else:
			return False	
Tag to toggle when new alarms are active

This tag will toggle value when there is a new alarm that’s become active. It should be a simple boolean memory tag. I’ve simply put it in the root of the tags folder and called it “New Alarms Active”. If you move it, you’ll also need to update the scripts where it’s used.

Gateway Timer Script

The gateway timer script will call the script above in order to toggle the value of the tag that we will use to show that there is a new alarm by when it changes value.

Define this in here:
image
image

The actual script:

print 'Checking for new alarms...'
newAlarms = shared.alarms.checkNewAlarm()

if newAlarms:
	print '  New alarm(s) found! Toggling value of tag.'
	tagPath = '[default]New Alarms Active'
	valOld = system.tag.readBlocking([tagPath])[0].value
	system.tag.writeAsync([tagPath], [not valOld])
Client Tag Change Script

Sorry, I said to create a client timer script earlier, I meant to say Client Tag Change script.
This will monitor the tag we’re using above for changes, and if there is a change then there is a new alarm and we will use this script to open the popup to show the alarm(s).

This should be defined in the project that you run a client for (which may be the same if you’ve only got one project, although having at least one inherited project to store your library of standard graphics/scripts/templates/etc. is recommended).
This should be defined in the project that you run a client for (which may be the same if you’ve only got one project, although having at least one inherited project to store your library of standard graphics/scripts/templates/etc. is recommended).
Define this here:
image

For example:
image

image

Ok, I’ve updated my previous post, hopefully it makes a little bit of sense… let me know

Thanks mate! I’ll give it a try