LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to reset hardware before exiting while loop

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

0 Kudos
Message 1 of 10
(3,121 Views)

Why don't you place the code outside the loop in a way that it executes when the loop has finished?

0 Kudos
Message 2 of 10
(3,117 Views)

 

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

 

 

0 Kudos
Message 3 of 10
(3,114 Views)

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.

0 Kudos
Message 4 of 10
(3,110 Views)

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....

0 Kudos
Message 5 of 10
(3,106 Views)

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.

0 Kudos
Message 6 of 10
(3,100 Views)

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??

0 Kudos
Message 7 of 10
(3,072 Views)

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.

0 Kudos
Message 8 of 10
(3,052 Views)

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

0 Kudos
Message 9 of 10
(3,039 Views)

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

Message 10 of 10
(3,000 Views)