Frame grabber enumeration and control.
The sample code shows how to perform operations (e.g., enumerating, opening, and attribute configuring) on self-developed frame grabber via enumeration APIs.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include "MvCameraControl.h"
void* g_hInterface = NULL;
bool g_bExit = false;
void PressEnterToExit(void)
{
int c;
while ( (c = getchar()) != '\n' && c != EOF );
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
g_bExit = true;
sleep(1);
}
{
if (NULL == pstInterfaceInfo)
{
printf("The Pointer of pstInterfaceInfo is NULL!\n");
return false;
}
printf(
"model name: %s\n",pstInterfaceInfo->
chModelName);
printf("\n");
return true;
}
void Set_Get_Enum(const char* str)
{
{
printf("Get %s Fail! nRet [0x%x]\n", str, nRet);
return;
}
{
printf("Get %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf(
"Get %s = [%s] Success!\n",str,stEnumentryInfo.
chSymbolic);
}
{
{
printf("Set %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf(
"Set %s = [%s] Success!\n",str,stEnumentryInfo.
chSymbolic);
}
}
}
void Set_Get_Bool(const char* str)
{
bool bValue = false;
{
printf("Get %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf("Get %s = [%d] Success!\n",str,bValue);
}
{
{
printf("Set %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf("Set %s = [%d] Success!\n",str,bValue);
}
}
}
void Set_Get_Int(const char* str)
{
{
printf("Get %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf(
"Get %s = [%ld] Success!\n",str,stIntValue.
nCurValue);
}
{
{
printf("Set %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf(
"Set %s = [%ld] Success!\n",str,stIntValue.
nCurValue);
}
}
}
void Set_Get_String(const char* str)
{
{
printf("Get %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf(
"Get %s = [%s] Success!\n",str,StringValue.
chCurValue);
}
{
{
printf("Set %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf(
"Set %s = [%s] Success!\n",str,StringValue.
chCurValue);
}
}
}
void Set_Get_Float(const char* str)
{
{
printf("Get %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf(
"Get %s = [%f] Success!\n",str,FloatValue.
fCurValue);
}
{
{
printf("Set %s Fail! nRet [0x%x]\n", str,nRet);
return;
}
else
{
printf(
"Set %s = [%f] Success!\n",str,FloatValue.
fCurValue);
}
}
}
unsigned int UserSelect2TLayerType(unsigned int nSelect)
{
switch(nSelect)
{
case 0:
case 1:
case 2:
case 3:
default:
return -1;
}
}
int main()
{
printf("[0]: GIGE Interface\n");
printf("[1]: CAMERALINK Interface\n");
printf("[2]: CXP Interface\n");
printf("[3]: XOF Interface\n\n");
do
{
{
printf("Initialize SDK fail! nRet [0x%x]\n", nRet);
break;
}
unsigned int nType = 0;
printf("Please Input Enum Interfaces Type(0-%d):", 3);
scanf("%d", &nType);
unsigned int nTLayerType = UserSelect2TLayerType(nType);
if(-1 == nTLayerType)
{
printf("Input error!\n");
break;
}
{
printf("Enum Interfaces fail! nRet [0x%x]\n", nRet);
break;
}
{
for (
unsigned int i = 0; i < stInterfaceInfoList.
nInterfaceNum; i++)
{
printf("[Interface %d]:\n", i);
if (NULL == pstInterfaceInfo)
{
break;
}
PrintInterfaceInfo(pstInterfaceInfo);
}
printf("Enum Interfaces success!\n\n");
}
else
{
printf("Find No Interface!\n");
break;
}
printf(
"Please Input Interfaces index(0-%d):", stInterfaceInfoList.
nInterfaceNum-1);
unsigned int nIndex = 0;
scanf("%d", &nIndex);
{
printf("Input error!\n");
break;
}
{
printf("Create Interface success!\n");
}
else
{
printf("Create Interface Handle fail! nRet [0x%x]\n", nRet);
break;
}
{
printf("Open Interface success!\n");
}
else
{
printf("Open Interface fail! nRet [0x%x]\n", nRet);
break;
}
switch(nType)
{
case 0:
{
Set_Get_Enum("StreamSelector");
Set_Get_Enum("TimerSelector");
Set_Get_Enum("TimerTriggerSource");
Set_Get_Enum("TimerTriggerActivation");
Set_Get_Bool("HBDecompression");
Set_Get_Int("TimerDuration");
Set_Get_Int("TimerDelay");
Set_Get_Int("TimerFrequency");
break;
}
case 1:
{
Set_Get_Enum("StreamSelector");
Set_Get_Enum("CameraType");
Set_Get_Enum("StreamPartialImageControl");
Set_Get_Int("ImageHeight");
Set_Get_Int("FrameTimeoutTime");
break;
}
case 2:
{
Set_Get_Enum("StreamSelector");
Set_Get_Int("StreamEnableStatus");
Set_Get_Bool("BayerCFAEnable");
Set_Get_Bool("GammaEnable");
Set_Get_Float("Gamma");
break;
}
case 3:
{
Set_Get_Enum("StreamSelector");
Set_Get_Int("FrameTimeoutTime");
Set_Get_Bool("MinFrameDelay");
Set_Get_Enum("LinkSelector");
break;
}
default:
{
printf("Input error!\n");
break;
}
}
{
printf("Close Interface success!\n");
}
else
{
printf("Close Interface Handle fail! nRet [0x%x]\n", nRet);
break;
}
{
printf("Destroy Interface success!\n");
}
else
{
printf("Destroy Interface Handle fail! nRet [0x%x]\n", nRet);
break;
}
g_hInterface = NULL;
} while (0);
if (g_hInterface != NULL)
{
g_hInterface = NULL;
}
printf("exit\n");
return 0;
}