LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Structuring program to avoid buffer overwrite

When working with multiple data input channels, viewing the raw data, performing complex analysis on the data, viewing the altered data, and then writing all the sets of data to a measurement file I often run into the issue of filling up the buffer and overwriting data before it has been read from the buffer.  What is the best way to avoid this error.  My thinking is to create a program buffer of some kind and perform the data reading, viewing, analysis, and writing in separate while loops as opposed to cramming it all into one.  I am not sure how to do this though.  If anybody could explain the best way to accomplish this or point me in the direction of an example of how to do this that would be great.  For example I created one application where I was reading in 4 accelerometers, 1 velocity probe, and a pressure transducer with the DAQ assistant.  I thin split these signals up and connected each to a graph indicator and numeric indicator.  From there I passed each signal to a Filter express VI.  Out of the filter I split each signal again and passed the filtered data to separate graph indicators.  I then passed the filtered signals to a power spectrum express VI and performed an FFT analysis.  Once again I passed all these signals to separate graph indicators and sent all raw data, filtered signals, and power spectrums to a measurement file.  This was all done in one while loop.  Of course when I ran the program I received the error from the power spectrum VI or the Filter VI or the Write to Measurement File VI that it attempted to read data that had been overwritten.  I then began deleting graph indicators 1 by 1 until I eventually no longer received the error. Thanks for any help.
0 Kudos
Message 1 of 3
(2,931 Views)

A few things that you can do to avoid buffer over write.

 

1. Increase the buffer size (samples/channel)

2. Grap the data from the buffer more frequently.  You can dedicate a loop to acquire data from the buffer and put the data on a queue, so that another loop can use that data.

3. If you don't mind some of your data in your buffer being overwritten, you an use a property node to setup the buffer, so that the buffer will allow overwrite without giving you an error.

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
Message 2 of 3
(2,912 Views)
One of the best ways to pass data between loops, especially when they are executing at different speeds is to use queues. Queues will maintain the order of the data, act as a buffer so you don't overwrite your data and provide a clean, thread safe (read no race conditions) to pass data between different tasks. Obivously this does require sufficient memory to be available (LabVIEW will manage the memory for you) since you will be making copies of the data as you queue it.
Message Edited by Mark Yedinak on 03-18-2010 10:32 AM


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 3 of 3
(2,897 Views)