Active Alarms to CSV

Hello all,

I am trying to run a script that I have tried to implement in the Gateway Tag change, property change on a component, and more…
The script is below:

from __future__ import with_statement
import csv, time, os
faultOccured = system.tag.read("Interface/NavigationBarTags/statusScannerIndicator").value
if(faultOccured==2 or faultOccured==3):
	with open("C:\Users\USER\Documents\HMI_Alarms\HMI_Alarms.csv", "a") as cosv:
		alarmTest=system.alarm.queryStatus(state=["ActiveUnacked"])
		t = time.localtime()
		timestamp = time.strftime('%b-%d-%H:%M:%S ', t)
		strAlarm="Reported Time: " + timestamp + alarmTest.toString()+"\n"
	
		csv_f = csv.writer(cosv)
		cosv.write(strAlarm)

I do not know why, but it will not run the script on anything but the Script Console. Perhaps the from future import with_statement does not work with the rest of Ignition? I’m not sure.

If I run it on the script console, it runs appropriately… It allows me to apend a .csv with the active alarm status.

Any idea on why this only works on the script console, and if this is the case, an alternative way to have the same functionality?

You could move your code to the Script Library and call it from a Gateway Event Script. I just tested with 7.9.6 and this works for me.

Does your gateway service account have access to that folder?

And look in your gateway logs – there should be messages for the errors generated in the script.