How do you implement a count down timer?

I am writing to two tags.
Waiting 60 sec between in between.
How do I implement a logic that accept timer value (60) and display count down and trigger command when count reach 0?

On timer start, write expected finish timestamp to a tag. (Add the timer duration to current timestamp)

For countdown display, use an expression that subtracts the current timestamp from the future timestamp.

For executing actions, have a 1s gatteway timer script that inspects the current timestamp and if it matches/is beyond the expected completion timestamp value, executes the action and writes None into the expected finish timestamp tag.

Whatever you do, do not rely on the perspective session to execute the delayed action.

As lrose mentions below, the delay and value write really should be in the control device, not Ignition.

1 Like
RST XIO COUNT_DELAY.DN NEQ MINS_TO_WAIT BST TON COUNT_DELAY 60000 0 NXB OTU TIME_ELAPSED BND RND
RST BST XIC COUNT_DELAY.DN SUB MINS_TO_WAIT 1 MINS_TO_WAIT NXB EQU MINS_TO_WAIT 0 ONS TIME_ELAPSED_ONS OTL TIME_ELAPSED BND RND

No?

Okay, a little more seriously, if for some reason I couldn't do this in the device, then I would do it with custom properties and a combination of expressions.

Create a custom property to hold the start time.
Create another custom property to hold the current time, I would use the expression now(1000) or some expression that resolves to that e.g. now(if(TIMING,1000,0)) That way you're only polling when you are actually wanting to time.
Finally use an expression to compare the two times until your desiered delay is reached.

if(dateDiff(START_DATE, END_DATE,min) > MINS_TO_WAIT, True, False)

There are other ways to achieve a similar result. It really just depends on what your true end goal is.

2 Likes

I would do this in the PLC. Make a temp/buffer tag and write to both at the same time and then after your delay copy the temp into the actual. Connect to a third tag that has the time remaining calculated from the PRE and ACC

3 Likes