04-13-2012 10:45 AM
Hi everyone,
I have wrote a programm with if case which checks whether the time stamp lies between 8am til 4pm with time range. If outside this range, it will send a signal to shut a relay down, if within this time frame, it will send another signal to turn it on. But the problem is, it runs 24 hours everyday to check this condition with while loop and if case, combine with timerange.
Does anyone has an idea , where the programm only runs twice a day, which is 8am run the program to turn it on, and 4pm run another time to turn it off, without repeating everytime.
I have a feeling it is time loop structure related and have tried it, but I can't seem to set the start time as 8am, and end time at 4pm, what i can manage to do is that in the first frame in time loop, it runs and it turn on, and the second frame has to wait a very long time(whatever time u set), then it will execute to turn it off. It works but everytime i have to calculate the time difference. I am looking for alternatives.
Thanks for anyone's help.
Have a nice day.
04-13-2012 10:52 AM
calculating a time difference is not prohibitively complicated. Why do you even try to avoid it?
For these long times, I would not use a timed loop. You could utilized a timeout event of an evet structure, for example. Whenever a different event occurs, it will recalcualte the timeout balance.
04-20-2012 04:53 AM
Hi,
please use this link to advance your VI with this advices. This KB is using Labview scripting. With these steps you can run and stop your VI programatically. You can use a for-loop which is just running 1 time, to shut the relay. After one loop the programm can stop via the method-node. With this method-node you can choose if you want to stop or start your VI. That means you have to duplicate this scripting-VI (which is programmed for the stop-condition) and implement the start-condition of this second one:
How do I stop a running VI:
http://digital.ni.com/public.nsf/allkb/68128403FC24FB6E86257211007F1104?OpenDocument
Best Regards
Reiner
04-20-2012 07:46 AM - edited 04-20-2012 07:47 AM
I think it is Ed Dickens who sprats a signature that reads something to the effect of;
"Using the abort button to sop your application is like using a tree to stop your car. It will work but you may not like the consequences."
Calculating time difference for 24 X 7 apps is not as easy as it appears due to Daylight Savings Time. DST introduce one day a yeear that has 25 hours and another day that has only 23 hours. We can not code these dates at development time since they are subject to the will of the congress and are subject to change ("Woe to those who seek to change times and ways." Is that Revelations?).
Since you target times do not fall into the nebulus hour that may or may not be there, I would recomend you set up a loop (timed or not) that queries the system time once a second to see if the current time meets your criteria. When doing the check don't try to an exact match of the time since the code may run end up missing the exact hour by a handful of seconds one way or the other due to other processes runing on the machine.
"
This thing all things devour:
Birds, beasts, trees, flower;
Gnaws iron, bites steel;
Grinds hard stones to meal;
Slays king, ruins town,
And beats high mountain down.
"
JRR Tolkiens The Hobbit, Riddles in the Dark , Time.
Ben