I have a Gateway Tag Change script that seems not to finish. I know it starts, but it seems to fail when calling a project script in a the Script Library that does some recursive browseTags. My intent is have this script called on gateway startup, and I know it works because I’ve run the code in the Script Console and it works.
I’m really stumped … here’s some cut-n-paste:
–Tag Change–
def AddTags(path, udttype, data):
#get all the tags that have the given UDT type under the given path
tagList = project.alarmlist.manualSearch(path, udttype)
# strip of the last part of the tag path and make that the alarm name
# the first part then becomes the path
for tag in tagList:
lastDel = tag.path.rfind("/")
strLen = len(tag.path)
alarmName = tag.path[lastDel+1:strLen]
path = tag.path[0:lastDel]
row = [path,alarmName,'default','color(255,255,255,255)','color(0,0,0,255)','','','','default','color(250,214,138,255)','color(0,0,0,255)','','',udttype]
data.append(row)
logger = system.util.getLogger("alarmlist")
if newValue.value:
data = [] # create an empty list to fill with tag paths
logger.info("Start Alarm Tag Refresh")
system.tag.writeSynchronous('GUI/Test','Starting')
AddTags("[default]/.","DigitalAlarm",data)
logger.info("DigitalAlarm Tag Refresh Complete")
AddTags("[default]/.","AnalogAlarm",data)
logger.info("AnalogAlarm Tag Refresh Complete")
AddTags("[default]/.","AnalogLockoutAlarm",data)
logger.info("AnalogLockoutAlarm Tag Refresh Complete")
almDataSet = system.tag.read('GUI/Alarm Tags')
headers = system.dataset.getColumnHeaders(almDataSet.value)
dataset = system.dataset.toDataSet(headers, data)
system.tag.writeSynchronous('GUI/Alarm Tags',dataset)
logger.info("Tag Refresh Complete")
system.tag.writeSynchronous('GUI/Alarm Tag Refresh',0)
system.tag.writeSynchronous('GUI/Test','Complete')
else:
system.tag.writeSynchronous('GUI/Test','Nothing Done')
– Script Library –
# Define the search as a function. This makes recursion easier.
def manualSearch(initPath, alarmType):
# Create a result set of just tags.
tagSet = system.tag.browseTags(parentPath = initPath, tagPath = '*', udtParentType=alarmType, recursive=False)
# Create a result set of UDT instances.
udtSet = system.tag.browseTags(parentPath = initPath, tagPath = '*', tagType='UDT_INST', recursive=False)
# Create a result set of just folders. We'll iterate over this set and call browseTags() again for the results.
folderSet = system.tag.browseTags(parentPath = initPath, tagPath = '*', tagType = 'Folder', recursive=False)
# Iterate through folders...
for folder in folderSet:
# Recursively start the process over again until we run out of folders.
tagSet+=manualSearch(folder.fullPath,alarmType)
# Iterate through UDT's ...
for udt in udtSet:
# Recursively start the process over again until we run out of folders.
tagSet+=manualSearch(udt.fullPath,alarmType)
# Return the list of tags.
return tagSet