LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can an output data generated within a loop in a sub-vi be transfered to the main program for each iteration of the loop ?

Solved!
Go to solution

Hi LV users,

 

I have a very basic question, which I did not succeed to asnwer using basic considerations.

 

I made a sub-vi which performs a current-voltage sweep using a Keithley source-measure unit and a FOR loop. 

This sub-vi outputs 2 arrays containing my data (basically a voltage array and the corresponding current array). I defined also an output terminal to output a cluster of these 2 arrays in order to plot them on a XY-graph. More specifically, I indexed this cluster to be updated after each iteration of the FOR loop, in my sub-vi (the indicator is placed outside the loop, of course).

 

My problem is that I would like my main program to display the XY-graph in real time, with an update after every iteration of the FOR loop which is in my sub-vi.

I have a problem as the output terminals of my sub-vi are onlu available to the main program as soon as the sub-vi has finished its own execution (which is what we expect from sub-vi to do).

 

How can I use a sub-vi (because it is very convenient) and get in the main program during its execution data that are generated from the sub-vi loops ?

Thanks in advance for your help,

 

Yoyo87

0 Kudos
Message 1 of 36
(4,968 Views)

You could use a queue to transfer data.

 

0 Kudos
Message 2 of 36
(4,961 Views)

Thanks for your reply.

How should be implemented the queue ? In the sub-vi ?

I don't see how this will solve the problem if it is in a sub-vi...

Should I forget using a sub-vi ? (which I wouldn't).

 

Yoyo

 

0 Kudos
Message 3 of 36
(4,958 Views)
Solution
Accepted by Yoyo87

Enqueue elements in the SubVI and dequeue them in your main VI where you want to display the data.

It's similar to producer/consumer architecture. There are examples for that in LabVIEW. The examples work with 2 parallel loops, in your case one loop (the producer) will be in the SubVI.

 

Message 4 of 36
(4,955 Views)

Hi,

 

can use a global variable, write to it  inside the loop in the subvi. On the main vi add another loop in which you read the global variable and update the xy graph.

Message 5 of 36
(4,953 Views)

OK for the producer/comsomer structure. But I expect the same problem as the sub-vi will have to finish its execution completely before giving back the execution to the main program. So, during the execution of the sub-vi, the main program is in stand-by, isn't it ?

 

Or does the queues worl differently ?

 

could you give me simple example where a number is randomly generated in a FOR loop in a sub-VI, and the main program is used to display the numbers for each iteration of the loop ?

 

Thanks for your kind help.

 

Yoyo

0 Kudos
Message 6 of 36
(4,950 Views)

Just try it... When you enqueue elements in a loop of the SubVI you'll get them in the main VI while the SubVI is running. Just pass the queue ref to the SubVI when you call it. Pretty simple.

 

 

0 Kudos
Message 7 of 36
(4,943 Views)

@Zekasa wrote:

Hi,

 

can use a global variable, write to it  inside the loop in the subvi. On the main vi add another loop in which you read the global variable and update the xy graph.


NO!! NO!!  NO!!!

 

DO NOT USE GLOBAL VARIABLES!!

 

It is not a good idea.  The queue is an appropriate method.  Using Globals is NOT!!

 

And yes...  I was screaming..

 

Zekasa,  being a CLD, you should know better!

Message 8 of 36
(4,940 Views)

@Yoyo87 wrote:

OK for the producer/comsomer structure. But I expect the same problem as the sub-vi will have to finish its execution completely before giving back the execution to the main program. So, during the execution of the sub-vi, the main program is in stand-by, isn't it ?

 

Or does the queues worl differently ?

 

could you give me simple example where a number is randomly generated in a FOR loop in a sub-VI, and the main program is used to display the numbers for each iteration of the loop ?

 

Thanks for your kind help.

 

Yoyo


 

Put your sub-vi in parallel with the loop from your mainVI.  Not within the loop.

 

Message 9 of 36
(4,938 Views)

I'm not going to use global variables, that's for sure as it won't solve my problem.

 

To reply to Ray.R, my loop is in the sub-vi, not the main program.

 

I'll make some test using the queues, and I'll see if I can manage it to work.

I'll keep you informed of my progresses....

 

Thanks guys.

 

Yoyo

0 Kudos
Message 10 of 36
(4,934 Views)