LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the front panel and the terminals of a subVI simultaneously

Solved!
Go to solution

How can I re-use the front panel of a sub-VI and have access to the terminals at the same time?

 

I found out that I can re-use the front panel using the subpanel-control. In this case I don't have access to the terminals of the sub-VI. But I need them in my calling VI.

 

As soon as I use the sub-VI in my block diagram and wire the terminals I get the Error 1000: The VI is not in a state compatible with this operation. I found out that this error occures if I call a VI multiple times. So as I said, if I remove the SubVI from the block diagram, the calling VI works, but I don't have access to the terminals any more.

0 Kudos
Message 1 of 21
(5,307 Views)

If you place subVI into subpanel, it work "long". And you can't recall it until first call finished.
For send new data you can use queues or set controls values by ref

cv.png

Message 2 of 21
(5,289 Views)

I'm not sure what you mean by "reuse the Front Panel of a sub-VI".  The sub-VI, however it is called, will obey the same rules of the Principle of Data Flow whether you can see its Front Panel or not.  That is, you can only pass data into it when you call it, and can only pass data out of it when it exits.  As Artem has pointed out, however, you can sometimes "cheat" a little -- if you pass in a reference to a control in your main VI, then the sub-VI can set that Control using a Property Node of the Reference.  Similarly, if you pass a Queue (reference) into the sub-VI, the sub-VI can Dequeue (read) or Enqueue (write) (but not both!) and exchange data.

 

What the sub-Panel lets you do is to view the sub-VI's Front Panel.  Ordinarily, you don't need (or want) to do this, but if the sub-VI, say, displays a graph of some data it is acquiring, you may want to see this graph (I've done this, for example).  But unless you are using references or queue-like structures, the only way to pass data in multiple times to the sub-VI is, like any other sub-VI, you have to call it multiple times, which means it has to exit before being called (unless, of course, it is called as a reentrant clone, and you get multiple instances running at the same time, which I don't think is what you want to do ...).

 

Bob Schor

0 Kudos
Message 3 of 21
(5,269 Views)
I'm not sure what you mean by "reuse the Front Panel of a sub-VI"

Thanks for answering. My goal is to control a power supply using RS232. This power supply has four channels. The user shall set up all four channels and hit a "Transfer to Power Supply"-Button.

I have modeled one power channel as a sub-vi NT-Single. It has controls to enter the voltage (spannung), the current (strom) and there is a "Channel 4" option visible in the block diagram where I can tell the subvi NT-Single which channel to program. Also there is an error IN and OUT and a connection to the VISA.2018-08-24 SubVI.png

 The VISA to the power supply should be opened by the controlling VI, lets call it NT-Master. NT-Master shall open the VISA connection, initialize things, call NT-Single four times and close the VISA again.

I have included NT-Single in NT-Master using the Select VI... option. This gives me access to the VISA IN/OUT and ERROR IN/OUT but the front panel is missing.

I have included NT-Single in NT-Master using the construct shown. This has lead to the confusion described in my first posting. 2018-08-24 SubVI 2.png

 Thanks, Christian

0 Kudos
Message 4 of 21
(5,262 Views)

Let's step back a bit.  NT-Master opens VISA, then calls NT-Single four times (once for each of the 4 PS's being set), then it closes VISA and exits.

 

Presumably you could run NT-Master just by itself, just to see that it works correctly (it is, in fact, a Very Good Idea to test sub-systems before building them into the Final Big Monstrosity That Does Everything).  Does NT-Master need to "see" the Front panel of NS-Single?  [Are you, perhaps, setting the Power Supplies "by hand", rather than giving them some values you just pass to them?].  If so, then NT-Single needs to be in a sub-Panel of NT-Master.  You also (probably) want it to completely fill the Front Panel of NT-Master so that when NT-Master runs, it just "sees" NT-Single #1, NT-Single #2, NT-Single #3, NT-Single #4, then exits.  There's a neat trick to accomplish this.  In the LabVIEW Tools Network (which you get to by running VIPM), there are a set of Tools called the OpenG Toolkit.  Download and install them.  In the Application Palette of OpenG, there is the function "Fit VI Window to Largest Decoration".  So draw a "Decoration" (I use a Raised Frame) around your Sub-Panel, and put the OpenG function as the first function in NT-Master.  Now, when it runs, all you'll see is the sub-panel.

 

Incidentally, you don't need to (and probably shouldn't) use Run VI when you are using sub-Panels.  Just open the sub-Panel first, then run your sub-VI in the "normal way" by putting it next on the Error Line and passing it any arguments it needs.  When it finishes, it will exit (and you can close the sub-Panel if you wish).

 

OK, so NT-Master is now running as you want, but now you want to run NT-Master as a sub-VI in My Main Program, and be able to see NT-Single in the Window.  By now, you probably know what to do -- open a sub-Panel in My Main Program, stuff NT-Master in it, and then call NT-Master, again as an ordinary sub-VI.  NT-Master calls NT-Single 4 times, showing NT-Single as it's Front Panel, so NT-Single's Front Panel is being viewed in My Main Program, and when NT-Master finishes, you can close the sub-Panel in My Main Program (if you wish).

 

