LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Working with the SubPanel container

I'm using a subpanel in a project.  The VI called in this subpanel has some "clean-up" code associated with it that I would like to have run prior to the VI leaving memory.  The "clean-up" code includes de-asserting the boolean lines within a DAQmx task, cleasning up the task, and then writing some files that contain the value of some cluster controls into an XML file.

Between the main VI and the subpanneled VI I'm using an AE ("Action Engine") VI to communicate some simple messages.  One of those simple messages is a "stop" signal that should cause the VI that is called in the SubPanel to start executing its "clean-up" code before stopping.

Did some research and looked at some example VIs and it looks like once the VI containing the Subpanel stops execution the VI within the Subpanel loses its reference and is removed from memory.  This worries me that there will be a race condition between the two VIs.  It is essential for the VI in the Subpanel to execute its clean-up code.

I don't like the solutions I've come up with so far, but here they are:

1. Add a time-delay between when the stop signal is sent to the VI in the SubPanel using the AE and when the main VI starts executing its own clean-up code.  I don't like this because what is a good value?  Probably 500ms is plenty of time for any computer system, but what if the hard drive is thrashing on some other operation and there is some random lag that occures?

2. Send a signal back to the main VI saying "I'm done stopping" and be waiting for that return signal.  I like this way better, but it still seems like a very messy code approach.  Also, I may want to execute the main VI w/o the subpanel and I would hate to have my main VI hang as it waits for a signal from a subpanel VI that is not running.

so both solutions seem "hookey."  Any other solutions?  What about the event's "Panel Close" and/or "Panel Close?" under <This VI> within an event structure?  Would these execute properly in my scenario?
0 Kudos
Message 1 of 4
(2,937 Views)

In solution 2 are you talking about doing it in the following way:

1. Event structure to capture the close

2. Send a notifier to notify the subvi to start closing. You can have it done sequentially done by having the subvi receive a notification and in turn send a notification to the next subvi to initiate a shutdown.

3. The subvi that is last to finish send a notfication to the main VI to shutdown

4. The main vi finally completes the shutdown.

0 Kudos
Message 2 of 4
(2,924 Views)

Hi Nickerbocker,

It sounds like what you would like to happen is have the subpanel execute the closing code then close followed by the main VI closing. If you wired the stop control through the subpanel before running it to the main VI stop procedure you should be able to accomplish this. You can then add the closing code inside or sequencially after the subpanel VI.

It would help if you could like to include your VI or pictures of the specific VI where the subpanel is called. Let me know if you have any other questions or if I am incorrect in my assumptions.

Sappster
0 Kudos
Message 3 of 4
(2,896 Views)
It feels like there's some better solution here, but one standard way to deal with this problem is to have the VI in the subpanel open a reference to itself when it starts executing, and then only close this reference when it finishes. What this means is that if the main VI that has a reference to the VI in the subpanel stops executing and that reference closes, it's not the last open reference to the subpanel VI, so LabVIEW won't remove it from memory. This will provide you the protection you need against the race condition.




Message Edited by Jarrod S. on 06-10-2008 04:26 PM
Jarrod S.
National Instruments
0 Kudos
Message 4 of 4
(2,890 Views)