Creating an elapsed time display that must be reset by an acknowledge button

Hello all, brand new to ignition here. I’m attempting to make a display on an inputs banner i’ve created that has some acknowledge buttons for strainers on a water tank. I want these buttons to have an elapsed time display underneath them that counts in minutes and seconds to show how much time has passed. Pressing the acknowledge button should reset the time displays to zero. I have the button and two numeric text displays with minute and second labels under them. What is the simplest way to script the minute display to increment up each minute and the second display to increment up each second, and still be able to reset them with the button?

Please tag your post as either Vison or Perspective. The answers will depend on that.

Also, can you guarantee that there will be only one client or would it be possible for two clients to reset at different times. What would you want to happen in that instance? Both reset or only one?

Tagged as Vision, sorry.

Yes, only one client would be resetting it.

Have the acknowledge button write system.date.now() to a datetime custom property. In the elapsed time display, compute the delta seconds between now() and that property. Use some modulo math to separate seconds and minutes.

2 Likes

In the elapsed time display, when I was trying to write an expression to compute secondBetween that custom datetime property and now() it gives me an error that the function does not work with 1 arugments. I think that part is where I’m getting a little confused.

The function needs two arguments: 1) now(), and 2) {path.to.saved.timestamp}.

I want to make sure i’ve taken the correct steps along the way. On the acknowledge button, I’ve gone to customizers>custom properties and added a new one labeled Strainer1Time and made the type a “date” type. Then I go to the component scripting for that ack button and go to a mouseClicked event and go to script editor and have set that property as follows:

Strainer1Time = {system.date.now()}

Then I go to the numeric display and bind its data value to an expression. Is everything correct so far? Because at this point i get syntax errors when trying to calculate the detla time as such:

secondsBetween(now(), {Root Container.Input 3.Strainer1Time})

and this time is just a really large number, because clicking the acknowledge button never resets the timestamp it is assigned. The date associated with that custom property is constantly the earliest date in the system. It’s always set to 12/31/1969 12:00:00. The numeric display’s value is increasing each second, but the button isn’t getting a new timestamp when clicked.

I recommend creating a DateTime memory tag to store your start date. All the acknowledgement button would need to do is write the current time to that tag. The code will fire from the button’s actionPerformed event handler, and it will look like this:
system.tag.writeBlocking(["[default]yourTagPath/DateTimeTag"],[system.date.now()])

Then, bind your Strainer1Time custom property to that tag value

If you are using a label to display your time difference, bind the following expression to the text property, and it will display the time difference you are looking for in hours, minutes, and seconds:

round(dateDiff({Root Container.Label.Strainer1Time},now(1),"hr")-.5)+ " Hours " 
+ 
round(dateDiff({Root Container.Label.Strainer1Time},now(1),"min")-.5
-(60*round(dateDiff({Root Container.Label.Strainer1Time},now(1),"hr")-.5))) + " Minutes "
+
round(dateDiff({Root Container.Label.Strainer1Time},now(1),"sec")-.5
-(60*round(dateDiff({Root Container.Label.Strainer1Time},now(1),"min")-.5))) + " Seconds "
1 Like

Note that your date order would give you a negative number.


Tip: use the </> button to format code. It will preserve indentation and do some syntax highlighting for you. For inline code put it inside a pair of ` backticks.

No, this would be:

event.source.Strainer1Time = system.date.now()

If you looked in your diagnostics console, you would have seen an error every time you clicked the button.

Thank you, that has been a tremendous help. It definitely beats everything I was trying to do. I'm getting an error now on the quality property of my label that reads, "Error_ExpressionEval". Do you know what would be giving me that error? When i click the button in preview mode it doesn't give me a new timestamp either. The date for Strainer1Time still says also.

If you haven’t done so already, you will need to create that memory DateTime tag. Then, right click on it and copy the path. Afterwards, you will replace "[default]yourTagPath/DateTimeTag” with your tag path.

Then, press your button. If your custom property binding is pointed at the tag, it should pull in the data provided that your custom property is a DateTime. Afterwards, your expression will probably evaluate correctly.

Also, I like the advice from @pturmel: click on the help tab and launch a diagnostic console. If there is anything going wrong in the project, the console will provide detailed information on the errors.

1 Like

Yes, I have done that. I found out what the issue was regarding my last reply. I was binding the Strainer1Time custom property to the DateTime tag instead of DateTime.Timestamp property of that tag. Once I did that, it started taking the proper timestamp and cleared the error. Thank you for the input!

1 Like

Great! glad you figured it out

1 Like

Yeah, thanks for your help! The only thing I’m still working out is how to make the button reset the time on the label. When I click it, it doesn’t reset the time in the label.

What is the code you are using in the actionPerformed event handler of your button?

Bind the label to the tag. Then it will be automatic.

system.tag.writeBlocking([“[default]Timestamp/DateTimeTag”],[system.date.now()])

And for the other two buttons below it i have it going to the other Timestamp tags i made.

Looks correct. Is your tag set to read only?

1 Like

No, it’s not set to read only. Write permissions are set to public.