Gateway Restart Triggers On Change Data & Scripts

Ignition Platform 8.1.20

Currently, I am having an issue with our gateway crashing and restarting. We are addressing that issue, but as a byproduct of the issue my on change data in history is recording multiple times, instead of unique values.

History Settings:

SQL History View of On Change Data
image

The big issue that I am currently having is that these restarts are activating a script in my tag event scripts. Is there a way to ensure that the script does not trigger on initial startup?

Current Script IF Statement:

if previousValue.value != currentValue.value and initialChange == False and currentValue.value <> 0 and currentValue.quality.good:

All tag change events are executed once on startup with initialChange set True and previousValue None. You must not attempt to reference previousValue.value during initial execution as that will throw an error.

Your code must be tolerant of this as there is no way for the server to know, short of a history query, to obtain the previous value. (And a history query is too expensive to run in a tag event. Really, any database operation is too expensive for a tag event, unless it hands off to the store and forward system.)

A gateway tag change event (in a project) is more tolerant of longer execution times, and can use a project script library's "import" behavior to bulk query the most recent value for many tags at once.

Bottom line: there is no simple solution. Many applications tolerate the extra row and use lead/lag functions in the DB or scripted post-processing to deal with such duplicates.

1 Like

In your initial statement you say that on startup initialChange is set to True, but my code indicates that it must be False for it to run. How does it execute the code then?

Would referencing a memory tag be less taxing?

The if statement's condition itself accesses previousValue.value before it checks initialChange.

Broken.

Does broken mean it goes ahead and triggers whatever is after?

No, it means it hits a null for previousValue whenever initialChange is true, never even getting to that case.

The order you put your checks in an if statement matter.

1 Like