Very late but I was able to figure this out in one way and failed in another.
Based on a tag being High priority the value source will change to opc. This works fine.
I failed on trying to change the alarm priority correctly, but none the other 99% of this code works.
EDIT: I got it to work on alarms only if the alarm was put on the UDT itself and not directly put on the tag.
This uses two function to either change an alarm priority or setpoint value base on what the user does with the view's components. I used random condition logic that can be altered as needed.
Components are:
• two radio buttons(one for each function call) • Numeric field(to set a new setpoint value), three labels(labels the differences between components), and • one text field(To grab teh folder we want to start in)
Here is my full code:
# Setpoint change function
def changeSetPoint(UDTPath, tagPath, tag, alarm, newSetpoint = 0):
"""
• UDTPath = The UDT instance; used as the path to update the configs for each tag
• tagPath = The tags full path from folder to indivudal tag
• tag = The tag that is being iterated through on the Nth loop
• alarm = The current tags alarm info
• newSetpoint = Setpoint value: if nothing is set will make it 0
"""
# get a list of alarm names so we can access each tag individually
alarName = str(alarm['name'])
priority = str(system.tag.readBlocking(alarms + alarName + ".Priority")[0].value)
tagName = str(tag['name'])
system.perspective.print("The UDTPath is: %s" % (UDTPath))
try:
system.perspective.print("The current Set point value is: " + str(alarm['setpointA']))
except:
system.perspective.print("This tag has an alarm setpoint to 0 or none at all")
if priority == 'High':
# EXAMPLE ONLY----------------------------------------------
# do something here based on tag alarm being on high
# before set point change
system.perspective.print("Tag full TAG path is: " + str(tagPath))
system.perspective.print("Tag %s with alarm named %s with the OLD setpointA value" % (tagName, alarName))
try:
system.perspective.print("Old setpoint value: " + str(alarm['setpointA']))
except:
system.perspective.print("This tag has an alarm setpoint to 0 or none at all")
system.perspective.print("This tags priority is " + str(priority) + "\n")
alarm['setpointA'] = newSetpoint
system.tag.configure(UDTPath, tag, 'o')
system.perspective.print("BEFORE-------------------------AFTER\n")
# after setpoint change
system.perspective.print(str(tagPath))
system.perspective.print("Tag %s with alarm named %s with the NEW setpointA value" % (tagName, alarName))
system.perspective.print("New setpoint value: " + str(alarm['setpointA']))
system.perspective.print("This tags priority is " + str(priority))
return system.perspective.print("Process of updating tag %s's SETPOINT is completed.\n" % (tagName))
# Function 2: Change alarm priorty
def changeAlarmPriority(UDTPath, tagPath, tag, alarm, newPriority):
"""
• UDTPath = The UDT instance; used as the path to update the configs for each tag
• tagPath = The tags full path from folder to indivudal tag
• tag = The tag that is being iterated through on the Nth loop
• alarm = The current tags alarm info
• priority = the priority that we are changing to
"""
# get a list of alarm names so we can access each tag individually
alarName = str(alarm['name'])
priority = str(system.tag.readBlocking(alarms + alarName + ".Priority")[0].value)
tagName = str(tag['name'])
# do something here based on tag alarm being on high
system.perspective.print("The UDTPath is: %s" % (UDTPath))
system.perspective.print("Tag full TAG path is: %s" % (tagPath))
system.perspective.print("Tag %s with alarm named %s with the OLD Alarm priority which is: %s \n" % (tagName, alarName, priority))
# change this property
alarm['priority'] = newAlarmPriority
system.tag.configure(UDTPath, tag, 'o')
newPriority = str(system.tag.readBlocking(alarms + alarName + ".Priority")[0].value)
system.perspective.print("BEFORE-------------------------AFTER\n")
system.perspective.print("The UDTPath is: %s" % (UDTPath))
system.perspective.print("Tag full TAG path is: " + str(tagPath))
system.perspective.print("Tag %s with alarm named %s with the NEW Alarm priority which is: %s" % (tagName, alarName, newPriority))
return system.perspective.print("Process of updating tag %s's PRIORITY is completed.\n" % (tagName))
# main folder
MainTagFolder = str(self.getSibling("folderPath").props.text)
# goes through each folder until the type is UDTtype/UdtInstance/AtomicTag/folder based on what we need/put here
getTagPaths = system.tag.browse(MainTagFolder, filter = {"tagType": "AtomicTag","recursive":True}) # "tagType": "AtomicTag",,UdtType, AtomicTag, UdtInstance, folder
# to update the tag I needed the UDTinstance path for the group of tags that will be looked at. This is how I get that.
# DO NOT DO THIS TO MANY FOR LOOPS
# UDTPath = system.tag.browse(MainTagFolder, filter = {"tagType": "UdtInstance", "recursive":True})[0]['fullPath']
for tags in getTagPaths:
# grab full path of all folder/UDTs/AtomicTags whwavter we are looking into above
if str(tags['tagType']) == "AtomicTag":
tagPath = str(tags['fullPath'])
UDTPath = tagPath.replace("/"+str(tags['name']), "")
## another way to grab alarm property info, there seems to be at least two way to get different info.
## E.G: Alarms and value need this way, but tagType can be used like a key in a dict tag['tagType']
# # get our alarm path
alarms = "%s/Alarms/" % (tagPath)
# get the configs of each tag instance
configs = system.tag.getConfiguration(tagPath, True)
#If we get a UDT insatnce this part will need to look like this to go further into the dict/json
# for tag in configs[0]['tags']:
userSelectedChoice = self.getSibling("UserChoice").props.index
for tag in configs:
# check for user chaoice and run that function based on that. uses compoent index
if userSelectedChoice == 1:
# get our set point value based on compoent input
setpointValue = int(self.getSibling("SetPointValue").props.value)
try:
for alarm in tag['alarms']:
changeSetPoint(UDTPath, tagPath, tag, alarm, newSetpoint = setpointValue)
except:
pass
else:
try:
for alarm in tag['alarms']:
newAlarmPriority = str(self.getSibling("AlarmPriority").props.value)
changeAlarmPriority(UDTPath, tagPath, tag, alarm, newAlarmPriority)
except:
pass