LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

as introducing a subVI in a subpanel to work at the same time?

Sometimes when you have a new concept (like "How does a Sub-Panel Work?"), it helps to build "The World's Simplest Demo Program" to try the basic concept, then "make it more complicated".  Here's a Sub-Panel example.

 

My "Main", which includes the Sub-Panel and a call to a single sub-VI that will run in the Panel, is extremely simple.

Main Sub-Panel.png

This does the following:

  1. Inserts the Front Panel of a (closed) sub-VI called Do Some Work into the Sub-Panel -- this causes the Front Panel to "appear" within the sub-Panel.
  2. Wait 1 second -- this allows the User to see that the sub-VI is "doing nothing".
  3. Call the sub-VI, which starts it running, and causes its Front Panel to become "active" (with results appearing in the sub-Panel).
  4. The sub-VI continues running until the user clicks its "Stop" button.
  5. When it finishes, it waits another second, showing now the "static" Front Panel
  6. Remove the VI from the sub-Panel, show the empty sub-Panel, then exit.

It doesn't really matter what the sub-VI does.  I made a simple Uniform Random Number generator running at 50 Hz, with a running average of the last 5 numbers showing a "low-pass filter" effect, and a Stop Button to demonstrate User Interaction with this VI running in the sub-Panel.  Note that this sub-VI must be closed in order to be called to run in a sub-Panel (otherwise you get Error 1144).

Do Some Work.png

If you have LabVIEW 2016, these are both LabVIEW Snippets that you can drag to a blank LabVIEW Block Diagram and save.  This second VI I had saved as the sub-VI "Do Some Work", and is the VI whose static VI Reference is used in the main Sub-Panel demo shown first.  If you are creating them "from scratch", you should be able to simply lay down the Structures and Functions as I have done.

 

Bob Schor

Message 11 of 20
(2,003 Views)

Thank you.
Then the structure to follow is:
Subpanel -Sampling in the subVI.
-Ejecuto The subVI.
-Finalizo The subVI.
I close the subpanel.
Would this be a correct structure?

Tanks

0 Kudos
Message 12 of 20
(1,978 Views)

I'm trying to run the subVI into the subpanel using Boolean controls, so good.
But when I perform the operation I turn, I turn back to light when an error jumps 1198 and have to close the whole project to reopen it for functions.
They know that this is ...
this is my test VI.

0 Kudos
Message 13 of 20
(1,970 Views)

LabVIEW:  (Hex 0x4AE) Error 1198 The VI is not in a state compatible with this operation. Change the execution mode of the referenced VI to reentrant for this operation.

-The above error says you cannot run the VI in reentrant mode.

- What is reentrant mode: By default, when LabVIEW calls the same subVI from multiple locations within either the same VI or different VIs, only one instance of that subVI can run at a time. This limitation occurs because the subVI reserves only a single space in memory to store its data, so all instances of the subVI must take turns using that data space. However, if you configure the subVI for reentrant execution, LabVIEW can execute all instances of the subVI simultaneously. 

- LabVIEW provides the following types of reentrant VIs:

  • Non-reentrant execution—LabVIEW allocates a single data space for use by all instances of the subVI.
  • Preallocated clone reentrant execution—LabVIEW allocates a separate clone for each instance of the subVI.
  • Shared clone reentrant execution—LabVIEW initially allocates one clone per processor on the machine, creating a pool of clones for instances to share. When an instance of a subVI executes, it claims one of these preallocated clones, returning it to the pool after execution. If no clones are available when an instance needs to execute, LabVIEW allocates another clone on demand, thereby expanding the clone pool.

-Use the Start Asynchronous Call node instead of the Run VI method to run target VIs asynchronously.

-How to call VI asynchronously for parallel execution: https://zone.ni.com/reference/en-XX/help/371361J-01/lvhowto/acbr_call_clones/

-Source: https://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/reentrancy/

 

Thanks
uday
0 Kudos
Message 14 of 20
(1,966 Views)

Curious.  When I downloaded VI1198, it was set to "Non-reentrant execution".  When I combined it with the code in the earlier Project (it would have been nice to have all of the files again sent as a Zip to ensure we were all talking about the same VIs), it ran without error.

 

There are, however, several things "wrong".

  • The "usual" (for very good reasons!) way to code Event structures is to have a single Event structure inside a While Loop, with some means (an "Exit" button?) to stop the Loop.
  • Boolean controls being used in an Event structure are usually "Latch When Released" (the middle icon on the bottom row), and the Boolean control is placed inside its corresponding Event case.  This has the following effect(s):
    • Pushing the button does nothing.  The Value doesn't change, and no Event is generated.
    • Releasing the Button makes the Value go to True, and triggers the Event.
    • The next read of the Button (which is why it is placed inside the Event loop) sets it back to false.
    • The net effect of this is that the Latch When Released acts almost like a PushButton (Switch Until Released), but only generates one (not two) Events per Push/Release cycle.
  • Your code does show and unshow the Front Panel of M2000.  However, it only starts this routine -- there is no correlation between the turning off of the Front Panel (in the sub-Panel) and the stopping of M2000.  Indeed, it looks like this routine never stops, which can cause trouble the second time you run it.

