LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best Practices for Gracefull Application exit/close

I have a production labview application for testing brain scanners that employs 100's of subvi's.  The system was designed by a very green labview developer originally and has been incrementally updated with best practices over the past 6 years.

 

It is clear that the application is not using the right method for shutting down and it is my goal to bring it up to standards.  Please post links and/or solutions and examples of how to properly startup an application or close an application.

 

Problems:

  Pressing the Windows X button to close the program will close the panel but the program instance continues to run and the comm ports (visa) are not released.  (the only way to close it after this is to terminate the task in task manager)

  A global stop variable is currently what is used to propogate the program stop command to all the vi's, the user must remeber to press the stop button before closing the program.

  The program doesn't stop immediatly as some parts of the code contain loops which are terminated by the global variable, but the loops will run once before terminating.

  

 

If there is a standard architecture/shutdown procedure for writing vi's please point me to examples, I already check the Labview Best Practices page, but it didn't give specifics it just stated that this is important.

I also did a search for this in the forum but found answers like this "Exiting a LabVIEW Application" Which did not give links or specific enough information.

 

-Regards

eximo
_______________________________________________
UofL Bioengineering M.S.
Neuronetrix

"I had rather be right than be president" -Henry Clay
0 Kudos
Message 1 of 12
(9,191 Views)

I use the Panel Close? filter event and discard it and use the event to signal to my other loops/modules that my software should shut down. I normally do this either via user events or if I'm using a queued state machine (which I generally do for each of my modules) then I enqueue a 'shutdown' message where each VI will close its references (e.g. hardware/file) and stop the loop.

 

If it's just a simple VI, I can sometimes be lazy and use local variables to tell a simple loop to exit.

 

Finally, once all of the modules have finished, use the FP.Close method to close the top level VI and the application should leave memory (once everything else has finished running).

 

This *seems* to be the most recommended way of doing things but I'm sure others will pipe up with other suggestions!

 

The main thing is discarding the panel close event and using it to signal the rest of your application to shut down. You can leave your global for 'stopping' the other loops - just write a True to that inside the Panel Close? event but a better method is to use some sort of communications method (queue/event) to tell the rest of your application to shut down.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 2 of 12
(9,173 Views)

If you don't want the user to be able to close the window by using the red x in the upper right hand corner, do the following.  From either the block diagram or front panel go File -> VI Properties.  In the drop down menu select Window Appearance.  Now click on Customize.  You should see a check box that says "Allow user to close window" on the right.  Deselect that box and the user won't be able to close the window.

 

I usually have a while loop with an event structure that monitors the user actions with the main vi.  For example, if the user hits the stop button, my stop value change user event will execute and take the new value and place it in a notifier that is passed to the various subVIs.  Each of the subVIs will be monitoring this notifier and will stop execution upon seeing a TRUE.

 

Another nice option is on the same menu screen that you deselected "Allow user to close window."  On the left is the option "Show front panel when called."  Once that is selected you can now select "Close afterwards if originally closed."  So now the vi will stop executing upon receiving a TRUE from the notifier and close its front panel.

 

These are just some of the methods that I use.  Hopefully they are helpful.

Message 3 of 12
(9,167 Views)

I fully agree with Sam_Sharp here.  Use the Event Structure and the Panel Close? filter event.  My opinion is that a GUI should NEVER have a Stop button.  You don't see them in Office or any other programs.  Why should LabVIEW programs be any different?  And disabling that Windows 'X' just confuses users.

 

If you are using parallel modules, you should have a good communication scheme to pass data around, usually queues or User Events.  Regardless, there should be a way to send a Stop command.  I really try to avoid using the Stop Global.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 12
(9,137 Views)

When using a Panel Close? event, you may want to add in a "Are you sure" dialog so that a user doesn't accidentally close an app they meant to keep running.  It could even be dangerous if the app is running some sort of mechanical hardware.

 

I feel there are 3 different types of Close behaviors, depending on the application.

 

1.  If it is something simple like a Windows Explorer window, clicking X to close is usually okay, and if it is a mistake, they can easily reopen.  There the Panel close just goes ahead and initiates the shutdown commands and closes the other loops.

 

2. Something like Excel or Word.  If things are kind of wrapped up, hitting X to close can just go ahead and close it.  But if you have a document where you haven't saved it yet and don't want to lose your work, then hitting X should trigger a dialog that says "Unsaved changes,  Close, Cancel, Save"  or something like that.

 

3.  An app that you don't want to have close unless the user is certain like something that runs a test stand.  You want to give the person and opportunity to set all controls back to defaults like zero speed, zero load.  Those should always have an "Are you sure?" dialog to give them a chance to back out of a close.

Message 5 of 12
(9,100 Views)

Any admin's have any suggested links or examples?

-Regards

eximo
_______________________________________________
UofL Bioengineering M.S.
Neuronetrix

"I had rather be right than be president" -Henry Clay
0 Kudos
Message 6 of 12
(9,073 Views)
As a matter of fact, check the link in my signature block. And for what it is worth, there are a few NI folk that monitor the forum, but the majority of us are volunteers who like helping out.

Concerning your specific problems, when I an working on a project, one of the first things I put in place are standard mechanisms for things like starting and stopping the application, reporting errors and retrieving configuration data. Once that is in place I can start creating the needed functionality.

Likewise, when I am called on to maintain existing code I start in much the same way. What are the major subsystems? How are the launched? What can cause them to stop? What is done with errors that occur? Where are the setups coming from?

In addition to the "Panel Close?" Event mentioned above, there should also be one place in the application that checks for the "Application Instance Close?" Event. It is the event Windows fires when it wants to shutdown. The handler for that event should also initiate an application shutdown.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 7 of 12
(9,036 Views)

Hi Crossrulz, 

 

Can you show an example of this method to exit an application? (event structure + panel close? filter event) 

 

Could you give an eye to what I did and tell me if I badly interpreted what you suggested? It is in the right lower corner of my VI. 

 

Thanks

0 Kudos
Message 8 of 12
(8,555 Views)

raflouk wrote:

Could you give an eye to what I did and tell me if I badly interpreted what you suggested? It is in the right lower corner of my VI. 


You broke one MAJOR rule about Event Structures: you should only have 1 in a VI.  There are rare exceptions, but by no means should you have more than 1 in a single loop.  Do you not know how to make different event cases inside of a single structure?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 12
(8,527 Views)

Nope, I've never heard about that.

Do I just need to go in "Edit event handled by this case" and add a case for any button that might start execution of a function? 

Furthermore I suppose you understood that each event structure in my design is here to execute a specific function after clicking or modifiying button or ring menu. If I delete all the event structure I'll lose it right ? What do you advice me to fix it? Should I talk about it in another topic? 

 

Thanks

0 Kudos
Message 10 of 12
(8,508 Views)