WaitForSnap with multiple boards

LabVIEW, mvAcquireControl

When developing your applications with the mvAcquireControl-SDK in combination with the use of
multiple MATRIX Vision frame grabber devices you have to take great care when using the function "SnapAsync(0)".
When passing "0" to this function, an internal event will be used to signalise the end of the image acquirering.
This event resets to "nonsignaled" state automatically.
When now working with more then one board the following situation can occur:

TASnapResult snapRes1, snapRes2;
while(m_boLoop)
{
m_firstAcqcontrol->GetIGrabber()->SnapAsync(0);
m_secondAcqcontrol->GetIGrabber()->SnapAsync(0);
while( !(m_firstAcqcontrol->GetIGrabber()->WaitForSnap(0, &snapRes1, sizeof(TASnapResult) ) ) || !(m_secondAcqcontrol->GetIGrabber()->WaitForSnap(0, &snapRes2, sizeof(TASnapResult) ) )
{
Sleep(SLEEP_TIME);
}
RefreshView(m_imageWindow1.m_hWnd);
RefreshView(m_imageWindow2.m_hWnd);
}

When the first grabber is ready (returning TRUE),
but the second one is not (returning FALSE) you"ll remain inside the loop...

From the next iteration this loop now can"t be left anymore, as the event from the first grabber
has been set back to "nonsignaled" state, an will not be set to "signalised" until the next image
has been acquired completely. So this "WaitForSnap" call will always return FALSE from now on.

If you make some small changes to your application you can bring this loop back to work again.
The only thing you have to do is to replace the direct function calls in the loop condition by two BOOL-flags.
These flags you set to TRUE whenever the corresponding frame grabber is ready.
Have a look on the next section of code, to understand how to do this:

TASnapResult snapRes1, snapRes2;
while(m_boLoop)
{
m_boFirstGrabberReady = m_boSecondGrabberReady = FALSE;
m_firstAcqcontrol->GetIGrabber()->SnapAsync(0);
m_secondAcqcontrol->GetIGrabber()->SnapAsync(0);
while( !(m_boFirstGrabberReady & m_boSecondGrabberReady) )
{
Sleep(SLEEP_TIME);
if( m_firstAcqcontrol->GetIGrabber()->WaitForSnap(0, &snapRes1, sizeof(TASnapResult) ) )
m_boFirstGrabberReady = TRUE;
if(m_secondAcqcontrol->GetIGrabber()->WaitForSnap(0, &snapRes2, sizeof(TASnapResult) ) )
m_boSecondGrabberReady = TRUE;
}
RefreshView(m_imageWindow1.m_hWnd);
RefreshView(m_imageWindow2.m_hWnd);
}

LABVIEW:
A similar principle applies for the virtual instruments from the mvLabVIEW-SDK
("MV_SnapAsync.vi", "MV_WaitForSnap.vi", "MV_DualSnapAsync.vi", "MV_GetAsyncImage.vi" und "MV_GetImage.vi"):

Try to avoid a similar situation like the one dicussed above.
When waiting for two images use two seperate loops when waiting
for the images to be ready ( one for each grabber ).
See the example "MV_Test_DualSnapAsync.vi".
Or you have to implement some kind of bool-flag under LabVIEW, which can be used like in the source segment from above.

Back