Ignition Version 8.1.44
Vision Module
I have this script that if I setup the tags outside of a UDT works great. But when I attempt to run it from inside the UDT it just does not work. I am assuming there is some hidden thing about UDTs that I do not understand. What is supposed to happen is that the tag the script is attached to becomes true, pulls the fault code from another tag, writes to two other tags, then creates an alarm on the original tag that is executing the script.
def _findFault(ds, code):
try:
rows = ds.getRowCount()
for r in range(rows):
try:
ds_code = int(ds.getValueAt(r, 0))
except:
continue
if ds_code == int(code):
return (str(ds.getValueAt(r, 1)), str(ds.getValueAt(r, 2)))
except:
pass
return ("Unknown Fault ({0})".format(code), "No documented solution.")
def _ensureAlarmOnIsFaulted(abs_isfaulted_path, label_text, message_text):
try:
changes = {
"DriveFaultActive": [
["enabled", "Value", True],
["priority", "Value", "High"],
["mode", "Value", "Equality"],
["setpointA", "Value", 1],
["label", "Value", label_text],
["message", "Value", message_text],
]
}
system.tag.configure([abs_isfaulted_path], changes)
except:
pass
# --- Tag Change Entry Point ---
try:
if initialChange:
return
newVal = bool(currentValue.value)
oldVal = bool(previousValue.value)
isFaultedPath = str(tagPath)
lastCodePath = "[.]Last Fault Code"
descPath = "[.]Fault Description"
solnPath = "[.]Fault Solution"
datasetTagPath = "[~]Assets/Fault Data/Drives/PowerFlex/PowerFlex 753 Faults"
if newVal:
code_qv, ds_qv = system.tag.readBlocking([lastCodePath, datasetTagPath])
fault_code = code_qv.value
desc, soln = _findFault(ds_qv.value, fault_code)
system.tag.writeBlocking([descPath, solnPath], [desc, soln])
label = "F-{0} {1}".format(fault_code, desc)
message = "Fault {0}: {1}\nSolution: {2}".format(fault_code, desc, soln)
_ensureAlarmOnIsFaulted(isFaultedPath, label, message)
elif (not newVal) and oldVal:
system.tag.writeBlocking([descPath, solnPath], ["", ""])
except:
pass
Update:
Based on feedback from the comments and some more thinking I figured out a solution that works much better.
Instead I am just searching through the dataset tag and assigning values to the Fault Desc and Fault Sol tags. Then I have a set alarm that uses the Fault Desc for the Label and isFaulted for the On Condition of the alarm. Thanks everyone.