LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Swapping Ui's dynamically

Hello,

I would like to swap between 2 Front panels and I found a solution but I bet there's a better one I couldn't think of. 

 

Julsbng_0-1707056111305.png

Julsbng_1-1707056121112.png

Here just the thought behind it. I would have to do this with more Indicators and controls to swap some parts of the UI. I got 2 options in the Ring and if one is changed the front end should adept. 

 

Is there a way to build 2 separate Vis with a separate front end and just call them with the corresponding UI. I don't want them to run simultaneously. 

 

Best regards 

 

 

0 Kudos
Message 1 of 20
(11,933 Views)

The answer is "Yes" (as opposed to the children's song "And the Word is No").  There is something called a Sub-Panel in LabVIEW (on the Front Panel screen, it in in the "Layout" menu).

    Let's say you have two VIs, call them "One" and "Two", and a third VI, call it "Master" with a switch that says which VI you want to be "visible" and "controllable".

     Ideally, you configure "One" and "Two" so that their Front Panels are the same size.  [The way I do this is to put a Decoration like a Flat Box under my sub-VIs Controls and Indicators, and make it the same size for both "One" and "Two".  I also arrange the Run-Time Window of both so it "fits" the identically-sized VIs.]

     On Master, you create a sub-Panel that's the size of the (now identical) Front Panel of One and Two.  When you create the sub-Panel (and name it), you'll find an Invoke Node (which you can name "Master") called "Insert VI" that you can put a reference to the VI you want to run in the sub-Panel Window.

     There's a good example that ships with LabVIEW showing three identically-sized sub-Panels all actively running, and letting you view their Front Panels by choosing which one you want to observe.  The Example notes that you can't "pass values" (easily) to these sub-Panels, but you can give them their own "Front Panel" controls (for example, if they plot a Graph, you can have controls to change the Y scale).  You can also make the sub-VIs get data asynchronously (via a Queue or Channel Wire) so that they continually update whether or not you are viewing them.

 

Bob Schor

0 Kudos
Message 2 of 20
(11,892 Views)

Sometimes I use the "Visible" property on a specific control.  (Note that you don't need to disable a hidden control.)

Often I'll use a tab control.

Message 3 of 20
(11,890 Views)

Thats what i wanted thank you very much! I will see if i can run this like you said. 
Best regards. 

 

0 Kudos
Message 4 of 20
(11,885 Views)

So if i hide a control its also disabled or is it running in the background? 

0 Kudos
Message 5 of 20
(11,879 Views)

If you left it running, it is still running.  About 8 years ago, I wrote a Behavior Monitoring program that (in priniciple) monitored up to 24 Stations (we usually used around 10 at a time).  Each had a Video camera and an "Event Detector", and when the Event Detector fired, we wanted to save a video from 1 second before the event to 4 seconds after.  Events occurred irregularly, about 4-5/hour.

 

We wrote a "Station" routine for one Camera, one Event Detector, and one Video out, cloned it as many times as we had Stations, and had an array of Clones that we could put into a sub-Panel if we wanted to "look at the Video" over the 2-hour period we were monitoring.  When we pushed the button for "Station 17", we released the Station that was using the sub-Panel and put Station 17's Reference in, and we were watching the feed from Station 17's camera.  Of course, at the end, we had to shut down all the running Stations (and their Event Detectors, Cameras, and Videos).

 

Bob Schor

Message 6 of 20
(11,863 Views)

Hello i got the Vi´s Done now and want to build the master but im not getting it done right:

 

Julsbng_0-1709566042697.png

This error occures when i put the Ring and run vi inside the loop. 

 

Julsbng_1-1709566095083.png

When i put it outside i got the problem that I cannot change the vi. 

Julsbng_2-1709566140361.png

It did not swap

Julsbng_3-1709566166971.png

Any idea how to fix this? Best regards

0 Kudos
Message 7 of 20
(10,786 Views)

There are multiple things you need to do with subPanels, which may not be shown in your images.

 

  1. You can use the "Call and Forget" mode to dynamically call your VI, instead of the older Run VI method. This will not make a difference except Call and Forget is a bit more modern and allows you set controls when called rather than call another method.
  2. If the VI is already running, then do not call the "Run VI" method to run the VI again, just insert the reference into the subPanel.
  3. When you want to change VIs in the subPanel, you need to remove the VI form the subPanel. There is a method for the subPanel called Remove VI.

You need to decide how you want your system to run. When you select the VI starts and is inserted into the subPanel, when finished does the subPanel VI close, or does it keep running. Do you want to insert VI's that are always running into the subPanel? All of this will affect how you call your VI's. 

Message 8 of 20
(10,763 Views)

Hello, 

Thanks for the fast reply. I want to start the master Vi from the desktop. After that the Vi selected by the Ring should be visible i the sub panel and be running until i press stop or swap to the other vi with the ring. Both Vis are using similar output and inputs, just wanted to mention if this effects something. 

 Where do i have to place the Call and Forget mode. Inside or outside the loop? Same with the Remove Vi

0 Kudos
Message 9 of 20
(10,758 Views)

So Everythig  is working except for switching the Vis....

They are both loadinh running and working. 

So i need a solution for exchanging them while the programm is running. 

 

Julsbng_2-1709569651734.png

 

 

Julsbng_0-1709569576117.png

 

I also need to know how to align them to the subpanel automatically. Now i need to use the scroll bar to align them. The vis have the same size as the Subpanel but i dont get it how i can align them automatically. Also any ideas on this? I read the post i marked as solution and i understand the concept but i dont know how i do the last step. One of the Vis is placed very good but i still can use the scrollbar. the other one is misplaced havily. 

Julsbng_1-1709569626903.png

 

0 Kudos
Message 10 of 20
(10,749 Views)