LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass data from one VI to another one

Hi,
I try to control a event structure in a VI with a boolean command from a second VI. I have been advised to "build a connector to pass any data from one VI to another one".
Below an simple example: my goal is MyVItwo gives the result of a 2 numbers addition only when the boolean "MyBooléen" value changes in MyVIone.
How can I realise this?
Thanks
PB
0 Kudos
Message 1 of 8
(7,951 Views)
Hello.

When they say "build a connector to pass any data from one VI to another one" they are referring on how to pass data from a VI to a subVI only. From what I can see in your example, you have 2 main VIs, but no subVIs, which means that you cannot use a connector to pass data from one to the other one.

There are several ways in which you can pass data from one VI to another one. An easy one is the use of global variables. Another easy method is the use of datasocket.

I am attaching an example of how to do this using global variables. You must be aware that it is recommended that you useglobal variables ONLY when it is necessary, like in this case. But, if you do not need to use more than one VI, or you can use a subVI then it is better to do that and use the subVI's connector pane to pass data to it.

Alejandro
0 Kudos
Message 2 of 8
(7,940 Views)
Sorry, I forgot to save the VIs in LabVIEW 7.0 version.

This attachment should be the correct version:
0 Kudos
Message 3 of 8
(7,933 Views)
It is not entirely clear what you are trying to do. I think that what you want is a main vi/subvi setup. The boolean control would be in the main vi and would be monitored by an event structure. When the value of the boolean changes the subvi would be activated. I have attached an example showing how this is done.

In order to use a vi as a subvi you build a connector box. In order to do this you just right click on the vi icon at the top right of the front panel and select show connector. You then wire connections on the connector block to controls on the front panel. You insert the subvi into your main vi by choosing "Select a vi" on the functions pallette and browsing to the subvi.

If you absolutely have to pass the data from one vi to another while running in parallel there are a number of ways to do it. Global variables will certainly work but are generally avoided by experienced LabVIEW programmers due to their potential caveats and the break in data flow. An alternative to global variables is the functional global, also called a LV2 style global. This is basically a non-reentrant subvi with an unitialized shift register which allows for data to be stored. For more information search this forum for LV2 globals.

Another alternative is to obtain a reference to the control and operate on that reference. You could also use queues, notifiers, or occurences. Search the examples which shipped with LabVIEW for examples on using these operators.

If you need any more information feel free to post back here.
0 Kudos
Message 4 of 8
(7,936 Views)
Oops. I forgot to attach the vis. Here they are.
0 Kudos
Message 5 of 8
(7,929 Views)
Hello,

I am interested in your attached VI, but could it be possible you send me back it in the 7.0 Labview version. I can not read 7.1 version. Thank you very much.

PB
0 Kudos
Message 6 of 8
(7,908 Views)
Here it is in version 7.0.
0 Kudos
Message 7 of 8
(7,890 Views)
I would strongly recommend against ever using globals. In twelve years of LabVIEW development, I have only seen one instance where they were truly needed. They have too may problems with synchronization. LabVIEW's multithreaded environment is confusing enough without adding more issues.

InterVI communication is well represented. You can use queues, notifiers, occurrences, events, or functional globals. Attached is an example of the functionality you want using queues (LV7.0). It consumes no CPU time until you do something on the UI.
Message 8 of 8
(7,866 Views)