Sound Player Optimization

I am working on getting 2 different sound players to play when a certain value is passed. right now, to pull this value, I need to reference 100 different tags to see if any of those tags have a certain value, if they do, pass one value, if not, pass another. I was thinking to use an expression tag, but not sure how to do wildcards inside of a tag path or if that is even possible. Any thoughts?

Not sure it's the best way, but I'd use system.tag.browse to get a tag list, then read the result with system.tag.readBlocking, then use a for tags in tagvalues type loop to find a true value.

I assume that you already know the tag paths of these, and given that you are wanting to use wild cards, that suggests that they have similar enough paths that they can be enumerated.

A few vialble options that I see.

  1. Use a vision client tag change event. This would run in each client independently, and can reference vision client tags.
  2. Use a timer to run a script which examines the list of tags to determine if any of their values match.
  3. If you can, perhpas Phil’s Integration Toolkit Module would allow you to do this work in a couple of expressions with the iterators provided by that module. Maybe not, though, as I would suspect that Phil has already read this and didn’t have any suggestions.

FWIW, I’m thinking of a script something like:

parentPath = '[default]someParentPath'
folder = 'someSharedFolder'
readPaths = ['tagPath1','tagPath2',...,'tagPath100']
paths = ['{}/{}/{}'.format(parentPath,folder1,tagPath) for tagPath in readPaths]

for qv in system.tag.readBlocking(paths):
    if qv.value == 'yourTriggerValue':
        #trigger sound player
        return 'value to play sound'

Ideally the list of paths would be written as a top level variable in a project library script so it is only processed once. Then the for loop would be in a project library function, Say

def checkForAlarm(): Then where you want to call, this script you would simply just call that function returning the value to play the sound.

I've been using system.tag.query for requirements like this, which can return values & desired properties of all tags matched for quick comparison thereafter (via any(…) or all(…), etc ). Script can be generated using Tag Report Tool.

The wildcards put me off. If the tag list is constant, my tags() function plus some iteration would handle this.

1 Like

Thank you all for your replies, wasn’t expecting anything over the weekend. I am working on trying to make it into a project library script, but I can’t figure out a couple issues. I got the script working and I have it in a client timer event right now. I would prefer it to be on a tag change event, but do I need to manually insert all 100 tags in the tag change tag paths, or is there a way to include wildcards and or iteration, or even a scripting variable in that window?

Gateway tag change events allow wildcards at the folder level when defining tags to monitor. You can always do further filtering in your actual script to only run logic when the wanted tags change.

2 Likes

If your list of tags will never change, it might be best to hard-code them. If this list will change in future, make the tag paths more dynamic.

Can you share an example of a few of your tag paths? What kind of wildcard search do you believe would capture only the desired tags?

2 Likes