Update a property when a tag changes

Hello everyone!

I have a template that show two labels depending on a value. If the value is 1, the label1 is shown and the other one is hidden, in contrast, when is 2, the label2 is shown and label1 is hidden. To do it, I am using the runScript function in the bindings in the labels’ visible property to read a bit of the tag.

That works but only when the window is shown at the first time, after that, if the value changes, nothing more happen. So, is there any way to update the value of the visible property to show or hid “online” depending on the tag value?.

Thanks a lot.

If I’m understanding you correctly, you’re over complicating things :slight_smile:

Click on the label you want to make visible, in the Property Editor Pane find the entry labeled “Visible” and click on the Binding icon.

Select the “Expression” Binding type and enter the expression to make the label visible when your tag or property is 1 for Label 1.

For example, assuming that Value is a custom property on your template

{Root Container.Value} = 1

Then repeat for label two and change it to

{Root Container.Value} = 2

Thanks abushur.

It should be easy but it is taking me more time than I expected :laughing: .

Your solution is the easiest, in my case, label 1 or 2 depend on a bit of a tag. To read specific bits in a tag, I am using a python function that return the value of a bit from a tag path. So, in order to evaluate the visible propertys I use an expression binding:

if(runScript("shared.utils.bitReadTag('"+{param1}+"/"+"ACT"+{param2}+"',1)") > 0,True,False)

If the code is correct (I think so because it works the first time), my function is returning the bit value and the if condition evaluates it. But only one time, when the window is loaded.

Any idea to solve it?

Thanks a lot!

Ah, I see I’ve done something very similar to what you’re doing.

In my case, I broke it down into 2 separate parts.

First I created a custom variable (let’s just call it test for simplicity) that I used indirect tagging to get the variable of the integer I wanted to read i.e.


Then I substituted the param1 custom property in for ref#1 and param2 for ref#2.

Then on the visible property I used the following code

if(getBit({Root Container.test},1),True,False)

This will make it visible whenever bit 1 is 1 and invisible when bit 1 is 0

(Side note, I know that’s not really what you’re asking for per se, but that’s as far as my knowledge takes me right now for a viable workaround, sorry)

Okay, I worked it out!

When using the runScript function you need to specify a poll rate in milliseconds otherwise it only executes once.

Modify your code like this and it should work

if(runScript("shared.utils.bitReadTag('"+{param1}+"/"+"ACT"+{param2}+"',1)",1000) > 0,True,False)

That assumes a 1 second poll rate

I tested it by creating a shared library named util and adding the following function to it

def bitReadTag(tagToRead, bitLocation): rootValue = system.tag.read(tagToRead) bitValue= (rootValue.value >> bitLocation & 1) return bitValue

and called it with this bit of code

if(runScript("shared.utils.bitReadTag('"+{Root Container.param1}+"/"+{Root Container.param2}+"',2)",1000),True,False)

(For my testing purposes Param1 was the tag folder name and param2 was the tag in the folder to read)

Superb! The key was the poll rate, using 1s as you said it works properly.

I find out lot of new things about Ignition every day! :smiley:

Thank you very much abishur :prayer: :prayer:

No problem, thank you for helping me learn about the runScript and shared libraries :smiley: