Hour, minute, second timer


Recommended Posts

Hi, 

I am new to Daqfactory and fairly new to labjack (T7) which is being used.  I am struggling to set up a visual timer that can be started and stopped with a button and will visually display time lapsed time in hours, minutes and seconds.  Ultimately I also want data logging to be stopped and started at the same time.

Any guidance or examples on how this is best achieved would be amazing!

Thanks

 

Link to comment
Share on other sites

There are a number of ways to do this.  Here is one:

1) create a start button.  

2) in the Start Button, select a Quick Sequence Action, with code like this:

global expStartTime = systime()
global expStopTime = 0
beginLogging(myLog) // to start logging.  Replace myLog with the name of your logging set.

3) create a Stop button, select a Quick Sequence Action with code like this:
expStopTime = systime()
endLogging(myLog)  // again, replace myLog with the name of your logging set

4) create a Variable Value component.  The expression would be:

formatDateTime("%H:%M:%S", iif (expStopTime, expStopTime - expStartTime, systime() - expStartTime))

That is it.  The script in the start button initializes two variables holding the start and stop time of the experiment.  Stop time is set to 0 while the experiment is running since it isn't over yet.  The stop button then sets the stop time to the current system time.

The expression in the variable value component has two parts.  The first, formatDateTime() takes a time stamp and displays it in human readable format based on specifiers.  In this case %H is hours, %M is minutes, and %S is seconds.  Note that this will only work for up to 24 hours.  If you need longer you'll need the specifier for days, which is %j.  That will work up to 1 year.

The second part is iif() which stands for inline if.  It has three parameters.  If the first parameter is true (i.e. not 0), then the function returns the second parameter, otherwise it returns the third parameter.  In this case, we are looking to see if the stop time is 0 or not.  If it is not 0 then the experiment is done and we return the difference between the stop and start times, which is the final elapsed time.  If it is 0, then the experiment is running, so we display the difference between the current system time and the start time.  This updates each time the screen is redrawn.

Link to comment
Share on other sites

Legend! that's bang on.

+ Good work on DAQ Factory... Great product :)

 

FYI - For reference for anyone in the forum looking to do a similar thing - Have added some bits to name the data logging file + added an extra timer to display total test time:

image.png.ac4fc3d6d163da0e1983e6f3c51bf080.png

 

In a button quick sequence:

// Starts Timer and starts Data logging

if (Timer2Running != 1)  
  global expStartTime2 = systime() // Total Test Timer
  global expStopTime2 = 0
  global Timer2Running = 1
endif

global expStartTime1 = systime() // Test Phase Timer
global expStopTime1 = 0

if (logging.Data1.running) 
   endlogging(Data1)
 
   delay(1)
   
   logging.Data1.strFileName = "file path" + formatdatetime("%y_%m_%d@%H_%M",systime()) + ".csv" //add folder address into file path where ya want it saved.
   beginlogging(Data1)

else 
  
 logging.Data1.strFileName = "C:\Users\rs\Desktop\Calirometer Room\Test Data\CM1_" + formatdatetime("%y_%m_%d@%H_%M",systime()) + ".csv" 
   beginlogging(Data1) 
   
endif

 

Stop timer button quick sequence:

//Stops Timer & Data Logging Data1

expStopTime1 = systime()
endLogging(Data1)   

 

Second stop timer button quick sequence:

//Stops Timer & Data Logging Data1

expStopTime2 = systime()
endLogging(Data1)   

Timer2Running = 0 // resets bit to allowed timer to be started

Link to comment
Share on other sites

  • 5 months later...

Given a variable deltaT in seconds, to format it as H:M:S where H could be > 24 you would do:

doubleToStr(floor(deltaT / 3600)) + formatDateTime(":%M:%S",deltat)

If H was always < 24 you could just use the FormatTime() function, but that function rolls over at the day.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.