LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

output of a for loop read in a subvi

Hi, I am a newbie to labview programming and am learning everything by trial and error, so please don't laugh if this sounds obvious or dumb:D.

I have a for loop in a vi(subvi.vi) with a value that changes in the loop with each iteration. In main.vi I am calling the subvi, but I need to see the value change that happens in the loop in real time in Main. is this possible.
So far I can't read this output in main.vi until the loop in subvi has terminated.. can someone please explain why this happens? and is there anyway to get around this?

I've attached a version of this that I tired for testing.

Thank you and cheers

Download All
0 Kudos
Message 1 of 3
(2,638 Views)
My first thought was "Gee, such a big front panel for just one control...".

General answer: What you're seeing is by design, as this is how LabVIEW, or any other programming language for that matter, works. If you call a function, you don't get the results of that function until that function is finished. In order for the caller to see the function twiddling something is to have the function write to a variable that is visible to both the function and the main program. Computer Science 101. How to accomplish this varies with each programming language. With LabVIEW there's a number of ways to do this, such as using global variables or passing in a control reference so the subVI can update the value of a control on the calling VI's front panel.

Specific answer to your VIs: It seems you want to see the value of the loop iteration index as it's running from the main VI. If so, the simplest solution is to pass in a control reference of the "Value to be read" indicator on the front panel of "Main" to the subVI so the subVI can update the "Value to be read" indicator on the front panel of "Main" as it is running. You can accomplish the same thing by having the subVI write the current iteration value to a global variable and in your "Main" VI you would need a separate loop that continuously reads the value of the global variable and writes it to the indicator.

Attached is the control reference method. Others can provide alternate methods. Like I said, there's plenty of ways to do this.

You can read more about control references in the LabVIEW user manual, and it wouldn't hurt to head over to the NI Developer Zone and take a look at some of the tutorials available there, as well as on some of the external sites.
Download All
Message 2 of 3
(2,628 Views)
thanks for the reply...

0 Kudos
Message 3 of 3
(2,606 Views)