In this example I’m going to use a tag that will control digital output 1 and the tag will be called digital output
Here’s the code I wrote that will check and see if any tag is in an alarm state. Make sure to put this in the Init section and not the cyclic section. Right now it’s setup to run every 60 seconds from timer 1
Tset 1, 60 // will run through this code every 60 seconds
Ontimer 1, “Goto check_alarm”
check_alarm:
counter% = 0 //initializes the counter to 0
alarm% = 0 // Initializes the alarm state
n% = GETSYS PRG,“NBTAGS” //gets the current number of tags you have created
For i%=0 To n%-1 //creates a for loop that will run through every tag you’ve created
SETSYS TAG, “LOAD”, -i% //loads the system info for each tag
counter% = Alstat i%
If counter% = 2 Or 3 Or 4 Then //these are for active alarms or unacknowledged alarms
alarm% = alarm% + counter% //will raise the value of the alarm variable past 0 if any tag is in alarm
Endif
If alarm% > 0 Then
digital_output@ = 0 //if any alarm is active then the output will go to 0
Endif
If alarm% = 0 Then
digital_output@ = 1 // if no alarms are active, the output will stay high
Endif
Next i% //goes to the next tag in the loop
End