LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save data from before event trigger?

I'm looking for some example code to help me collect analog data to a buffer and then write a portion of the buffered data to a file when an event occurs.  The event occurs about once a week but I need to be able to examine data from about 5 hours BEFORE the event up to the event itself. Collecting two points a second would be often enough to assure event capture. Dumping data older than 5 hours is ok. I've been through numerous forum discussions and online code examples but can't find the pieces to solve my problem. A search for "buffered event" seemed promising but didn't solve it. BTW I pretty new to LabView so far my knowledge of data structures is pretty limited. TIA

Bruce

0 Kudos
Message 1 of 7
(3,776 Views)
Bruce,

A circular buffer may be what you need. Size it to hold the 5 hours of data (2*60*60*5 = 36000 samples). When the buffer is full it automatically writes over the oldest data. I think there maybe some circular buffer examples around. Gary Johnson described one in his book, LabVIEW Graphical Programming in 1994.

Lynn
0 Kudos
Message 2 of 7
(3,770 Views)
Bruce,
 
I found a good example of how to do a simple circular buffer during data acquisition.  I've attached it to this post.
 
I hope this helps,
Justin D.
Applications Engineer
National Instruments
0 Kudos
Message 3 of 7
(3,757 Views)
As often as people need to implement their own circular buffers with various array manipulations, it'd be nice if NI took their DAQ circular buffer code and spawned it into some app-level support for circular buffering, looking similar to queues.
 
Features needed
-------------------------
1. Circular Buffers must be defined with fixed size.
2. Once full, new writes will overwrite the oldest data.  (Maybe not writing at all could be a wire-able option?)
3. Separate read and write marks should be maintained.
4. Normal Read behavior is similar to DAQmx Read -- start at earliest unread data.
5. Can also Read most recent data, all data, Preview data (without affecting the read mark).
 
Uses
--------
1. A high-speed DAQ process could write to a circular buffer.  The user interface can read from the circular buffer to update the display, while other routines are also reading from the same circular buffer to maintain process-control or limit-checking functions.
2. Make it easier to perform decimation and/or filtering with a sliding window.  Periodically read all data from the circular buffer, perform processing functions that reduce array down to a few scalar characteristics.  Consecutive calls could have partially-shared data -- no need to wait for new "fresh" data to arrive, just use the most recent already-available data.
 
Just some thoughts...
 
-Kevin P.
CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 4 of 7
(3,719 Views)

Kevin, your postings are real gems!

The circular buffer you described as

"

Features needed
-------------------------
1. Circular Buffers must be defined with fixed size.
2. Once full, new writes will overwrite the oldest data.  (Maybe not writing at all could be a wire-able option?)
3. Separate read and write marks should be maintained.
4. Normal Read behavior is similar to DAQmx Read -- start at earliest unread data.
5. Can also Read most recent data, all data, Preview data (without affecting the read mark).

"

was code I developed back in LV 6.0 and I have used in many projects since that time (sorry, no-can-post! I sell that critter).

LV would definatley benefit from having a native version available.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 7
(3,719 Views)

Hi,

 

I find your example very interesting but I don't understand everything... How can I define what kind of event I want to save?

 

For my application I need a scan rate of 300kHz. The voltage is more or less stable (due to the noise) and I have to record data when an event occurs. This one is a small variation in voltage. I want to record the values 10ms before the event until 10ms after the event and read continuously the data from the acquisition card in order to catch the following event. 

 

My problem is I don't know where I can define the event. circular buffer is really new for me and even by reading the application note I don't understand everything....

 

thanks a lot for your help!

 

Sophie

 

PS: LV 8.2 and PCI-6281

0 Kudos
Message 6 of 7
(3,265 Views)

Things have changed since then.

 

Rahter than write a round-robin buffer you can use queues.Queue up new data in the DAQ loop and let the logging function monitor the queue and maintain its most recent history in its own queue. As new updates come in to the logger, check the update for your trigger condition. if not found toss the oldest stuff in the logers private queue and add in the new update info. When a trigger is found in an update, go back and get the pre-trigger info from the loggers private queue etc.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 7
(3,263 Views)