03-10-2013 05:00 PM
Hello,
I want to reset the status of several hardware to a defined state if the user clicks stop but before the while loop actually halts.
This is necessary to switch some hardware off before the program halts as otherwise the DAQ ports remain in the last status (and hence the hardware switched on) even if the vi has been stopped.
I tried several ideas (e.g. a sequence of events placed within the while loop and triggered by pressing a stop button) but no success so far.
This must be possible somehow, any help is greatly appreciated.
Thanks
Holger
03-10-2013 05:07 PM
Why don't you place the code outside the loop in a way that it executes when the loop has finished?
03-10-2013 05:13 PM
Hi Guenther, thanks for fast reply.
When the while loop has stopped the connection to the hardware is closed (I am using the LV for Arduinoi toolkit), see attached vi.
Thanks
Holger
03-10-2013 05:16 PM
No problem: Make some space on the block diagram for further actions (= your reset) before "Close" executes.
You can optionally put that code in a case structure that executes when Stop is True.
03-10-2013 05:34 PM
Hmm - tried that already, see attached example trying to switch off the pilot LED before the loop exits - doesn't work, doesn't switch of anything....
03-10-2013 05:42 PM
Bad luck: That is a race condition: Writing to the local variable does not ensure that the front panel gets updated in time!
If you don't want to place some code outside the while loop before the "Close" executes (which I still prefer): You can place your control "Pilot LED" in the False Case in your lv02.jpg and wire from here! The True Case should simply wire a "False".
Side Note: Remove the Flatten Sequence in the True Case of code in lv02.jpg. It has no effect to your code.
03-11-2013 02:13 AM
Pls can you explain what you mean by:
"If you don't want to place some code outside the while loop before the "Close" executes (which I still prefer)"
How can I place code outside the while loop that executes before the while loop closes??
03-11-2013 01:43 PM
The attached PNG shows two ways to do it: (1) You add some code after the loop and before the close. (2) You add a case sttructure. The Stop Button defines the set of booleans that will be used to set the state.
03-11-2013 02:07 PM
Ah - thanks Guenther, I have not done that before, but option one looks very interesting - especially as i do not have to change existing code.
So I just need to wire something from inside to the outside of the loop ...
I certainly look into this.
Thanks again.
Holger
03-17-2013 09:56 AM
Something that you don't seem to be considering; what happens if your computer crashes?? If you have a situation where you have to turn off items before shutting down code, then I would think that you also have to turn these items off, or disable them in case of a software catastrophic failure. This would seem to be a textbook case for a watchdog hardware unit. These units are dirt cheap, and can save many heartaches.
Good luck,
Dave