11-09-2012 05:03 AM
Hi,
I need to know how to read data from a while loop in a subvi, and plot in a main vi simultaneously ?
11-09-2012 05:12 AM - edited 11-09-2012 05:17 AM
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)
11-09-2012 05:44 AM
Hi,
Is it Possible to use Global variables or shared variables ?
11-09-2012 05:49 AM
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.
11-09-2012 05:55 AM
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
11-09-2012 06:01 AM
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.
11-09-2012 06:12 AM
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)
11-09-2012 06:20 AM
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.
11-09-2012 08:38 AM
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
11-09-2012 11:04 AM
@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.