How to write component value generated by expression into a memory tag


I have a label in which there is an expression. I want to write the value of this into a tag on a fixed rate. How do I do these practically?


idk if its the best methode, but this works:

add it in a struct expression, which has a time expression (now(5000) is every 5 sec )in it aswell.
and then add in a transform script which writes it to the tag and returns your expression again

edit: tho i guess it will also trigger if the expressionvalue changes, you’ll have to add in some more scripting for that then i guess if thats not what you want

Generally, if you need something like this, you don’t do it in the user interface. In the UI, it will run for each client looking at that view, and not run at all if no-one is looking at that view.

If it needs to run all the time, use an expression tag instead of a memory tag, and place your expression in the tag itself. Set the tag to be a member of a tag group that has the rate you desire.

1 Like


I would use the expression on the tag itself but the problem is this expression getting some values from other components. As far as I know tag expression dont read component values. I think I need a script that run on gateway on a fixed rate without anybody opening or pressing something. But how do I reach to a scpecific view and specific component in that view inside gateway event script? Have never done gateway scripting before.


Thanks, tried it now it worked on value changedexactly what I want

1 Like

The solution to use a script and tag write isn’t great imo, definitely with phil on this one. It sounds like you’re going about this the wrong way.

Back up a bit, what is the expression on your label?
Where are the values coming from on the components you’re using in your label binding? And how do they get their values?
What is the end goal?

1 Like

Correct, they don’t. But if they are input components, bind their values to memory tags. The expression tag can use those in its calculation instead. And the memory tags will hold those values for use when no client has that view open.

If those components have computed values, then make them expression tags, too.

If extra expression tags makes it too convoluted, you could use a gateway timer script to collect all necessary raw values, run all exotic calculations in jython form, and write the result to a memory tag.

So the expression is a calculation and it uses other component values in this calculation. Some of those used component values also have expression in them. Basically the structure I made for this one is mostly component values and expressions. That is why I could not put this expression on the expression tag because there are other component values inside. The result of the calculation I need to send it to PLC that is why I need it on tag level now. Yeah thinking now I would have make those expressions on tag level not on components but could not predict this.

Right now I made a transform script on the component it writes the value on a tag like victordcq suggested. Why do you think it is a bad way what could go wrong?

Thanks for the inputs

Because you’re putting gateway-side functionality into the client-side, and to re-emphasise what Phil said, it won’t run unless a client is open, and will run multiple times if multiple clients are running. I would definitely move the expressions in memory expression tags. You will get very strange looks from other integrators if they see it as is :smile:

It’s the same idea as moving the OPC-UA functionality into a client page. If the client page isn’t open, tags stop updating (and you lose them altogether). If you have multiple clients with the page open, multiple connections are made to PLCs congesting the network.