Timer Script for Active Alarms

I am using Ignition version 8.1.3 and Vision.

The customer wants Ignition to tell the PLC if there are alarms active so that a buzzer/horn will sound when there are active alarms. A discussion with a coworker produced the following script:

#tag.quality needs to be "Good" or else the value cannot be trusted
#tag.value is the 'value' you would proceed to use, if the .quality was found to be "Good"

#logger = system.util.getLogger("MiscDebug")
#logger.info("Misc -Start-")

tagPath = "[Modicon]HR1005.2" #Flat Robot E Stop
tagPath2 = "[Modicon]HR1005.3" #Vial Robot E Stop
tagPath3 = "[Modicon]HR1005.4" #PB2519 E Stop
tagPath4 = "[Modicon]HR1005.5" #PB2520 E Stop
tagPath5 = "[Modicon]HR1005.6" #PB2521 E Stop
tagPath6 = "[Modicon]HR1005.7" #PB2522 E Stop
tagPath7 = "[Modicon]HR1005.8" #PB2532 E Stop
tagPath8 = "[Modicon]HR1005.9" #PB2533 E Stop
tagPath9 = "[Modicon]HR1005.10" #PB2534 E Stop
tagPath10 = "[Modicon]HR1005.11" #PB2535 E Stop
tagPath11 = "[Modicon]HR1005.12" #PB2536 E Stop
tagPath12 = "[Modicon]HR1000.8" #Label Printer Fault
tagPath13 = "[Modicon]HR1000.9" #Label Printer Out of Ink
tagPath14 = "[Modicon]HR1004.9" #Safety Enabled
tagPath15 = "[Modicon]HR1004.3" #Tray with No ID
tagPath16 = "[Modicon]HR1005.0" #HMI Alarm Present (Tells PLC there is an alarm)

#read tag
readTag = system.tag.readBlocking(tagpath)

if str(readTag.quality) == "Good":

	tagValue = readTag.value
	#logger.info("tagValue : " + str(tagValue))
	
	if tagValue: #if true or non-zero
	
		#update value to be written to tagPath16
		result = true
	
		#write tag
		system.tag.writeBlocking("[Modicon]HR1005.0", 1)
	
	else:
		#update value to be written to tagPath16
		result = false
		
		#write tag
		system.tag.writeBlocking("[Modicon]HR1005.0", 0)
		
#logger.info("Misc -Done-")

I’ve tried it as a Gateway Timer Script and a Client Timer Script. Both set to run every 1,000 ms or 1 second. We make an alarm go off and nothing happens as far as the audible for alarms being active.
My questions are
A) should this be in the gateway or the client?
B) what is wrong with the code or what code should I be using?

A) Gateway for sure. If in the client, and no client is running, your code won’t run. If you have multiple clients running, they’ll all be running this code and hammering the PLC.

B) You are mis-using readBlocking. It takes a list of tagPaths and returns a list of QualifiedValue results.

Instead of using readBlocking, what should I be using?

You’re using the correct function, you are just not using it correctly.

tagQVs = system.tag.readBlocking(['tagPath','tagPath1','tagPath2'])

for tagValue in tagQVs:
    print tagValue.value

NOTE: I used generic strings to represent the tag paths, this code will not function.

1 Like

Ok. Do I insert this at my readBlocking point and put in each tagpath where you used generic strings for tag paths?

Do I need all the stuff in my code about the quality being "good"?

I don't see any documentation on "tagQVs" could you elaborate please?

You can do this, or you can build a list and supply that to the functioin.

That is dependent upon your specific use case. If you care that you only do something when a tag's quality is good then leave it.

tagQVs is just a vairiable. I name my variables base on the type or types that it holds, in this case a list of Qualified Values.

1 Like

Can I use the list I've already created by modifying it somehow or do I need another list?

Okay, so I would recommend that you do some research into python, there are several great resources out there for that.

Technically speaking you haven't created a list (even though it may look that way) instead you have created several variables holding string values.

In python a 'list' is a type of data sequence denoted by surrounding comma separated values with square brackets [ ].

For instance a list of integers could be [1,2,3,4].

In my code I created a list inline by surrounding the strings with [ ]. You could also create the list separately and hold it in a variable.

 tagPaths = ["[Modicon]HR1005.2","[Modicon]HR1005.3","[Modicon]HR1005.4","[Modicon]HR1005.5" , "[Modicon]HR1005.6","[Modicon]HR1005.7","[Modicon]HR1005.8","[Modicon]HR1005.9","[Modicon]HR1005.10","[Modicon]HR1005.11","[Modicon]HR1005.12", "[Modicon]HR1000.8","[Modicon]HR1000.9","[Modicon]HR1004.9", "[Modicon]HR1004.3","[Modicon]HR1005.0"]

tagQVs = system.tag.readBlocking(tagPaths) #NOTE the missing [], because tagPaths is already a list

Alternatively you can also use the append function of the list to add elements

tagPaths = []
tagPaths.append('New Tag Path')

Again, I would highly recommend that you work on getting a better understanding of python. Not only will it help you in writing the code but also in understanding replies to questions on the forum. Because despite our best efforts our answers can be somewhat cryptic to the uninitiated. :wink:

Here's a good post on where to hone your skills, also I can't recommend Inductive University enough.

1 Like