Gateway Tag Event Script - Event Driven Bug?

Am I missing something? I had the following expression that was working with Fixed Rate execution mode and in the gateway tag change script.

if({[.]inDeviation} = True && {[.]../../shift/secondsInShift} >2,dateDiff({[.]prevCountTimestamp},{[System]Gateway/CurrentDateTime},"second") - {[.]deviationCycleTime.value},0)

Then I switched to event and the gateway script only triggered on the inDeviation change.

if({[.]inDeviation} = True && {[.]../../shift/secondsInShift} >2,dateDiff({[.]prevCountTimestamp},now(1000),"second") - {[.]deviationCycleTime.value},0)

My gateway script then doesn't capture the change of the tag on the now() function in the expression. The tag value changes as expected.

It doesn't say it in now | Ignition User Manual, but I imagine this will work in Vision and Perspective expressions but not in tags. I imagine that this is because of the way that things get added to a watch events or schedules.


Comments:

  • You don't need == True when testing a boolean. The boolean will return a True or False.
  • Expressions can take line breaks, spaces and tabs to improve legibility.
  • Add a space after a comma and before and after operators (=, <, >, etc.), as done in written English. It makes reading much easier and will allow text wrapping on space in some editors.
if(
    {[.]inDeviation} 
    && {[.]../../shift/secondsInShift} > 2,
    dateDiff(
        {[.]prevCountTimestamp}, 
        {[System]Gateway/CurrentDateTime},
        "second"
    ) - {[.]deviationCycleTime.value},
    0
)
if(
    {[.]inDeviation} 
    && {[.]../../shift/secondsInShift} > 2,
    dateDiff({[.]prevCountTimestamp}, now(1000), "second") 
      - {[.]deviationCycleTime.value},
    0
)

The now() expression function ignores its argument when used in an expression tag, and that tag is not in event driven mode. (Same for runScript().)

If you are using now() or runScript() in expression tags, you probably do want event driven mode.

1 Like