LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Executing a command when exitting a VI

Hello everyone!
I am hoping my question is very simple, but I would like to know how I can execute a series of commands when exitting a VI.
 
In my VI, I am allowing the user to choose three choices: "Mark Bad," "Mark Good," and "Mark Questionable."
 
According to which choice the user selects, it'll append a column array to a 2D, and write it to a file "delivered.csv".
 
What I want is whenever the user exits the VI, for this occura.  You will see in my VI the Exit Button doesn't work for some reason. 
 
For example, if I select "Mark Bad," then when I exit the program, I should see a file named "delivered.csv" in my folder. 
 
The file only writes when operating on the PC (not PDA), and ONLY WHEN a particular boolean is highlighted at the start of a run program.   I want it to write when I exit a program.
 
Any ideas?  I am attaching my VI along with my *.csv files.  Be sure to change the directory.  I can also send a VI in LV8.0 if it helps.
Thank you! 🙂
 
 
Amal Patel
0 Kudos
Message 1 of 10
(5,335 Views)
Amal,
 
The reason why the three cases aren't executed is because the buttons for these are read at the start of the VI.  Obviously they are false at that time, and so will go through the False cases.  You can see this by using the Execution Highlight debug mode (see Online Help if you aren't sure what this is). 
 
What you need is data dependency betwen your loops.  You will want to ensure that these buttons aren't read only after the other loops have stopped.  A quick-n-dirty way would be to enclose these cases in Flat Sequence structures to force the data dependency.  A better approach would be to use an Event Structure.  And maybe a consumer state machine with it.  Lookup these keywords for more details on these. 
 
Hope this gives you some ideas.
 
-Khalid

Message Edited by Khalid on 11-22-2006 12:17 AM

Message 2 of 10
(5,330 Views)
Mr. Khalil,
Since I'm pressed for time, I'll use the Flat Sequence Structure 🙂  I'll look it up.  Thank you very much.
 
One more question, any idea as to why my exit button is not working?
 
Amal Patel
0 Kudos
Message 3 of 10
(5,312 Views)

Where is the Exit button?

-Khalid

Message 4 of 10
(5,294 Views)
This may not suite to your problem, but one general way to execute code on VI exit is to place an XControl on the fron panel. This XControl should have an additional ability which is executed on XControl exit. The XControl is exited when the VI is closed, so this ability VI gets ran when the VI exits. You can hide anything to this ability VI that you need to be executed when your VI exits. A much easier method is of course use event structure to detect front panel close.

--
Tomi Maila
Message 5 of 10
(5,284 Views)

Thank you everyone! All of your help has been wonderful; high ratings for everyone!!!!

I spoke with a support engineer and he fixed my code.  I am attaching it if anyone in the future would like to use something like this.

Amal Patel
0 Kudos
Message 6 of 10
(5,268 Views)

One still has to click on one of the buttons (Mark Good/Bad/etc...) before running the VI.  Not sure if this is the best way to do it. 

In any case, whatever works for you. 

-Khalid

Message 7 of 10
(5,263 Views)

Mr. Khalid,

You are right, and that is not what I want.  It's a bit cleaner now that there's only one "STOP" button.  I need some help!!!  Anyone?  I am clueless as to how I need to get this working.

I'll take any suggestions 🙂

Amal Patel
0 Kudos
Message 8 of 10
(5,255 Views)
Hi Amal,
 
One solution to this problem would be to write the delivered.csv data after the while loops have finished. Khalid mentioned this in a previous post and if you are in a hurry this is the quickest fix. Simply move the entire bottom section of the code to the right side of the page and use a Flat Sequence Structure to execute the left side of your block diagram before the right. Let me know if you need more information.

Michael K.

| Michael K | Project Manager | LabVIEW R&D | National Instruments |

Message 9 of 10
(5,202 Views)

Mr. Michael,

You and Mr. Khalid were correct, I just bad wiring.  My VI works beautifully now.  I love it 🙂  Now I just have to test it on the PDA.  It'll work though, I'm confident.   I am reattaching my modified VI in case anyone in the future needs it.

Thanks again "Smiley Very Happy

Amal Patel
0 Kudos
Message 10 of 10
(5,191 Views)