Tag Restart or Parameter Change Script

Because of some inconsistencies in the field we have a parameter to define direction/sign for a number of tags in a UDT. We have a tag change script that watches one value but it is not entirely reliable, it is a Bool and when the received value is false we don’t even see the initialChange event fire.

Is there any mechanism to fire a script on tag restart or parameter change? Tried using initialChange on a couple of tags in the UDT and it doesn’t fire, plus, don’t even really want the check for that running all the time, this would be a rare occurrence.

Ideally, we would have a script that runs once on either a parameter change or a tag restart.

initialChange occurs when a tag is first subscribed (e.g. gateway restarts) or the first execution after a Tag Update (e.g. Tag Edits accepted). It is not set for an actual value change.

I don't fully understand what you are trying to accomplish.

From the manual:

UDT parameters are pre-compiled, which in this case means value changes are mostly ignored until the UDT is restarted

OK, let me see if I can do this better.

I have 12 tags within the UDT. They represent six value pairs of IN and OUT. In the field at some devices the ones labeled IN are actually OUT, and some of the ones labeled OUT are actually IN. But the data table is fixed.

What we have done to resolve this is put those OPC tags in a folder named “Indirects” within the UDT. Then when we first read the device we can easily tell which way is IN and which OUT. We then have matching Derived tags, and we use a script to set the sourcePath for those derived tags.

When we first developed this we had a Boolean value that we thought would tell us which tags were IN and which OUT, but it turns out not to be the case. We have found no rhyme or reason, it is basically a 50:50 shot at which tags are IN and which are OUT.

So, created a parameter to define that. Assigned the parameter a default value of OUT, which is wrong half the time. What I’m looking for a is a way, when an operator changes the parameter value to run a script that re-assigns the derived tag sourcePath.

The assignment scripting is easy/done. It’s just getting a script to run once rather than all the time, and to run when we need it to, which can either be on parameter change, or I can make it a part of the procedure to restart the tag when updating the parameters. Or, any other solution that allows me to fire off the solution once without a button a on the screen (because it is usually on the development side where we would set it once and then done). I could do this with a change event on the indirect tags, but then it fires all the time, which is not elegant, and, as noted, initialChange doesn’t quite meet the need, plus you have to evaluate the first line of the script every time, again, not elegant.

Evaluate initialChange every time. Unless you have other checks validating currentValue versus previousValue and/or external state. Elegance is meaningless.

1 Like

I’m looking for something that doesn’t need initialChange. This thing is really more of a development side process, although there’s a small chance with equipment replacement that it will need to be run in runtime. That means I don’t really want to be monitoring the OPC tags for change, would rather be able to monitor either one parameter or a tag restart. Then it only needs to fire once a year or five years, or whatever equipment life is, rather than being constantly monitored.

To me, on tag restart would be best, something along the lines of a “tag initialization script”.

You’re asking for a separate event? Put it up on the ideas site (feature requests). Considering that you want an alternative to existing functionality, I doubt it will be entertained, but you never know.

What is the existing functionality? I don’t see anything that runs only once when a tag is started. Even more when a UDT instance (with many tags in this definition) is started. It’s functionality I can get in a second by ticking a box in System Platform, so I’m trying to see if I’m missing something. Use it all the time to assign tag bindings on startup.

But, having been thinking about it, I think if I set the Derived tag binding to “some text” + {Parameter} I can make it work. Hadn’t thought of that approach (because we started with thinking the Bool tag would tell us), but this discussion got my mind pointed in that direction, so thank you.

The initialChange flag is the existing functionality within the existing events. Each event runs once (unconditionally) after tag startup/restart with that set true, and previousValue set to None. It runs thereafter (on event) with initialChange set false, and previousValue set to the actual previous qualified value.

If you need to handle startup, your code must look like this:

if initialChange:
    do_some_initialization()
else:
    do_normal_event()

If you need neither initialization or to use previousValue, your code can look like this:

do_something_with_currentValue()

It is that simple. It is what you need to do. Until such time as IA alters it to suit your definition of elegance.

1 Like

Got it. Just don't like it. That first line:

has to be evaluated on every change, along with the tag change watch built into the system. For something that basically assigns a static value that isn't efficient. But, it is what it is.

FWIW I've done this by creating two parameters "IN" and "OUT" and then setting the sourcePath to use those. This, too, is inelegant, because I have two parameters and no way of making them mutually exclusive, but absent the capability of an "IF" statement in the binding expression....

Anyway, I do want to thank everyone, I appreciate the discussion as it gets my mind moving in a different direction.