Remotely Control Door

You can remotely control door, i.e., open, close, remain open, and remain close, by the access controller.

Call NET_DVR_ControlGateway to remotely control door.

Note:
  • If the device is configured with multi-factor authentication mode, this API is available only when the parameter dwGroupNo in the structure NET_DVR_GROUP_COMBINATION_INFO_V50 is set to "0xffffffff".

  • Before controlling door by calling the above API, you should call NET_DVR_Init and NET_DVR_Login_V40 to initialize the resources and log in to device.

  • After controlling door, you should call NET_DVR_Logout and NET_DVR_Cleanup to log out and release the resource.

Figure 1 Door Control Example Page

Sample Code for Remotely Controlling Door

#include <stdio.h>
#include <iostream>
#include <afx.h>
#include "Windows.h"
#include "HCNetSDK.h"
using namespace std;

void main()
{
	//---------------------------------------
	//Initialize
	NET_DVR_Init();
	
	//Set connection timeout and reconnection function
	NET_DVR_SetConnectTime(2000, 1);
	NET_DVR_SetReconnect(10000, true);
	
	//---------------------------------------
	//Initialize
	NET_DVR_Init();
	
	//Set connection timeout and reconnection function
	NET_DVR_SetConnectTime(2000, 1);
	NET_DVR_SetReconnect(10000, true);
	//---------------------------------------
	//Log in to device
	LONG lUserID;
	//Login parameters, including device IP address, user name, password, and so on
	NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
	struLoginInfo.bUseAsynLogin = 0; //Synchronous login mode
	strcpy(struLoginInfo.sDeviceAddress, "192.168.1.64"); //Device IP address
	struLoginInfo.wPort = 8000; //Device service port number
	strcpy(struLoginInfo.sUserName, "admin"); //User name
	strcpy(struLoginInfo.sPassword, "abcd1234"); //Password

	//Device information, output parameter
	NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};
	
	lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
	if (lUserID < 0)
	{
		printf("Login failed, error code: %d\n", NET_DVR_GetLastError());
		NET_DVR_Cleanup();
		return;
	}

	//Open door, take door 1 as an example
	BOOL bRet;
	LONG lGatewayIndex = 1;//Access controller No., starts from 1, -1: control all doors 
	DWORD dwStaic = 1;//Command No.: 0-Close, 1-Open, 2-Remain Open, 3-Remain Closed 

	bRet = NET_DVR_ControlGateway(lUserID,lGatewayIndex,dwStaic);
	if (!bRet)
	{
		printf("NET_DVR_ControlGateway failed, error:%d\n",NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup();
		return;
	}
	
	//---------------------------------------
	//Exit
	Sleep(5000);

	//Log out
	NET_DVR_Logout(lUserID);
	//Release SDK resource
	NET_DVR_Cleanup();
	return;
}