Connect a camera via IP address.
The sample code below shows how to connect to cameras via its IP address and the related NIC's IP address. The input format is xx.xx.xx.xx
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include "MvCameraControl.h"
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);
}
static void* WorkThread(void* pUser)
{
while(1)
{
if(g_bExit)
{
break;
}
{
printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n",
}
else
{
printf("No data[0x%x]\n", nRet);
break;
}
}
return 0;
}
int main()
{
void* handle = NULL;
printf("Please input Current Camera Ip : ");
char nCurrentIp[128];
scanf("%s", (char*)&nCurrentIp);
printf("Please input Net Export Ip : ");
char nNetExport[128];
scanf("%s", (char*)&nNetExport);
unsigned int nIp1, nIp2, nIp3, nIp4, nIp;
sscanf(nCurrentIp, "%d.%d.%d.%d", &nIp1, &nIp2, &nIp3, &nIp4);
nIp = (nIp1 << 24) | (nIp2 << 16) | (nIp3 << 8) | nIp4;
sscanf(nNetExport, "%d.%d.%d.%d", &nIp1, &nIp2, &nIp3, &nIp4);
nIp = (nIp1 << 24) | (nIp2 << 16) | (nIp3 << 8) | nIp4;
do
{
{
printf("Initialize SDK fail! nRet [0x%x]\n", nRet);
break;
}
{
printf("Create Handle fail! nRet[0x%x]\n", nRet);
break;
}
{
printf("Open Device fail! nRet [0x%x]\n", nRet);
break;
}
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("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
break;
}
{
printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
break;
}
pthread_t nThreadID;
nRet = pthread_create(&nThreadID, NULL ,WorkThread , handle);
if (nRet != 0)
{
printf("thread create failed.ret = %d\n",nRet);
break;
}
PressEnterToExit();
{
printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
break;
}
{
printf("Close Device fail! nRet [0x%x]\n", nRet);
break;
}
{
printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
break;
}
handle = NULL;
} while (0);
if (handle != NULL)
{
handle = NULL;
}
printf("exit.\n");
return 0;
}