该示例程序说明相机掉线后,心跳时间内重新连接后的操作,通过在打开相机后注册异常回调函数来监测相机掉线异常状态。重连后先进行停止取流、关闭设备、销毁句柄操作后重新连接相机。
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
{
int c;
while ( (c = getchar()) != '\n' && c != EOF );
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
{
if (NULL == pstMVDevInfo)
{
printf("The Pointer of pstMVDevInfo is NULL!\n");
return false;
}
{
printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);
}
{
}
{
}
{
}
{
}
{
}
else
{
printf("Not support.\n");
}
return true;
}
{
if (pstFrame)
{
printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n",
if (false == bAutoFree &&
NULL != pUser)
{
}
}
}
{
{
{
unsigned int nIndex = -1;
printf("device diconnect, please wait...\n");
do
{
{
printf("MV_CC_EnumDevices fail! nRet [%x]\n", nRet);
continue;
}
bool bFind = false;
{
{
{
nIndex = i;
bFind = true;
break;
}
}
{
{
nIndex = i;
bFind = true;
break;
}
}
{
{
nIndex = i;
bFind = true;
break;
}
}
{
{
nIndex = i;
bFind = true;
break;
}
}
{
{
nIndex = i;
bFind = true;
break;
}
}
}
if ((-1 == nIndex) || (false == bFind))
{
continue;
}
{
printf("MV_CC_CreateHandle fail! nRet [%x]\n", nRet);
continue;
}
{
printf("MV_CC_OpenDevice fail! nRet [%x]\n", nRet);
continue;
}
else
{
break;
}
{
printf("MV_CC_StartGrabbing fail! nRet [%x]\n", nRet);
return;
}
}
}
}
{
unsigned int nSelectNum = 0;
{
printf("Initialize SDK fail! nRet [0x%x]\n", nRet);
return nRet;
}
{
printf("MV_CC_EnumDevices fail! nRet [%x]\n", nRet);
return nRet;
}
{
{
printf("[device %d]:\n", i);
if (NULL == pDeviceInfo)
{
break;
}
}
}
else
{
printf("Find No Devices!\n");
return nRet;
}
printf("Please Intput camera index: ");
scanf("%d", &nSelectNum);
{
printf("Intput error!\n");
return nRet;
}
{
}
{
}
{
}
{
}
{
}
{
}
else
{
printf("not support!\n");
}
{
printf("MV_CC_CreateHandle fail! nRet [%x]\n", nRet);
return nRet;
}
{
printf("MV_CC_OpenDevice fail! nRet [%x]\n", nRet);
return nRet;
}
{
if (nPacketSize > 0)
{
{
printf("Warning: Set Packet Size fail nRet [0x%x]!\n", nRet);
}
}
else
{
printf("Warning: Get Packet Size fail nRet [0x%x]!\n", nPacketSize);
}
}
{
printf("MV_CC_SetTriggerMode fail! nRet [%x]\n", nRet);
return nRet;
}
{
printf("Register ExceptionCallBack fail! nRet [%x]\n", nRet);
}
{
printf("MV_CC_RegisterImageCallBackEx fail! nRet [%x]\n", nRet);
return nRet;
}
{
printf("MV_CC_StartGrabbing fail! nRet [%x]\n", nRet);
return nRet;
}
{
printf("Close Device success! \n");
}
{
printf("Destroy Handle success! \n");
}
printf("exit\n");
return 0;
}