Hi!
We have found this thing that where a restart of a tag triggers tag-change script. This feels pretty normal since the tag is restarted. In the script we check for initial condition but the script runs anyway.
The tag change trigger only looks at value. The value is not changed.
Is there any other flag to look at when doing a tag restart?
Is this a bug?
When a tag restarts it is very briefly Null. So there really is a value change when the first OPC value arrives. At least, that’s what it looks like to me. Not really a bug, just an implementation detail.
You should note that if the value really does change while the tag is restarting, this approach will ignore it. If running extra is more of a problem than a rare miss, then carry on. The bottom line is that the tag itself doesn’t have enough information (cannot) to perfectly delivery value changes through a restart.
You need something that isn’t affected by the tag restart to hold state of some kind. For the simplest case, I recommend using a memory tag to hold the previous value. Then do not check initialChange. Just always check the delivered new value against the memory tag. If they are different, write the new value to the memory tag and proceed with the rest of the logic.
If the script is supposed to do database operations or other external operations, a more robust solution would be to cache the last successful operation in a project script top level variable. When accessed the first time after a script restart (cache==None), read from the DB or external server to populate the cache.
No, top level variables in script modules are thrown away when the script is restarted (due to project save, typically). It doesn't matter for these variables what data type is used. Can even be jython class instances that you've defined.
The memory leak hazards come when you place non-native objects in the dictionary from system.util.getGlobals(), or attach a jython-defined listener implementation to an SDK API object.