LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading from a subvi

Hi,

 

 

     I need to know how to read data from a while loop in a subvi, and plot in a main vi simultaneously ?  

0 Kudos
Message 1 of 10
(2,694 Views)

Sounds like you will need to use paralell loops.

 

Rather than having your loop inside the sub VI, have the subvi, inside a paralell loop to your main loop.

Then pass data gathered in the data gathering loop up to the loop displaying data with a queue.

 

(producer consumer with multuple consumer loops)

 

0 Kudos
Message 2 of 10
(2,693 Views)

Hi,

 

         Is it Possible to use Global variables or shared variables ?

0 Kudos
Message 3 of 10
(2,683 Views)

It is not generally recomended to use shared/global variables for this sort of thing.

A lot has been written about use of variables for this kind of thing, have a quick search. Lots about breaking data flow and causing race conditions.

 

 

0 Kudos
Message 4 of 10
(2,678 Views)

You could create the indicator/graph in the Main vi, pass a reference to the sub vi and update then the indicator via the value property of the reference

I do this all the time with progress bars to show progress of a running but hidden sub vi on the main interface

 

Ken 

0 Kudos
Message 5 of 10
(2,671 Views)

Isnt updating things via the Value section of a property node just as bad (worse?) as using local variables?

 

For small things like progress bars, fair enough. But if you are passing something like lots of measurement data from your DAQ, then I would be cautious about using the Value property node.

 

0 Kudos
Message 6 of 10
(2,669 Views)

I hadn't though of it like that.

 

I use the Value property to eliminate race conditions as the execution order can be controlled via the error cluster wire (only works for a single thread obviously)

0 Kudos
Message 7 of 10
(2,666 Views)

Good point about being able to use the error wires to control execution of the property node. 

 

I am mainly repeating things that I have read here: http://forums.ni.com/t5/LabVIEW/local-vs-property-node/td-p/321755

specifically the speed comparison stuff in the third post.

0 Kudos
Message 8 of 10
(2,660 Views)

Generally you dont read FROM a subvi, you execute it and it returns an answer you process.

Is there some loop performed, must it be in the sub-vi, or can the loop be in the main so the sub-vi process once and you can use the data?

If the sub-vi is some kind of self contained loop it can store data in an AE-Action Engine, or send it as events or to a queue.

The simplest solution is an AE.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 10
(2,645 Views)

@Ken_Naylor wrote:

I hadn't though of it like that.

 

I use the Value property to eliminate race conditions as the execution order can be controlled via the error cluster wire (only works for a single thread obviously)


The error wire will only order your execution within this piece of code and will not eliminate race conditions if your are passing the reference to multiple places or acting on the control in multiple places. From a design point it is generally best to pass data via queues, events or notifiers. Basically you want to design the system so that data capture, analysis and processing is separate from your UI processing. Using queues, notifiers or events allows you to do this. Passing references around code limits your reuse since you are tightly coupling the processing with the user interface. Same applies to globals and shared variables.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 10
(2,621 Views)