LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a variable from a subvi to a vi in real time?

Solved!
Go to solution

The main calls a subvi where there is a for loop. Is it possible to pass a variable from inside the for loop to the main in real time, that is while the for loop is still running? 

I tried with a global variable. The global itself is updated, but if I put in the main the global variable with a wire to an indicator, the indicatore doesn't update until the sub vi has not completely passed the control back to the main. 

Is it possible to do that?

0 Kudos
Message 1 of 11
(6,922 Views)

Of course this is easily possible with a global (not pretty, but posssible). 😉

 

You are doing something wrong. Please show us your code. Mostl likely you need to poll the variable in a parallel loop if the main loop is stalled due to the subVI call. Think dataflow!

 

 

0 Kudos
Message 2 of 11
(6,915 Views)

Yes, Use a Control Reference and a Property Node Value and the sub VI will update the value in real time to the Front panel and the main vi. But if the variable value in the top VI is passed in a wire it will not update the value of the wire until the loop starts a new iteration.  You must be very careful and control the order of execution or you could have flaky code due to race conditions. Remember LabView processes everything in parallel and if you are using a reference and property you are not sure when it updates. 

0 Kudos
Message 3 of 11
(6,905 Views)

@Dave_Brandt wrote:

Yes, Use a Control Reference and a Property Node Value and the sub VI will update the value in real time to the Front panel and the main vi. But if the variable value in the top VI is passed in a wire it will not update the value of the wire until the loop starts a new iteration.  You must be very careful and control the order of execution or you could have flaky code due to race conditions. Remember LabView processes everything in parallel and if you are using a reference and property you are not sure when it updates. 


That won't work if we are in Real Time.

 

 

What you really want to do is remove the loop out of the subVI and adjust your main VI's loop accordingly.  That way you can update your indicator after each time your subVI runs.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 11
(6,872 Views)

hi

can it work with an "Action Engine" ? you put a write state in the AE in the for loop of the subvi and read it elsewhere

n

0 Kudos
Message 5 of 11
(6,846 Views)

Hi, here I attached a simplified skeleton of what I would like to do. I have a for loop in the subvi, and I want to check the percentage of executed for loop (because in the original file it takes a very long time, and I need to check how much time I have to wait for it to be finished). 

The simplified version in the attachment works. However I would prefer not to have a while loop to poll the global variable, since it waste a percentage of the cpu time which could be used better to perform calculations


@altenbach wrote:

Of course this is easily possible with a global (not pretty, but posssible). 😉

 

You are doing something wrong. Please show us your code. Mostl likely you need to poll the variable in a parallel loop if the main loop is stalled due to the subVI call. Think dataflow!

 

 



Download All
0 Kudos
Message 6 of 11
(6,794 Views)

What is your target? By real time do you mean a real time target such as an fpga host vi or executable?

0 Kudos
Message 7 of 11
(6,784 Views)

Might be misunderstanding, but this might be what you want:

https://decibel.ni.com/content/docs/DOC-17541

Message 8 of 11
(6,782 Views)
Solution
Accepted by gnappo

If you are running in windows see example vi

Download All
Message 9 of 11
(6,773 Views)

Hi, here I attached a simplified skeleton of what I would like to do. I have a for loop in the subvi, and I want to check the percentage of executed for loop (because in the original file it takes a very long time, and I need to check how much time I have to wait for it to be finished). 

The simplified version in the attachment works. However I would prefer not to have a while loop to poll the global variable, since it waste a percentage of the cpu time which could be used better to perform calculations. 


Yes, the main loop has to keep iterating to update the FP indicator.  If you wait int he main diagram for the subVI to finish all its for loops then you won't be able to update things.  You have a few of choices if you don't want parallel polling.

 

Make the For loop in the main diagram and the math in the subVI, then the main diagram can update the indicator.

 

Second, you can pass the FP progress indicator reference to the SubVI and it can update the FP indictor from within the loop.

 

And even more elaborate, pass a USER Event reference to the SubVI and it can trigger an even every iteration to update the front panel and you will have an event structure in a while loop that will respond to these events.   This won't take CPU until the event is triggered and then updates the FP display.

LabVIEW ChampionLabVIEW Channel Wires

Message 10 of 11
(6,757 Views)