I am working on some alarming in perspective. I have a tag provider setup to hold my tags that I would like to create alarms on. I have added my tags to the tag browser via the OPC browse device feature.
I would like to create alarms on specific tag structures. Something along the lines of if the tag names tags this, add this type of alarm.
I started scripting this as I need to do it for lots of these guys. I noticed that the alarm would not create on the tag.
The script I have so far is below. It does not apply the alarm to the tag when I check in the tag browser, I can manually apply the alarm no problem...
def addAlarmToSpecificTag():
"""
Adds a basic alarm to the tag target tag
"""
tagName = "[Alarming]Test/ER200_LIT21_TEST/bHAlm" # The tag we want to update
try:
# Get the current tag configuration, including alarms
tagConfig = system.tag.getConfiguration(tagName, True)
# Define the alarm name and configuration
alarmName = "ER200_LIT21 TEST"
alarms = [
{
"name": alarmName,
"mode": "AboveValue",
"setpointA": 1.0
}
]
# Ensure alarms exist in the tag configuration
if 'alarms' not in tagConfig[0]:
tagConfig[0]['alarms'] = []
# Add the alarm to the list of alarms (or replace if needed)
tagConfig[0]["alarms"].append({
"name": alarmName,
"mode": "AboveValue",
"setpointA": 1.0
})
# config tag with the modified alarm settings
system.tag.configure(tagName, tagConfig, overwrite=True)
# Check
updatedTagConfig = system.tag.getConfiguration(tagName, True)
print("Updated configuration for tag " + tagName + ": " + str(updatedTagConfig))
except Exception as e:
print("Error configuring alarm for tag " + tagName + ": " + str(e))
addAlarmToSpecificTag()
I based the structure for this off the system.tag.configure
system.tag.configure