Link State of Pump

Hi All,

I’m new to Perspective.
I’m trying to link running, stopped and faulted of a pump to my tags (running, stopped and tripped).
Can someone please advise.
Thanks
pump

1 Like

Have you tried linking it to a tag and using a map transform?

I’m assuming you have those 3 tags as booleans, and there will always be one and only one true.
You could bind the state property to an expression structure, and add a little script:

This is probably doable with expressions, but I don’t like them.
I can explain how this works in more details if you’re not familiar with all of this, just let me know.

Another way you could consider if you need the same logic in other places of your project, would be to create a new tag containing the current state, then use a tag binding on the state property of the pump and add a map transform.

There are many ways to skin this cat. If it's a single tag, I'd echo @rourksb's recommendation of a map transform - it's simple to set up and easy to change later. If you have multiple tags, you could use @pascal.fragnoud's suggestion, though I'd simplify to two elements:

  1. A single expression bringing in the value of the tags and (assuming they're mutually exclusive) use binEnum to translate it to a single numeric value
  2. A map transform, just like the first suggestion. (You could do the entire thing using a single expression, but IMO a pair of transforms is the most readable and maintainable in the future).

Sidebar: This is perfectly reasonable if you're more comfortable with scripting, just be aware you're leaving performance on the table. Jython compilation can be a significant bottleneck; the more script transforms you're using the more that can pile up. For a simple task like this I'd strongly recommend an expression based solution.

1 Like

Yes, I try to use expressions where I can figure out quickly how to do what I want. But if it doesn’t work after a few tries, I’ll just switch to scripting.
To be perfectly honest, it’s not the expressions I don’t like, it’s the doc. More often than not, I find myself confused after reading the doc, or not sure where to go next to find the information I need.
On the other hand, python, even if it’s Jython is quite well documented.
For example, I gave expressions a shot for this case. BinEnum is exactly what I would have wanted to find, but… It’s not like the name speaks for itself, and there’s not much pointing in its direction for the case at hands.

1 Like

Thanks for all the help gents.
I came right using the map transform but will try the other methods as well.

Could you use expressions here to map multiple tags to the same prop?

i.e. I have one tag that checks if the pump is running but another tag that indicates if it is faulted

Follow what @PGriffith described above using binEnum.

1 Like

Yes. If the tags aren't mutually exclusive then use binEnc.

  • Create an expression structure binding on the symbol. Add in the paths to the two tags.
  • Add an expression transform.

Code:

//pumpRunning   pumpFaulted   Result
//          0             0   00 = 0
//          1             0   01 = 1
//          0             1   10 = 2
//          1             1   11 = 3
binEnc({value}['pumpRunning'], {value}['pumpFaulted'])

https://docs.inductiveautomation.com/display/DOC81/binEnc

1 Like

This worked, thank you!

Thanks for the reply. I ended up having to use binEnc because I have 1 tag for 'running' and 'stopped' and another tag for 'faulted' so the 3 values are not mutually exclusive.

1 Like