Dynamically disable a folder of tags in a UDT

I have a UDT that I use to monitor Allen-Bradley Logix PLC’s, and display status information on a diagnostics page. Within this UDT, I have a folder called “Clock”, which relates to a timekeeping AOI within the PLC. In every PLC I have access to, I add this AOI so that I have a common timekeeping structure.

But there are some PLC’s I don’t have access to, so those ones don’t have the Clock AOI. Ideally, I’d like to disable (or remove entirely) all the tags in the Clock folder if I don’t specify a path to the Clock AOI within the PLC. I can easily create an expression that returns true or false based on the presence or absence of that AOI, but I want a nice neat way of handling the tags in the clock folder so I don’t have them repeatedly trying to poll an address that will never exist.

I’ve considered binding the enable for each tag in the clock folder to something, but:

  • You can’t use an expression binding on the enable property
  • You can’t use a tag binding on the enable property
  • You CAN bind to a UDT parameter, but the enable parameter is a boolean, and you can’t create boolean UDT parameters
    I’ve considered having two UDT’s, one with the Clock folder and one without, but I’d prefer to do this all in the one UDT if I can.

I’ve considered having the PLC and the Clock be separate UDT’s, and just putting either one or both in an instance folder according to whether or not they have the AOI, but that leads to more complexity in managing the different instances and linking information between the two UDT’s.

Any other creative ideas?

My UDT knowledge is weak, but could you use system.tag.configure for this?
This is right out of the manual minus comments.

parentPath = "[NewProvider]SomeFolder"
configs = system.tag.getConfiguration(parentPath + "/AnotherFolder", True)
 
for tag in configs[0]['tags']:
    if str(tag['tagType']) != 'Folder':
        tag['enabled'] = False
 
system.tag.configure(parentPath, configs, "o")
1 Like

That’s exactly the sort of function I was looking for! Thanks a heap, I’ll see if I can manipulate that into something that does what I want and post back.

1 Like

Finally got back to this. So, the approach above worked, with a couple of important things to note for people reading this in the future:

The approach above gets the tag configuration for all tags in the specified folder, modifies it by setting all the “enabled” parameters to false, then writes that modified configuration back to the tags in the folder. The path to READ the tag configuration is not the same as the path to WRITE the configuration. That is, when you read the tag config, you specify the folder that all the tags are in. When you write the tag config, you specify the parent folder of the folder your tags are in.

All memory and OPC tags in the folder now show quality Bad_Disabled, but expression tags that reference those memory/OPC tags show Error_ExpressionEval, not Bad_Disabled, despite the fact that they too are disabled and shouldn’t be trying to evaluate an expression. Not a show stopper, but somewhat odd.

So the complete solution for posterity is:

  1. A UDT parameter called Clock AOI Tag
  2. A folder at the base level of the UDT called Clock, housing all the tags I want to disable if a Clock AOI is not used
  3. An expression tag called ClockEnabled at the base level of the UDT, which uses the following expression:
if(isNull({Clock AOI Tag}) || {Clock AOI Tag} = '', false, true)
  1. A tag event script (value changed) on that expression tag as follows:
if currentValue.quality.isGood():
    basePath = '[.]'
    tagConfig = system.tag.getConfiguration(basePath + '/Clock', True)
    for tag in tagConfig[0]['tags']:
        if str(tag['tagType']) != 'Folder':
            tag['enabled'] = currentValue.value
    system.tag.configure(basePath, tagConfig, 'o')