Ring Acquisitions
Overview
A ring acquisition is a multiple-buffer continuous acquisition that uses multiple image buffers in a buffer list and fills them up as images are acquired. When all buffers in the list are full, the acquisition begins writing data at the beginning of the buffer list, similar to a circular buffer, or ring. This document discusses the buffer list and how to examine the images in the ring.
Table of Contents
Buffer List
A ring acquisition consists of a buffer list with multiple buffers for storing images. The following figure shows how a buffer list might look for five allocated buffers. As the acquisition begins, images 0 through 4 fill up the buffer list. As more images are acquired, they overwrite the old images in the buffer list with new images. This process continues until the acquisition stops. Refer to the System Memory Versus Online Memory section of this document for more information about how images are examined during acquisition.
[+] Enlarge Image
All IMAQ acquisitions begin by using IMAQ Init
When configuring the buffer list, you can assign a different channel to each buffer for multiple channel devices. You can also specify a skip count for each buffer so it will skip some images before it fills up. The skip count is typically set to 0 for each image and only one channel is used for all buffers.
Because images take up a large amount of memory, IMAQ allows you to manage the memory since you can do this more efficiently than the operating system. The following figure and code snippets for LabVIEW and C illustrate how to set up a standard ring buffer list.

[+] Enlarge Image
static BUFLIST_ID Bid;
static SESSION_ID Sid;
static INTERFACE_ID Iid;
static Int8* ImaqBuffers[NUM_RING_BUFFERS];
// Create a buffer list with n elements
imgCreateBufList(NUM_RING_BUFFERS, &Bid);
bufSize = AcqWinWidth * AcqWinHeight * bytesPerPixel;
/* The following configuration makes theseassignments to the buffer list
elements:
- buffer pointer that will contain image
- size of the buffer for buffer element 0
- command to go to next buffer or loop when the last element is reached
*/
for (i = 0; i < NUM_RING_BUFFERS; i++)
{
imgCreateBuffer(Sid, IMG_HOST_FRAME, bufSize, &ImaqBuffers[i]);
imgSetBufferElement(Bid, i, IMG_BUFF_ADDRESS, (uInt32)ImaqBuffers[i]);
imgSetBufferElement(Bid, i, IMG_BUFF_SIZE, bufSize);
bufCmd = (i == (NUM_RING_BUFFERS - 1)) ? IMG_CMD_LOOP : IMG_CMD_NEXT;
imgSetBufferElement(Bid, i, IMG_BUFF_COMMAND, bufCmd);
}
// Lock down the buffers contained in the buffer list
imgMemLock(Bid);
// Configure the session to use this buffer list
imgSessionConfigure(Sid, Bid);
Both methods allocate the memory inside a For loop and assign properties to each buffer in the list.
See Also:
Ring
System Memory Versus Onboard Memory
System memory means that the buffer list is allocated in the computer memory. Onboard memory refers to the memory allocated on the IMAQ device. The IMAQ 1409, 1411, 1422, 1424, and 1428 have 16 MBytes of onboard memory. The IMAQ 1424 can be upgraded to 80 MBytes of onboard memory.
Extract and Copy (described below) are the two methods for examining data when acquiring to system memory.
Extract
Once you set up the buffer list and start the acquisition, the buffers begin to fill and you can use IMAQ Extract

[+] Enlarge Image
Specifying a number that is currently in the buffer list locks it out and prevents it from being overwritten. Specifying a buffer that has already been overwritten locks out the buffer that is currently in the same buffer index as the requested image.

[+] Enlarge Image
Note: IMAQ Extract uses memory that the IMAQ device writes to when acquiring. As a result, any processing done on that buffer is overwritten when the buffer is released. If you need the image for extended periods of time, make a copy of the image to a user-defined memory location and then reinsert the buffer list image back to prevent the acquisition from being held up waiting for that buffer to be released.
Copy
You can also use IMAQ Copy
Onboard acquisitions only work using Copy. When using onboard memory to store images, you cannot access and analyze data on the IMAQ device. You must copy the data from the device onboard memory to a buffer in system memory. Only images that are copied are transferred over the PCI bus. As a result, using onboard memory could help reduce PCI traffic if you do not need every image. The only difference between programming a system memory acquisition and an onboard acquisition is setting the memory location (to system or onboard) when calling IMAQ Configure List
IMAQ devices also take advantage of onboard memory to prevent images from being lost. If you extract an image and do not reinsert it before the acquisition fills the remaining buffers in the list, IMAQ devices with onboard memory (1409, 1411, 1422, 1424, and 1428) save images in onboard memory. As you read images from the buffer list, the IMAQ device transfers images to your buffer list as buffers in the list become available for writing, which increases the number of buffers you have before images are lost. When the onboard memory is full because an image is extracted for extended periods, the acquisition begins to lose any newly acquired frames because there is no more room to save them. This process continues until the extracted buffer is released and acquisition can begin going around the ring again overwriting images with newer ones.
See Also:
Acquisition into Onboard Memory
Avoiding Timeouts and Monitoring Lost Frames
Timeout errors are common when you trigger the buffers at infrequent intervals, or when frame rates are very slow because of integration times or large image sizes. The timeout timer begins counting as soon as you request an image with either Copy or Extract. Additionally, an error occurs if the entire image does not finish filling the buffer by the timeout value. To avoid this error, do not request a buffer until you know a new one is available, and then when you use Copy or Extract, you know the image is already there. You can use this method by periodically polling the last valid frame. When it changes, you know a new image is available.
For IMAQ devices with onboard memory, you can use a ring acquisition to monitor whether a frame is lost by reading the attribute that provides the lost frame number. Refer to the Monitor Lost Frames document for information about this topic.
See Also:
Monitoring Lost Frames
Pre- and Post-Trigger Saving to Disk
Using NI-IMAQ to Reacquire Lost, Corrupted, or Switched Video Signals
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
