01-02-2011 05:15 PM - edited 01-02-2011 05:15 PM
Hello All
The attached vi is quite simple. It is an event structure inside a for loop, with some other code (current time compared to fixed time value).
When the vi starts, the first iteration of the while loop happens (as evidenced by the time update in the time string indicator). Successive loop iterations, I assume occur, but it seems that whatever happens inside the event structure function stops the extra code in the while loop from performing (as evidenced by the indicator not updating in the time string indicator)
I'm not arguing that this is incorrect operation but would like somebody to give me a simple explanation as to what happens. I looked at the help, but it doesn't necessarily deal with this (that I can work out anyway)
What I intend to have happen is an event case to perfrom when a time value is reached (say shutdown the computer at 6:30 PM (my fixed string value)), and I wasn't aware of the above behaviour until I tried a few examples.
Any insights to what actually happens?
Regards
Ray
01-02-2011 05:29 PM
You have nothing wired to the timeout value so the event structure is the only thing that runs - it never exits back to the main loop. Wire up a value (i.e. 500) and place the get time code inside the timeout event. You should place the stop button in it's own event, get rid of the wait, and you would need to write to the Value(Signaling) property to programatically fire the 'equal' event. Doing an equal is also wrong. You are requesting seconds so your comparison will never match.
01-02-2011 05:41 PM - edited 01-02-2011 05:43 PM
As Dennis already hinted, you have some beginners misconceptions about the events structure.
In this particular code, the event structure has no meaning or useful function, because you need to spin the loop anyway in order to do repetitive comparisons. All it currenty does is wait forever, thus blocking the loop from going to the next iteration. All you need is wire a case structure to the output of the "equal". Leave the FALSE case empty and place your desired conditional code in the TRUE case.
Events are (primarily) triggered by user interactions of front panel controls. Indicator updated don't fire events for good reason.
Useful debugging tool are "execution highlighting" and "probes". Run the VI is highlighting mode and watch the diagram to get a better feel of what's happening.
What are you actually tring to do? I am sure there are better ways to do timed actions?
01-02-2011 10:09 PM
Dennis, Altenbach
Both your suggestion worked ( I had no doubts).
The vi I attached is a very heavily edited version of a much larger program in which I'm using a producer/consumer architecture. I cannot show the whole code due to proprietary issues and "in confidence" agreements with our client.
What I was aiming for with little snippet attached was simply to force any windows programs (including the vi) to close and the computer to shutdown mode at a particular time each day (6:30PM to be exact)
I have the code working for the forced shutdown and it is a small vi that I would run when the system clock read 6:30 PM.
I figured it would be a simple method to compare the current time to a fixed time constant and if true have the true case of a case structure call the shutdown vi.
That's the plan anyway. BTW...Dennis....I did try using the timeout event as you suggested and it worked just fine, but in my main program I am using the timeout event to cause a tab control to revert to a particular page witihn the control, so that's why I hadn't pressed it into service for this action.
Of course any advice is gladly accpeted.
Regards
Ray
01-03-2011 01:56 AM
What about windows scheduler and "Shutdown -s"?
/Y
01-03-2011 04:42 AM
Don't forget /t 0 to avoid the message and the one minute wait.
command will then be:
shutdown -s /t 0
change 0 to something else if you want some timedelay.
01-03-2011 10:16 AM
@altenbach wrote:Indicator updated don't fire events for good reason.
Unless of course you write to the Value(Signaling) property of the indicator. I am sure you know that but I just wanted to clarify.
01-03-2011 11:51 AM
01-03-2011 05:16 PM
Whoa.....starting to move off topic guys.
Thanks for all the suggestions, but I'm comitted to the method I suggested in my second reply post...that is.....no windows scheduler.....no shutdown command.......use event structure.
Regards
Ray
01-03-2011 07:11 PM
I'm sure they were just going on the premise that "the best way isn't always LabVIEW" and were simply suggesting something that might solve your problem in a more efficient manner. Since there was no background given on why you were attempting this, the windows scheduler comments weren't really too far off topic. I'd seen this solution mentioned a few times before and in those other cases they responded with "why didn't I think of that!" 😉