int main(void)
{
	/*
	 *	程序连接上设备后,用户可以通过拔网线或其他方式使设备断线,然后再恢复网络。
	 */
	NET_DEVICEINFO deviceInfo ={0};
	unsigned long lLogin;
	CLIENT_Init(DisConnectFunc,0);//初始化sdk,设置断线回调函数
	CLIENT_SetAutoReconnect(AutoConnectFunc,0);//设置断线重连成功的回调函数。不调用此接口,sdk将不进行断线重连。
	lLogin = CLIENT_Login("10.7.4.24",37777,"3","",&deviceInfo);//登陆设备,用户需另选设备。
	if(lLogin <= 0)
	{
		cout<<"登陆设备失败"<<endl;
	}
	else
	{
		cout<<"登陆设备成功,按任意键退出程序。"<<endl;
		cout<<"网络故障1分钟如果没有恢复,sdk会认为断线,请耐心等待"<<endl;
		_getch();
	}
	CLIENT_Logout(lLogin);
	CLIENT_Cleanup();
	return 0;
}
Exemplo n.º 2
0
/*----------------------------------
函数功能:
调用参数:BASE_PARAM的指针:
调用成功,返回TRUE;调用失败,返回FALSE。其它需要返回的参数,置于结构:BASE_PARAM中。
函数说明:
-----------------------------------*/
_EXT_C_DEVCAM_API BOOL CAM_Init(CommonParam *commonParam){
	if (commonParam == NULL){
		commonParam->devError = InitError;
		return FALSE;
	}

	CLIENT_SetAutoReconnect(AutoConnectFunc,0);

	NET_DEVICEINFO	      deviceInfo = {0};
	int				      error;
	DHDEV_CHANNEL_CFG	  channelConfig = {0};
	DHDEV_SYSTEM_ATTR_CFG systemAttr = {0};
	LDWORD			      bytesReturned;

	commonParam->loginID=CLIENT_Login(commonParam->deviceIP,commonParam->devicePort,commonParam->userName,commonParam->passWord,&deviceInfo,&error);

	if(error != 0){
		commonParam->devError = InitError;
		return FALSE;
	}

	if(!CLIENT_GetDevConfig(commonParam->loginID, DH_DEV_DEVICECFG,-1,&systemAttr,sizeof(systemAttr),&bytesReturned)){
		commonParam->devError = InitError;
		return FALSE;
	}

	if(systemAttr.byDevType == NET_NVR_SERIAL){
		commonParam->deviceType = NET_NVR_SERIAL;
		DEV_ENCODER_CFG_EX encoderConfigEx = {0};
		if(!CLIENT_GetDevConfig(commonParam->loginID, DH_DEV_ENCODER_CFG, -1, &encoderConfigEx,sizeof(encoderConfigEx),&bytesReturned)){
			commonParam->devError = InitError;
			return FALSE;
		}

		commonParam->totalChannels = encoderConfigEx.nChannels;
		commonParam->onlineCameras = new int[encoderConfigEx.nChannels];
		commonParam->cameraParam = new struct tagCommonParam[encoderConfigEx.nChannels];
		for(int i=0;i<encoderConfigEx.nChannels;i++){
			commonParam->onlineCameras[i] = encoderConfigEx.stuDevInfo[i].bDevChnEnable;
			if(encoderConfigEx.stuDevInfo[i].byManuFactory == 22){
				commonParam->onlineCameras[i] = 0;
			}
		}
		
		for(int i = 0;i < encoderConfigEx.nChannels;i++){
			commonParam->cameraParam[i].deviceType = NET_IPC_SERIAL;
			strcpy(commonParam->cameraParam[i].deviceIP,encoderConfigEx.stuDevInfo[i].szDevIp);
			strcpy(commonParam->cameraParam[i].userName,encoderConfigEx.stuDevInfo[i].szDevUser);
			strcpy(commonParam->cameraParam[i].passWord,encoderConfigEx.stuDevInfo[i].szDevPwd);
			commonParam->cameraParam[i].devicePort = encoderConfigEx.stuDevInfo[i].wDevPort;
			commonParam->cameraParam[i].channelNo = encoderConfigEx.stuDevInfo[i].byDecoderID;
		}
	}else if(systemAttr.byDevType == NET_IPC_SERIAL){
		if(commonParam->playHwnd == NULL){
			commonParam->playHwnd = CreateWindow("EDIT",NULL,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,NULL,NULL);
		}
		char *channelName = new char[16*32];
		int channelCount ;
		if(!CLIENT_QueryChannelName(commonParam->loginID,channelName,16*32,&channelCount)){
			commonParam->devError = InitError;
			return FALSE;
		}
		strcpy(commonParam->deviceName,channelName);
		delete []channelName;
		channelName = NULL;
		commonParam->deviceType = NET_IPC_SERIAL;
		CLIENT_GetDevConfig(commonParam->loginID,DH_DEV_CHANNELCFG,0,&channelConfig,sizeof(channelConfig),&bytesReturned);
		GetSize(channelConfig.stMainVideoEncOpt->byImageSize,commonParam->frameWidth,commonParam->frameHeight);
	}else{
		commonParam->devError = InitError;
		return FALSE;
	}

	return TRUE;
}