Showing results for 
Search instead for 
Did you mean: 

How to click 'Run' button at the start of the day, and 'Stop' button at the end of the day automatically or programmatically?

Go to solution



I am wondering how I can make my labview program start at the beginning of the day and stop at the end. 


Currently I am waking up at 8am each morning and going onto my PC and turning on a LabVIEW program I have working at a location.


Then at 5pm I go on my PC and stop the program again. 


However, I am wondering if it possible to completely automate this, as sometimes I forget to turn on the program and I will need to do this every day for many years if I do not automate it.


The program works by taking 4 channels of data from DAQ assistant, and writing each channel to its own tdms file using "write to measurement file" VI. 


This originally wrote the 4 files to a folder, and each day when I stopped the program I would go in and drag the 4 files to a new folder for example named '13th Jan'. 


I have automated this so that the file path is now a concatenated string, the middle part of which is an output from 'Format date/time string' so the file path looks roughly like this: C:\13Jan\Channel1.tdms. 


This creates a new folder and writes the 4 tdms files here, so I do not have to drag and drop the files after I stop the program each time.


So I have automated it slightly. I still however must click 'Start' and 'Stop' at 8am and 5pm, respectively, and I am wondering if there is a way to automate this too? 


All I would need to do, is click 'Run' button at 8am, and click 'Stop' button at 5pm.


I am struggling to find an answer, any help would be much appreciated.

0 Kudos
Message 1 of 13

I guess the simplest way would be to leave it up and running, but have the application only do the "stuff" between certain hours of the day.  (This solution assumes you can modify the code.)

(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 13

I am getting there. 


I am getting a date/time string in the 24 hour format mode %H (e.g. 17 for 5pm) and checking if that number is greater than 14 (edit: correction I meant to write 16 here). If it is, return true to the stop terminal in the while loop. This completely stops the program. However that doesn't really solve it as I still need to 'Run' the program each morning at 8am with this solution

0 Kudos
Message 3 of 13

I will try use a case structure and only return true if the time value is between 8 and 17. However that does mean that check will be done constantly, i dont know if that will affect the program or not.

0 Kudos
Message 4 of 13

@lorc34  ha scritto:

I will try use a case structure and only return true if the time value is between 8 and 17. However that does mean that check will be done constantly, i dont know if that will affect the program or not.

There is no alternative. Don't forget to put a suitable Wait in the False case.

LV 7.1, 2011, 2017, 2019, 2021
Message 5 of 13
Accepted by topic author lorc34

Expanding on @billko's elegant suggestion, you need two more routines that "manage" your existing routine.  Consider your requirements and "givens":

  • Assumption:  Your code is contained in a LabVIEW Project.  [This really isn't necessary, but if your code is totally disorganized, then "organizing it" into folders, putting it into a Project, and striving for "good style" will have huge payoffs].
  • Given:  You have a routine that you manually "Start" at 8 a.m., and have to push the "Stop" button at 5 p.m. every day.  Let's call this the "Main VI".
  • Requirement #1:  Once the Main VI starts, you want to stop it 9 hours later.
  • Requirement #2:  You want another routine (which might "contain" your Main VI) that runs your Main VI (with its "auto-stop" after 9 hours) at 8 a.m. the next day, e.g. 15 hours later).

OK.  Let's change Main VI so it meets Requirement 1.  LabVIEW has a Timing Palette that will return you the Date and Time in seconds.  Use this to get the Date/Time when the program Starts.  (You failed to attach your Program, so I can't suggest where to put this, but you should be able to figure out a place that meets the following criteria:  It runs more-or-less when the Program starts, and it runs only once.)  Compute how many seconds the program needs to run (exercise left to the reader) -- now you know the Date/Time when the program should end -- express this condition to create a LabVIEW Boolean that turns "True" at this time and wire this in place of the Stop button (you can use an "Or" function if you want both the Timer or the Stop Button to stop the program.


Requirement 2 means that you have a program that runs 24/7/365, and does something similar to the modification we made to Main VI, but now Main VI is the sole sub-VI of the "Master Timer" VI.  What does this do?  When it starts, it gets the Date/Time and figures how long to wait until the next 8 a.m.  [Think about how you'd use the Timing functions to figure this out].  Express this "Wait" time in milliseconds and use the Wait (ms) function to Wait.  Note that the Wait function does not use the Error Line -- if you are using LabVIEW 2018 or later, you can use the Stall VIM (which "attaches" the Wait to the Error Line -- see if you understand why this might be extremely convenient in your situation -- of course, since I didn't see your code, I don't know if you realize how important the Error Line can be to Good LabVIEW Style ...].


Once you've done this, run the Master Timer.  Be sure to put a "Stop" button on it, or you'll have to turn the PC off in order (2 years from now) to stop your routine running 8-5 every day ...


Bob Schor

Message 6 of 13

If you are executing a .exe you can use the Task Scheduler from windows to be sure to start the task each day at 8am and this from a clean startup of your software. You will only need to check one timer so less chance to have an issue.


Then you executes your VI for 9 hours with an internal timer until it stops, as suggested previously. Depending of your architecture, this check could be done in its own While loop that send a Stop event by Signaling your stop button when the timer is over, no big impact on the data acquisition performances and no changes in the global behaviour.


Message 7 of 13

You can try using the function OPEN VI REference, 

You need to create a vi that uses OPEN VI reference and calls the LabVIEW program you need to run at 8:00 AM use INVOKE node to RUN VI 

Then you make control to star the program at 8:00 and abort at 5:00 pm. 

You need to wire the VI path on the OPEN VI REference to the VI path of your LabVIEW PRogram. 



Message 8 of 13

Hi Bob.


Thank you very much for your suggestion. 


I have gotten half way with your suggestion, I am now able to stop the program after a specified number of seconds which I can define in my program (9 hours is 32,400 seconds, so I will set it to this)


I am struggling with the second part however, specifically finding out how long it is until 8 am hits.


8*3600 = 28,800 seconds. I have a few Get Date/Time Format functions finding the hours, minutes and seconds in the current day.


I am multiplying the hours by 3600 and minutes by 60, and adding these two products together and adding the seconds to that sum too. This finds the number of seconds since the beginning of the day. 


Lets say its 02:18:43, this will equate to [(2*3600)+(18*60)+(43)] = 8323 seconds. 


I could simply do a 'greater than?' function, so if my calculated seconds is less than 28,800, it would not be 8 am. 


However, this logic only works if its between midnight and 8 am, not if it was 10pm for example. Then my 'seconds in the day' would be (22*3600) 79,200 seconds which is greater than 28,800. 


Perhaps I can do a 'less than?' function in combination with my 'greater than?' function, and make sure it is also 'less than' 5pm, i.e. (17*3600) 61,200 seconds?


edit: Also, I have attached my VI. Thank you very much for your help and everyone else offering solutions. I will post the VI in the main post above too incase anyone misses it.

0 Kudos
Message 9 of 13

So my "Master Timer" VI will simply be a while loop, then inside that a case structure which operates my main VI (now a sub VI) only when the seconds clock is between 8 am and 5 pm?

0 Kudos
Message 10 of 13