Creating a Stopwatch inside Ignition

Hello
So a Timer component cannot be used as Stopwatch since it drifts. I have Ignition collecting data from a Spraying Process and collecting data off a few scales. I don’t want my users to use a Physical Stop watch. I

I guess I can look into hour meter functionality of Transaction Groups?

Maybe I could do some scripting where I store a Started Timestamp then Every second look at Current Timestamp minus the Started Timestamp.(this shouldn’t cause issues?)

1 Like

I’m not sure on your exact needs, but one way you can do it is set up a memory tag configured for a date value. Have a button set the value of the tag as the current time

import datetime
value = datetime.datetime.now()
system.tag.write('TimerTag', value)

Next just have a label with an expression binding

secondsBetween({TimerTag}, now())

There are other date difference functions but this will give a seconds count that resets with every button push

1 Like

So to build a Stopwatch I needed 6 client tags, two buttons(Start/Stop and Reset), and Text Display. I ran with the Seconds between idea from above but ran into some issues on how to handle stopping the timer and then starting it again. Basically you need an Accumulated Time tag that on each stop that you add your Seconds Between to. You also need a Total Seconds tag that is the sum of Accumulated and Seconds between, this Total Seconds then gets converted into HH:MM:SS format Here’s the tags. stopwatchtags.xml (2.1 KB)
Tags rely on some Expressions and got complex with converting Total Seconds into HH:MM:SS with various division and modulus operators.
Here’s the Start/ Stop button script

import datetime
button = event.source
timerRunning = system.tag.read("[Client]Stopwatch/TimerRunning").value

if timerRunning == bool(0):
#timer not Running, but you hit button so you want it to start
value = datetime.datetime.now()
system.tag.write("[Client]Stopwatch/StartTime", value)
#set TimerRunning
system.tag.write("[Client]Stopwatch/TimerRunning",bool(1))
button.text = “Stop”

else:
secondsBetween = system.tag.read("[Client]Stopwatch/SecondsBetween").value
accumulatedTime = system.tag.read("[Client]Stopwatch/AccumulatedTime").value
accumulatedTime = accumulatedTime + secondsBetween
system.tag.write("[Client]Stopwatch/AccumulatedTime",accumulatedTime)
system.tag.write("[Client]Stopwatch/SecondsBetween",0)
system.tag.write("[Client]Stopwatch/TimerRunning",bool(0))
button.text = “Start”

Reset button

system.tag.write("[Client]VectorSerial/Stopwatch/AccumulatedTime",0)
system.tag.write("[Client]VectorSerial/Stopwatch/SecondsBetween",0)
system.tag.write("[Client]VectorSerial/Stopwatch/TimerRunning",bool(0))

1 Like

What I have done in the past is to create an integer expression tag that gets just the seconds from the system clock.I use a tag change script to increment a value I have in an integer memory tag when the stop watch is enabled. You can use the script to create hours minutes and days from the seconds value. You reset the system by setting the seconds accumulator tag to 0.