Hope this gets you where you want to go.

 

Bob Schor

Message 5 of 21
(5,246 Views)

Bob,  

 

Look at the picture....top right...

 

Then see if you can explain the importance of the.......

 

Connector Pane to the OP

Smiley Surprised


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 21
(5,237 Views)

Okay,  Bob's busy.

 

I do not have a PC so,  I have to  try this with TEXT.  Oh, the irony of explaining a G IDE in words.

 

The glyph near the right at the top of your vi is the connector pane.

 

Right click on it and several patterns will be selectable.

 

VI inputs and outputs can be 'wired' to any of the areas on the connector Pane ,CP, for short. 

 

The most common pane used is the 4,2,2,4 pane.  It is  easy to wire together on a block diagram.   4,2,2,4 refers to the vertical stacks of terminals from l to r.

 

Use the wiring tool to attach the front panel objects to a CP terminal. 

 

Inputs on th left. Outputs on the right.  Unless you use Japanese or ancient Hebrew. 


"Should be" isn't "Is" -Jay
Message 7 of 21
(5,229 Views)

Sorry, Jeff, home, dinner, fixing some things around the house, then return here.

 

From time to time, a student will come to me wanting to learn LabVIEW, usually with a project in mind.  They've played a bit, have a few DAQ Assistants and other horrors on a single humongous Block Diagram, and say "This almost works" ...

 

We usually start by my asking What are you trying to do.  They proceed to tell me how they are trying to do it, but when I insist, they say something like "Step 1, then Step 2, then Step 3 until Condition 4, then Step 5".  We don't actually call the sub-VIs "Step 1", but the light dawns that they should break the Big Problem into Little Unified Pieces and clean up the Block Diagram.

 

I then hand them a sheet with some Style Rules for LabVIEW.  This includes:

  • Every Project needs a LabVIEW Project.
  • Every Sub-VI needs an Icon, a Description, and the 4-2-2-4 Connector Pane.
  • Every Sub-VI needs Error In and Error Out in the lower terminals.
  • Strive for only one or two inputs (not counting Error) in most sub-VIs (I know, my capitalization is inconsistent, so Sue Me ...)
  • Document, Document, Document (preferably at least something before you start coding).
  • Use Version Control!!!  Daily, if not more often.

Sometimes they listen.  Sometimes I never see them again.

 

To the O.P. -- If you read and understand what Jeff and I are going on about, and want to try to clean up your NT-Master and NT-Single a bit and attach them, I (and probably others) will take a look at it over the weekend and see if I can't illustrate some of what we've been trying to tell you.  If you are feeling really brave (and have no proprietary information in your code), compress the folder containing the LabVIEW Project file and all the VIs/TypeDefs in your Project and attach that.  I'll only concentrate on the sub-Panel story ...

 

Bob Schor

Message 8 of 21
(5,214 Views)

I have attached the project.

The user shall open NT-Master.vi and see a front panel, where he can set up the voltages, currents and some other stuff for the channels 1 to 4 of the power supply.

At the moment, how I include the sub-vi NT-Single.vi, he sees nothing on the front panel of the NT-Master.vi. Only Error Out, VISA Resource name and a stop button. If the user wants to set the parameters of the individual channels he has to click on the block diagram on each SubVI NT-Single.vi, set up the voltage, make it DEFAULT and save the VI. This is not what I want.

I could draw four voltage controls on the front panel of NT-Master.vi. And four current controls. And wire them to the NT-Single.vi, which I call four times. But this is not what I want. I want to draw the voltage and current controls ONE TIME and re-use them.

I will have a look at the tips from Bob next, the one with the library.

Thanks for your help.

Christian

0 Kudos
Message 9 of 21
(5,186 Views)

So there's enough that is New and Different that I decided to try to make a BS Master and BS Single, and immediately ran into a question/problem.  How does Single work?  What are the purposes of the three controls?

 

Here's what I'm guessing (only after I coded much of this, and realized I had Questions, comes from not following my own advice, "Understand What you want to do, don't worry initially about How to do it".

 

I think you want to call Single with a Channel number.  You configure that Channel, then what?  You have two functions that I think set V and A, and one that does something else (that I don't understand).  But what do you want Single to do?

 

I would think you would want it to first show you the current values of V, A, and Kanal (whatever that is), allow you to change/update one or all of them, then push an "OK" button to say you are finished.

 

Once we get Single figured out, Master is easy -- you have a Channel Control and a Done Button.  Whenever the Channel Control is changed, Single is called.  When All Done is pushed, Master is done.  Master also shows the current  version of Single's Front Panel in a sub-Panel.

 

But I'm still unclear how Single works with the other routines.  Maybe you never read the values, you can only set them (so you have to pass in the current values to initialize the Controls to their current values).  Please clarify.  I'll try to get this finished tonight -- now I have to go do "real work".

 

Bob Schor

0 Kudos
Message 10 of 21
(5,156 Views)