LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

storing global data - most efficiently

Hello,

 

I have the attached code that is reading from a com port and filtering data into seperate arrays.  I need to be able to access the stored data from from higher level VI's for data analysis.  In the following code i am storing the data into one large global or into indvidual global, dependent on the boolean indicator values.  When I call this VI the global values are not updated because to the calling VI as the loop does not stop.  It seems that i need a VI on top of this one that makes incremental calls in order for the globals to be updated?  I'm thinking i may be able to simply use an event structure based on serial events so that the loop will eventually break in order to update the globals?

 

I would also like to ask about most efficeint data storage. Would you recommend a more efficeint way of storing data and making it available to higher level VI's?  I like the idea of using the globals to store the data rather than a higher level shift register but Im not sure it is the best way of going about it. 

 

I would like some recommendations on how best organize this code for best performing operation.  

 

Thanks for the comments

0 Kudos
Message 1 of 6
(3,049 Views)

You didn't include any of the subVIs or the global variable VIs, so it's difficult to tell if you are simply suffering from a race condition. I think you may want to look over Action Engines.

 

Also, you should avoid creating greedy loops

 

 

Message Edited by smercurio_fc on 10-06-2008 09:52 AM
Message 2 of 6
(3,031 Views)

I do not have LabVIEW installed on this PC, so I could not look at your VI. 

However, you may not need to use Global Variables, as there are better alternatives.

The best approach is to have a main VI call sub-VIs and have the data directly from wires.

 

This may not always be applicable, especially in cases where there is acquisition happening at the same time as the data is being analyzed or processed.  An approach would be to have a Producer / Consumer archetecture, where the sub-VIs would pass the data using a queue.  Another approach would be to have Dynamic VI's (daemons) that collect data and make it immediately available by storing it into a Functional Global Variable or by using a queue.

 

And there are other scenarios available depending on how the overall process needs to take place.  There are also ways to minimize the number of variables (controls) within Global Variable (or any of the alternatives) and that is to combine the data within clusters.

 

Food for thought...

 

R

Message 3 of 6
(3,023 Views)
Thanks for the info,
 
smercurios, yeah i'm not sure about race conditions, i dont think so as, the globals are only being accessed from 1 vi that is not reentrant.  I do have a problem with the greedy loop, which i hope to resolve after some modifications and rewriting for better optimazation.
 
thanks joelabview i will have a look at the topics you listed.
 
the vi i am using is setting up the serial and looping to read the serial buffer, currently a wide open while loop.  I filter the data from the buffer and store the data into arrays.  all i want to do is to make the data available in the cleanest way possible to other vi's.  I chose to use globals so that can run the serial read and filter routines in parallel with any other analysis code.  It sound like the listed topic of "Producer / Consumer archetecture". I will look into this.  
 
Do you have good links into some of these different methods of creating those architectures?  
 
Thanks for the help. 
0 Kudos
Message 4 of 6
(2,994 Views)

What you want is a reference object.  You pass a reference to the object around instead of the actual object.  There are a variety of ways to do these in LabVIEW, but only two that I would recommend.  You already know about one - LabVIEW 2 globals, AKA functional globals, shift register globals, or action engines.  The other good option is single-element queues.  Check out this post for more information on the subject.  It has code examples and a complete writeup on the subject.

 

I, personally, prefer single-element queues because they fit my programming style better.  They are a bit harder to use, but give better performance when you need it (large data).  Try both and see what you like.

Message 5 of 6
(2,963 Views)
Using queues is also my preferred implementation method, but at least there are options out there instead of using Globals.. 😉
0 Kudos
Message 6 of 6
(2,950 Views)