08-01-2012 03:30 PM
I am using LabWindows/CVI, and I created a low-level ring acquisition. It works normally at first, but if I stop it and start a few times (does not always happen on the first stop / start cycle), then on the third session the function imgSessionStatus passes back "-1" for the active buffer index. Why would it do this??
Code:
error = imgSessionStatus(Sid, &status, ¤tRingBufNum);
Which is usually followed by, except when currentRingBufNum has been set to "-1" by imgSessionStatus.
error = imgSessionCopyBuffer(Sid, currentRingBufNum, (uInt8*)mainImage, FALSE);
I stop my acquisition by :
imgSessionAbort(Sid, &ringBufNum);
Then I unlock my ring buffer, dispose each element, dispose of the buffer list, close the session and then the interface. The next acquisition starts by opening the interface, opening a session, creating a buffer list, creating and allocating each element, locking the buffer list, and configuring the session to use that buffer list. Why do I get this error??
Buffer creation code:
imgCreateBufList(NUMRINGBUFFERS, &Bid);
imgGetAttribute(Sid, IMG_ATTR_BYTESPERPIXEL, &bytesPerPixel);
bufSize = AcqWinWidth * AcqWinHeight * bytesPerPixel;
for (i = 0; i < NUMRINGBUFFERS; i++)
{
imgCreateBuffer(Sid, IMG_HOST_FRAME, bufSize, &ringBuffer[i]);
imgSetBufferElement(Bid, i, IMG_BUFF_ADDRESS, (uInt32)ringBuffer[i]);
imgSetBufferElement(Bid, i, IMG_BUFF_SIZE, bufSize);
bufCmd = (i == (NUMRINGBUFFERS - 1)) ? IMG_CMD_LOOP : IMG_CMD_NEXT;
imgSetBufferElement(Bid, i, IMG_BUFF_COMMAND, bufCmd);
}
imgMemLock(Bid);
imgSessionConfigure(Sid, Bid);
Buffer disposal code:
if (Bid) imgMemUnlock(Bid);
for (i = 0; i < NUMRINGBUFFERS; i++)
{
if (ringBuffer[i] != NULL)
imgDisposeBuffer(ringBuffer[i]);
ringBuffer[i] = NULL;
}
if (Bid) imgDisposeBufList(Bid, FALSE);
Bid = 0;
11-12-2012 09:04 AM
I thought I would post an update in case anyone else has this problem. I have not solved it, but a work around has essentially made it a non-issue. imgSessionStatus returning "-1" only seems to occur on the first attempted frame grab, so I simply have my frame-grabbing callback ignore any buffers returned as "-1". On all future iterations until the acquisition is halted, imgSessionStatus returns good buffers.
Additionally, error trapping reduced this headache while I was developing and troubleshooting it. I wrapped all IMAQ functions with:
error = imgSessionStatus(arguments);
if (error) showError(error);
Nothing new or innovative, of course, but it was helpful.