Hello all,
Is there a way to dynamically build the source tag path of a Reference Tag?
I have a structure similar to the following:
(just pretend that the PLC tag is actually connected)
What I'm trying to do is have the Temperature tag reference either the MEM/Temperature tag or the PLC/Temperature tag, based on the value of the Config tag: that is, if Config has value "MEM", I want Temperature to reference MEM/Temperature, whereas if Config has value "PLC", I want Temperature to reference PLC/Temperature instead.
I can do that using an Expression tag, dynamically building the path I need by reading the Config tag. However, I also need to be able to write on the Temperature tag and have the value cascade back on the tag that is being referenced: that is, if I'm referencing the MEM/Temperature tag and I write the value 20 on the Temperature tag, I want the tag MEM/Temperature to also be written with the value 20.
If I use an Expression tag, I lose the ability to write on the Temperature tag.
I'm not sure what the application is here, but if you want to dynamically transfer data from Temperature to either MEM/Temperature or PLC/Temperature, I would use a tag value change script on Temperature that dynamically writes to either MEM or PLC, switching case based on the value of Config.
Hi Alex, thanks for the suggestion. That would solve the problem of having to write back the value to either the MEM or PLC tag, however if I setup the Temperature tag as an expression (to mirror the value of either the MEM or PLC tag), I cannot write in the Temperature tag, meaning that the tag value change script would not trigger
This is the whole problem I am trying to solve: we defined a UDT that looks like this
For each tag in the Data folder, we have
a tag with the same name in the Config folder, which indicates where we want to read the data from
a tag with the same name in the MEM folder, which is a memory tag
a tag with the same name in the PLC folder, which is an OPC tag
We developed a Perspective interface that allows our client to create a new instance (or edit an existing one) of this UDT, specifying for each tag in the UDT
Whether the tag is static (MEM) or read from the PLC
The value of the tag (if the tag is memory)
The address of the tag (if it is PLC)
This was done because the PLCs used by our client do not always have all the information that are required. Tags that are missing from the PLC are set as MEM, so that they can be manually edited by the operator if needed.
Since some of the tags in the Data folder need to be written, I need a way to be able to both read from either the MEM/PLC folders and write back to those tags.
You should make all your Data tags as OPC tags in the UDT. If a particular instance doesn't have one or more of them, override the .valueSource to "memory". (You can use a simple system.tag.writeBlocking() for that.)
No config required. No funky, unsupported expressions. Tag configuration bindings don't behave the same as other bindings, so your approach is broken. See this related topic: