Expression Tag Referencing Its Own Path

I’ve seen a number of threads that hit around this, but nothing that directly addresses my question.
If I have an Expression Tag in a Tag Path Folder, something like, Area01/PanelA/MotorX/Alarm, is there a way for the Alarm tag’s Expression to derive the parent path (Area01/PanelA/MotorX) it is contained in?

The ultimate goal here is to create an expression tag that will examine the folder it is in to see if any other tags are in an alarm state, and if they are the Alarm tag turns on. We don’t want to create a custom expression on each of these expression tags, but rather have a generic function that indicates an alarm in the folder. We just have too may motors to do that on an individual basis. The motor naming has already been created (by others) and is not completely consistent throughout the project. Hence it was determined to create one tag that would then be used to drive an on screen indicator for a motor to indicate if that motor was in alarm or not.

Thanks!

1 Like

For an individual expression tag outside of a UDT, I don’t think there is a way to do that. However, if you use an expression tag inside a UDT, you can get the UDT folder path, among others.

I suppose I could create a UDT with a single boolean tag. If that’s the only way to do this then that’s what I’ll do! :slight_smile:

Thanks!

You can “walk” up and down the tag path in the expression editor.

Say you have some additional tags:

Area01/PanelA/Motor1/Alarm
Area01/PanelA/Motor1/ExpressionTag
Area01/PanelA/Motor2/Alarm

If you wanted the Area01/PanelA/Motor1/ExpressionTag to reflect the value of Area01/PanelA/Motor2/Alarm the expression would be: {[.]…/Motor2/Alarm}

[.] ==> Parent Folder (Area01/PanelA/Motor1/)
…/ ==> Up one level (Area01/PanelA/)
“Motor2/Alarm” then denotes where we want to go. Put them all together!

2 Likes

What I’ll have are a number of device (OPC) boolean tags in the same folder as the expression tag (UDT with expression tag possibly). I will need to evaluate if any of the alarm tags in that folder are active. My thought was that I could use the system.alarm.queryStatus function by passing it the parent folder (path) and if the length of the Alarm Query Result is greater than 0 turn on my expression tag. That tag would then be used to animate graphics on screen.

As yet I’ve had no luck getting any of this to work.

I’m open to suggestions! :slight_smile:

Mike

If the expression tag is in the same folder, you should be able to use an expression such as:

{[.]Tag1.AlertActive}||
{[.]Tag2.AlertActive}||
{[.]Tag3.AlertActive}||
{[.]Tag4.AlertActive}||
{[.]Tag5.AlertActive}

The problem with that approach is that we will have several hundred of these folders with up to 9 boolean tags that have alarming configured. Some may not have all nine alarm tags. To do it this way would mean having to customize each expression tag for the specific tags in the folder, which would consume an enormous amount of engineering time that we simply do not have.

The hope is that we can create this one expression tag, even if it is a UDT instance, to dynamically know if the folder it is contained in has any active alarms.

The system.alarm.queryStatus method should allow that by specifying the path parameter of the method. But to do that I need to be able to get that path.

Here is a little more detail. Maybe that will help.

So we have tag folders in a structure like:
MDF/M101/
MDF/M102/
and so on...
In each of these folders there are several tags. Up to 9 of those tags have alarms configured. Those will be tags like:
MDF_101_Low_Voltage
MDF_101_Port_Error
MDF_101_Motor_Jam
MDF_101_Thermal_Error
Etc...

The display path for each alarm is configured with the tag name as part of that in order to identify the specific Motor and Alarm.
Hence all the folder tags will be different from folder to folder. With roughly 500 or so of these you can see how configuring the expression tag with the individual folder alarm tags would be a daunting task.

I'm sure it is possible to use the system.alarm.queryStatus in a fashion like this.
I have used it in the Script Console and passed it a wildcarded tag path with the required states and it works fine.
The problem I get in the UDT Expression Tag is the following:
The tag's expressing is:

if(runScript("project.MDF.alarmStatus", 0, {PathToParentFolder})=True,1,0)

The "project.MDF.alarmStatus" consists of the following:

def alarmStatus(tagFolder):
   alarmQRes = system.alarm.queryStatus(path = ["'*" + tagFolder + "*'"], state = ["ActiveUnacked", "ActiveAcked"])
   numAlarms = len(alarmQRes)
   if numAlarms > 0:
         return True
    else:
       return False

so the script takes the tag's parent folder in and should return True/False depending on if there are any Acktive alarms, whether acknowledged or not.

What I actually get is a the expression tag gets the little red square with white "x". When I look at the Tag Diagnostics for the expression tag I see this:
"Error configuring tag for execution. Error:
Syntax Error on Token: 'DIVIDE' (Line 1 , Char 47)"

The expression code looks like this:

if(runScript("project.MDF.alarmStatus", 0, {PathToParentFolder})=True,1,0)

Counting over 47 characters puts the "offending" syntax at around the "th" in PathToParentFolder.
No matter what I have tried I keep getting this same kind of error.

Any help point out where I'm going wrong and what I need to do to change this would be appreciated!
Mike

Your code samples are unreadable. Please use triple-single-backquotes above and below each section of code so it will be displayed with indents and formatting.

Did my changes correct the “unreadable” issue?

Mike

Should be simplified to:
runScript("project.MDF.alarmStatus", 0, '{PathToParentFolder}')

Note the quotes around the {PathToParentFolder}. You need to wrap the UDT instance variable in quotes because those parameters are filled in as direct string replacement before the expression evalutes; ie as you had it, the expression was literally:
if(runScript("project.MDF.alarmStatus", 0, path/to/some/folder)=True,1,0)
The syntax error on 'divide' token is the clue: it's trying to interpret path/to/some/folder as an expression to evaluate, rather than a string value to pass through to the runScript.
Also, you don't need an if statement returning true/false if your script already does.

4 Likes