01-15-2013 02:36 PM
Hello,
I am using the Mikrotron MC1310 camera with the NI-1429 frame grabber. I am developing an application in Visual Studio 2010 using 64-bit C++ libraries.
After I perform a grab, and then try to capture a snapshot, the snapshot is timing out with no frames acquired. I can keep doing one grab after another one and one snapshot after another one.
Here is my code for cleaning up the acquisition objects after the grab:
_______________________________
void NIIMAQ::CleanUpAfterRecording()
{
uInt32 bufferIndex = 0;
if(this->m_Sid != 0)
imgSessionAbort(this->m_Sid, &bufferIndex);
// unlock the buffers in the buffer list
if (this->m_Bid != 0)
imgMemUnlock(this->m_Bid);
// dispose of the buffers
if(NULL != this->m_pImaqBufferArray)
{
for (unsigned int i = 0; i < this->m_totalAcquisionFrames; i++)
{
if (m_pImaqBufferArray[i] != NULL)
imgDisposeBuffer(this->m_pImaqBufferArray[i]);
}
delete [] this->m_pImaqBufferArray;
this->m_pImaqBufferArray = NULL;
this->m_totalAcquisionFrames = 0;
}
// close this buffer list
if (this->m_Bid != 0)
{
imgDisposeBufList(this->m_Bid, TRUE);
this->m_Bid = 0;
}
// dispose of the buffer
if (this->m_pImaqBuffer != NULL)
{
imgDisposeBuffer(this->m_pImaqBuffer);
this->m_pImaqBuffer = NULL;
}
// Close the interface and the session
if(this->m_Sid != 0)
{
imgClose (this->m_Sid, TRUE);
this->m_Sid = 0;
}
if(this->m_Iid != 0)
{
imgClose (this->m_Iid, TRUE);
this->m_Iid = 0;
}
}
01-16-2013 12:53 PM
Hello Brian,
I took a look at an example written in Measurement Studio that should be fairly similar to what you're trying to do. In fact, the code has many similar steps, such as unlocking and disposing of the buffers. At the start of the code, it has a section that actually stops the grab operation. In your code, I do see you using imgSessionAbort, which should stop the actual acquisition, but there is a section of code in the example that precedes this call. I'll paste the example here (from "LL Grab.c"):
DWORD StopThread(LPDWORD lpdwParam) {
DWORD dwResult;
int i;
// Get a handle to the stop event
HANDLE event = *((HANDLE*) lpdwParam);
// Wait for the done event to occur
dwResult = WaitForSingleObject(event, INFINITE);
if (dwResult != WAIT_FAILED) {
CloseHandle(event);
event = NULL;
}
// Stop the thread
StopGrab = TRUE;
// Wait for the thread to end and kill it otherwise
dwResult = WaitForSingleObject(HThread, 2000);
if (dwResult == WAIT_TIMEOUT)
TerminateThread(HThread, 0);
// stop the acquisition
imgSessionAbort(Sid, NULL);
// unlock the buffers in the buffer list
if (Bid != 0)
imgMemUnlock(Bid);
// dispose of the buffers
for (i = 0; i < NUM_GRAB_BUFFERS; i++)
if (ImaqBuffers[i] != NULL)
imgDisposeBuffer(ImaqBuffers[i]);
// close this buffer list
if (Bid != 0)
imgDisposeBufList(Bid, FALSE);
// free our copy buffer
if (CopyBuffer != NULL)
free(CopyBuffer);
// Close the interface and the session
if(Sid != 0)
imgClose (Sid, TRUE);
if(Iid != 0)
imgClose (Iid, TRUE);
EnableWindow(HStop, FALSE);
EnableWindow(HGrab, TRUE);
EnableWindow(HQuit, TRUE);
return 0;
}
Following the imgSessionAbort, the code is very similar to what you have in your post (buffer unlocking/disposing/etc.). Perhaps you have structured your code differently and aren't using threads - but is it possible that you have a thread continuing, and need to terminate that thread before aborting the session?
Do you have the examples installed on your machine? They are typically located at C:\Users\Public\Documents\National Instruments\NI-IMAQ\Examples. If you call the example code for a grab then immediately call the example code for a snap, do you see the same behavior?