The code I attached ran the sub-VI "in-line", so a necessary condition for removing the sub-VI from the sub-Panel was that the sub-VI had to exit.  In your case, you are running your sub-VI asynchronously, without waiting for it to exit.

 

Is this what you intend?  Did you want to start a parallel loop running "out-of-sight" of your main VI and periodically "take a look at" its Front Panel?  That's what your code is doing.  If that is what you want, that's what you have.

 

Bob Schor

0 Kudos
Message 15 of 20
(1,962 Views)

@udka wrote:

LabVIEW:  (Hex 0x4AE) Error 1198 The VI is not in a state compatible with this operation. Change the execution mode of the referenced VI to reentrant for this operation.

-The above error says you cannot run the VI in reentrant mode. 


No, It says that the VI needs to be re-entrant to be inserted multiple times and it currently is not. As pointed out days ago, he is trying to insert a VI that is already inserted, over and over again. You can only launch new parallel instances if the VI is reentrant.

 

Reentrancy is not the problem. The problem is that the code does not keep track if the VI is already inserted or not. It keeps pounding the head into the same wall over and over.

 

Making the VI reentrant would make things worse. After a while you would have millions of parallel instances of the same VI running and you will run out of memory.

Message 16 of 20
(1,950 Views)
Thanks for the correction altenbach 🙂
- Forum and you always teaching me.
Thanks
uday
0 Kudos
Message 17 of 20
(1,946 Views)

Hello, I think this is me this out of hand.
I just do not understand the approaches and offer.
On the one hand I understand that using a Boolean to power and another to cancel is not the most effective but the goal of this operation was to understand the operation of the VI.
On the other lado.¿ As verify that the VI is open or closed?
If I start the subVI and place it in the subpanel, this must remain active until an action close the subVI clearing the subpanel for the execution of another or the same VI.
That's the approach I want.
But seeing different structures in forums like block and some more number of blocks used. And this confuses me because the idea 100% of each block do not know and I'm starting to confuse.
I appreciate all the advice.
But if they know something text where this explained the correct use of a block would do me a favor.
In addition seguerencía or any help it is welcome

0 Kudos
Message 18 of 20
(1,925 Views)

Sorry for the confusion if i had made. Let's get things clear.

-Start new VI and Complete the following steps to load a front panel in a subpanel control.

  1. Add a subpanel control to the front panel. LabVIEW creates an Invoke Node on the block diagram with the Insert VI method selected.
  2. Add the Open VI Reference function to the left of the Invoke Node on the block diagram.
  3. Wire the path of the VI whose front panel you want to load to the vi path input of the Open VI Reference function.
  4. Right-click the vi reference output of the Open VI Reference function and select Create»Method for VI Class»Run VI from the shortcut menu and add the Invoke Node that appears on the cursor to the right of the Open VI Reference function.
  5. Wire the vi reference output of the Open VI Reference function to the vi reference input of the Run VI method.
  6. Right-click the Wait Until Done input of the Run VI method and select Create»Constant from the shortcut menu to create a Boolean constant with a value of FALSE.
  7. Wire the vi reference output of the Run VI method to the VI Ref input of the Insert VI method.
  8. Add a While Loop to the right of the Insert VI method.
  9. In the While Loop, right-click the conditional terminal and select Create Control from the shortcut menu to create a stop button.
  10. Add the Wait Until Next ms Multiple function inside the While Loop and wire a numeric constant to the millisecond multiple input. Specify the number of milliseconds you want to lapse when the VI runs.
  11. Add the Close Reference function to the right of the While Loop.
  12. Wire the vi reference output of the Run VI method through the While Loop and to the reference input of the Close Reference function.
    Refer to the following block diagram for an example of loading a front panel in a subpanel control.
  13. Wire all error in and error out terminals on the block diagram.

-Now notice that you can load a subvi named Untitled5.vi opens in subpanel and waits until you press stop button.

-Now Open VI reference creates the reference to the vi which you want to run.

-VI run Invoke method will make the VI to start executing.

-Subpanel Insert method will insert the subvi front panel into Subpanel.

-The while loop is to ensure the vi is escuting and keep the refernce alive.

-When you press stop the reference is closed and the vi will be remove from the memory.

 

-You can check if a vi is running or not by creating property node and selecting the execution state

 

P.S. whenever In confusion start with fresh VI rather than mixing up with already existing VI and complicating it. I hope above post helps if not completely ignore and proceed as suggested by others.

Thanks
uday
0 Kudos
Message 19 of 20
(1,919 Views)

Hi, I'm back :). I've been trying to work and actually I work, the problem is that when re-run the subVI this works but does not open (not displayed on the SubVI but if ejectuta).
I tried to change the call or putting it as reentrant but still can not get display ...
Any ideas?
thank you very much

0 Kudos
Message 20 of 20
(1,869 Views)