Timer function that works gloabally(gateway)

I have a timer component that runs based upon a tag Boolean and displays it onto the screen. My problem is that I would like the timer to be synchronized throughout the project. So I guess a gateway script of some sort would work the best for this situation.

The timer is a vision component whose value won’t increment if the screen isn’t open and the ‘Running?’ parameter not set.

From the documentation:

This is often used for animations or repetitive scripts within a window

and

Want to run a script every time the timer counts? First, make sure you don’t actually want to write a project Timer Script, which will run on some interval whenever the application is running. In contrast, a script that works via a Timer component will only run while the window that contains the Timer is open, and the Timer is running. The way to do this is to attach an event script to the actionPerformed event.

What are you using the timer for? Hopefully not timing the boolean tag… It sounds like you want a Gateway Timer Event Script.

1 Like

Actually I am using it to count the time in between the Boolean tag changes from 1 to 0. Is there a better way to grab that value and display it on the client?

I would suggest making a Tag with the type of ‘Date’ that stores the time of the last transition from 1->0.

Then in your Boolean tag, write a tag-changed event script that reads:

if previousValue.value == 1 and currentValue.value == 0:
    system.tag.write("Path_to_date_tag", system.date.now())

So now you’ve got the time of that change. In your vision window to display the duration to the user, in an expression binding do something like:

secondsBetween({datetag}, now())

Which will display the raw integer seconds since the last 1->0 change. You could format that into a string as you like.

2 Likes