Reconnect a camera.
The sample code shows how to reconnect a camera the camera goes offline.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include "MvCameraControl.h"
void* g_hHandle = NULL;
bool g_bConnect = false;
char g_strSerialNumber[64] = {0};
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');
}
{
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;
}
void __stdcall ImageCallBackEx(
unsigned char * pData,
MV_FRAME_OUT_INFO_EX* pFrameInfo,
void* pUser)
{
if (pFrameInfo)
{
printf("GetOneFrame, Width[%d], Height[%d], nFrameNum[%d]\n",
}
}
void __stdcall ReconnectDevice(unsigned int nMsgType, void* pUser)
{
{
if(true == g_bConnect)
{
g_hHandle = NULL;
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);
g_hHandle = NULL;
continue;
}
else
{
break;
}
}while(g_bExit== false);
{
printf("MV_CC_StartGrabbing fail! nRet [%x]\n", nRet);
return;
}
}
}
}
int main()
{
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;
}
PrintDeviceInfo(pDeviceInfo);
}
}
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;
}
g_bConnect = true;
{
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;
}
PressEnterToExit();
g_bConnect = false;
g_bExit = true;
{
printf("Close Device success! \n");
}
{
printf("Destroy Handle success! \n");
}
g_hHandle = NULL;
printf("exit\n");
return 0;
}