PDA

View Full Version : AnsiC.c example to check if a device is in use



marimar128
September 14, 2014, 23:39:14
I'm using the Ansi C DLL to (hopefully) control a camera from TIS. I'm having trouble understanding one of the code examples in the file AnsiC.c, included in the IC Imaging Control C Library (http://www.theimagingsource.com/en_US/support/downloads/details/icimagingcontrolcwrapper/)

Which of the calls to the DLL actually determines if the device is in use? It seems that the output of GetUniqueName is compared to the output of GetUniqueNameFromList, but this doesn't make any sense to me. Is one of these outputs expected to depend on whether or not the device is in use? The documentation does not seem to indicate this in any way. Should I read more carefully, or is this undocumented behavior?

Also, when I run this code myself, it always shows the same output from these two function calls, even when I'm simultaneously streaming images from the camera using IC Capture 2.2. Is this expected behavior?


//////////////////////////////////////////////////////////////////////////
/*! This functions shows, how to check, whether a video capture device is already
in use.
*/
void CheckDevice()
{
int i,o;
int iDeviceCount;
char szUniqueName[121];
HGRABBER Grabbers[10];
int iFound = 0;

for( i = 0; i < 10; i++ ) // Create some grabber objects for testing this function
{
Grabbers[i] = IC_CreateGrabber();
}
IC_OpenVideoCaptureDevice( Grabbers[5], "DFK 21F04" );
if( !IC_IsDevValid(Grabbers[5])) printf("Failed to open test device.\n");

iDeviceCount = IC_GetDeviceCount(); // Count the connected video capture devices
for( i = 0; i < iDeviceCount; i++ )
{
printf("Device %s\nUnique Name : %s\n\n",IC_GetDevice(i),IC_GetUniqueNamefromList(i));

for( o = 0; o < 10 && iFound == 0; o++)
{
if( IC_IsDevValid(Grabbers[o]))
{
if( IC_GetUniqueName(Grabbers[o], szUniqueName,120) == IC_SUCCESS)
{
if( strcmp( IC_GetUniqueNamefromList(i) , szUniqueName) == 0 )
{
printf("Device already in use. (Grabber %d)\n",o);
iFound = 1;
}
}
}
}
}

for( i = 0; i < 10; i++ ) // Create some grabber objects for testing this function
{
IC_ReleaseGrabber(&Grabbers[i]);
}
}

Stefan Geissler
September 24, 2014, 14:48:21
Hello

The only way to check, whether a camera is already streaming a live video, is trying to start the live video. If this fails, then either the camera is already streaming or another error happens.

You can not determine, whether another application uses the camera. You can open the the camera twice and set properties, but the live stream can be started once only.

The function aboves shows only, how identify a camera unique, if you have a camera in your application in use. This is to avoid to open your camera twice in the same program. That means, you must handle a list of currently used cameras in your program and compare it with all available cameras. This is done with IC_GetUniqueName(). This functions returns a unique name for each camera, even if you have connected many cameras of the same type.