#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#pragma comment(lib, "wsock32.lib")
#define PERSISTENT_CONFIG_REG 0x0014
#define PERSISTENT_IPADDR_REG 0x064C
#define PERSISTENT_SUBNETMASK_REG 0x065C
#define PERSISTENT_DEFAULTGATEWAY_REG 0x066C
bool WritesToRegisters(
char* chSerialNumber,
unsigned int nIpAddr,
unsigned int nNetWorkMask,
unsigned int nDefaultGateway);
{
while(!_kbhit())
{
Sleep(10);
}
_getch();
}
{
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;
}
bool ConvertToHexIp(
unsigned int *nHexIP,
unsigned int *nDecIP,
char c)
{
if ( nDecIP[0] < 0 || nDecIP[0] > 255
|| nDecIP[1] < 0 || nDecIP[1] > 255
|| nDecIP[2] < 0 || nDecIP[2] > 255
|| nDecIP[3] < 0 || nDecIP[3] > 255
|| c != '\n')
{
return false;
}
*nHexIP = (nDecIP[0] << 24) + (nDecIP[1] << 16) + (nDecIP[2] << 8) + nDecIP[3];
return true;
}
{
unsigned int nIP[4] = {0};
char c = '\0';
unsigned int nIpAddr = 0, nNetWorkMask = 0, nDefaultGateway = 0;
do
{
{
printf("Initialize SDK fail! nRet [0x%x]\n", nRet);
break;
}
{
printf("Enum Devices fail! nRet [0x%x]\n", nRet);
break;
}
{
for (
unsigned int i = 0; i < stDeviceList.
nDeviceNum; i++)
{
printf("[device %d]:\n", i);
if (NULL == pDeviceInfo)
{
break;
}
}
}
else
{
printf("Find No Devices!\n");
break;
}
printf(
"Please Input camera index(0-%d):", stDeviceList.
nDeviceNum-1);
unsigned int nIndex = 0;
scanf_s("%d", &nIndex);
{
printf("Input error!\n");
break;
}
{
printf("Create Handle fail! nRet [0x%x]\n", nRet);
break;
}
char chSerialNumber[16] = {0};
printf("serial number:[%s]\n", chSerialNumber);
printf("Please input ip, example: 192.168.1.100\n");
if ( 5 != scanf("%d.%d.%d.%d%c", &nIP[0], &nIP[1], &nIP[2], &nIP[3], &c) )
{
printf("input count error\n");
break;
}
{
printf("input IpAddr format is not correct\n");
break;
}
printf("Please input NetMask, example: 255.255.255.0\n");
if ( 5 != scanf("%d.%d.%d.%d%c", &nIP[0], &nIP[1], &nIP[2], &nIP[3], &c) )
{
printf("input count error\n");
break;
}
{
printf("input NetMask format is not correct\n");
break;
}
printf("Please input DefaultWay, example: 192.168.1.1\n");
if ( 5 != scanf("%d.%d.%d.%d%c", &nIP[0], &nIP[1], &nIP[2], &nIP[3], &c) )
{
printf("input count error\n");
break;
}
{
printf("input DefaultWay format is not correct\n");
break;
}
if(bAccessible)
{
{
printf("MV_GIGE_SetIpConfig fail! nRet [%x]\n", nRet);
break;
}
printf("set IPConfig succeed\n");
{
printf("MV_GIGE_ForceIpEx fail! nRet [%x]\n", nRet);
break;
}
printf("set IP succeed\n");
}
else
{
{
printf("MV_GIGE_ForceIpEx fail! nRet [%x]\n", nRet);
break;
}
printf("set IP succeed\n");
{
printf("MV_CC_CreateHandle fail! nRet [%x]\n", nRet);
break;
}
{
printf("MV_GIGE_SetIpConfig fail! nRet [%x]\n", nRet);
break;
}
printf("set IPConfig succeed\n");
}
{
printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
break;
}
printf("Finish, everything is OK.\n");
} while (0);
{
}
printf("Press a key to exit.\n");
return 0;
}
bool WritesToRegisters(
char* chSerialNumber,
unsigned int nIpAddr,
unsigned int nNetWorkMask,
unsigned int nDefaultGateway)
{
printf("Now start writing registers ...\n");
if (NULL == chSerialNumber)
{
printf("Serial number is invalid\n");
return false;
}
unsigned int nIndex = -1;
do
{
{
printf("Enum devices fail! nRet [0x%x]\n", nRet);
break;
}
{
for (
unsigned int i = 0; i < stDeviceList.
nDeviceNum; i++)
{
if (NULL == pDeviceInfo)
{
printf("Pointer invalid!\n");
break;
}
{
nIndex = i;
break;
}
}
}
else
{
printf("Find no devices!\n");
return false;
}
if (-1 == nIndex)
{
printf("Can't find the device, that just modified IP\n");
return false;
}
{
printf("Create handle fail! nRet [0x%x]\n", nRet);
break;
}
{
printf("Open device fail! nRet [0x%x]\n", nRet);
break;
}
unsigned int nConfig = htonl(0x05);
{
printf("Write config fail! nRet [0x%x]\n", nRet);
break;
}
unsigned int nIpAddr1 = htonl(nIpAddr);
{
printf("Write IP fail! nRet [0x%x]\n", nRet);
break;
}
unsigned int nNetWorkMask1 = htonl(nNetWorkMask);
{
printf("Write network mask fail! nRet [0x%x]\n", nRet);
break;
}
unsigned int nDefaultGateway1 = htonl(nDefaultGateway);
{
printf("Write default gateway 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;
}
printf("Writing registers success\n");
} while (0);
{
}
{
return false;
}
return true;
}