02-25-2015 11:03 AM
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.
02-25-2015 11:35 AM - edited 02-25-2015 11:36 AM
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.
02-25-2015 11:39 AM
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.
02-25-2015 01:21 PM
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.
02-25-2015 09:04 PM
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.
02-26-2015 08:08 AM
Any admin's have any suggested links or examples?
02-26-2015 08:05 PM
12-22-2016 06:47 AM
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
12-22-2016 08:15 PM
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?
12-23-2016 06:21 AM
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