From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass variables (arrays, boolean etc.) from main VI to subVI called in event structures

Hello,

 

I have created an event structure to call different subVI's to do different tasks. Picture 1. When I select for example headgates, it brings up a new window with the front panel of the headgates subvi. What I want to do is push variables from my main VI to the headgates subVI. I have wired subvi's before using wires and connecting arrays, but the method I used from a tutorial online does not explain how to push variables such as arrays from the main VI to the sub. I have tried local and global variables ,but my I don't know what I am doing with them and the labview help online is all but useless in explaining in simple terms how to use each object.

 

Thank you.

Download All
0 Kudos
Message 1 of 19
(2,806 Views)

Use a VI>Control Value>Set or VI>Control Value>Set Multiple method before running the VI.

Message 2 of 19
(2,763 Views)

Connect your required terminals on connector pane as shown below, and use it vi wherever you need just pass the values into it.

Pass Value.png

Message 3 of 19
(2,753 Views)

@SabariSaravanan.M wrote:

Connect your required terminals on connector pane as shown below, and use it vi wherever you need just pass the values into it.

Pass Value.png


That doesn't help when dynamically starting a VI, as OP tries to do.

Message 4 of 19
(2,746 Views)

@stevenette wrote:

I have tried local and global variables ,but my I don't know what I am doing with them and the labview help online is all but useless in explaining in simple terms how to use each object.

 


Local variables are local to each subVI, but global variables should work just fine. What did you try? Did you see the help?

In lieu of global variables, you could also do an action engine if you need more intelligence/modes.

 

Do you need to set these values only at the subVI call or also once the subVI is running? You could launch the subVI using "Start Asynchronous Call" and wire some inputs. For later, use the global or action engine.

 

Another option would be the use of queues.

 

Also make sure to keep the terminology clear. You are pushing values, not variables (even though the values are variable :D).

 

As you can see, there is a large variety of solutions, but we cannot really tell what's best unless we have more information. Of course we could provide more specific help if you would attach the actual VIs, and not just truncated, incomplete pictures. (There are quite a few questionable code constructs visible.)

0 Kudos
Message 5 of 19
(2,726 Views)

Another solution is to use a call and forget dynamic call (Start Asynchronous Call). That would give you the VI connector pane as interface, except the VI runs dynamically. You can then wire the inputs just like a normal subVI.

0 Kudos
Message 6 of 19
(2,701 Views)

Asynch.png

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 19
(2,689 Views)

@Yamaeda wrote:

Asynch.png


But that will wait until the VI is done...

Message 8 of 19
(2,685 Views)

Ok, I have created 2 new vi's to better explain my position. When I create a main VI and a subVI, I can easily pass data through global variables back and forth. When opening up a subVI through the main VI, I no longer can pass data in real time. Please see my examples to try yourself. Thank you.

 

P.S. I just used the pull down menu item labeled "Headgates" so that is the only one that will explain what I am trying.

Download All
0 Kudos
Message 9 of 19
(2,675 Views)

First you were talking about passing from Main to Sub.

 

Now you are talking about messages both ways.

 

You really should be using queues in that case.

0 Kudos
Message 10 of 19
(2,669 Views)