12-15-2011 04:45 AM
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
Solved! Go to Solution.
12-15-2011 06:21 AM
You could use a queue to transfer data.
12-15-2011 06:36 AM
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
12-15-2011 06:38 AM
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.
12-15-2011 06:44 AM
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.
12-15-2011 07:03 AM
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
12-15-2011 07:27 AM
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.
12-15-2011 07:47 AM - edited 12-15-2011 07:48 AM
@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!
12-15-2011 07:49 AM
@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.
12-15-2011 08:00 AM
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