Search for Access Control Events

If the access control alarms or events are received and stored in the third-party platform, you can search for the alarms or events by setting different search conditions.

  • Make sure you have called NET_DVR_Init to initialize the development environment.

  • Make sure you have called NET_DVR_Login_V40 to log in to device.

Figure 1 Programming Flow of Searching for Access Control Events

  1. Optional: Call NET_DVR_STDXMLConfig to pass through the request URL: GET /ISAPI/AccessControl/GetAcsEvent/capabilities for getting the capability of access control alarm/event search to know the details or notices about search.
    Note:

    To check whether the device supports searching for access control events, you can call NET_DVR_GetDeviceAbility, set the capability type dwAbilityType to "ACS_ABILITY" (macro definition value: 0x801), and set the input parameter pointer pInBuf to the message XML_Desc_AcsAbility for getting the access control capability.

    The capaility is returned in the message XML_AcsAbility by the output parameter pointer pOutBuf. The related node is <isSupportGetDeviceEvent>.

    The capability message XML_Cap_GetAcsEvent is returned.

  2. Call NET_DVR_StartRemoteConfig with "NET_DVR_GET_ACS_EVENT" (command No: 2514) and set IpInBuffer to NET_DVR_ACS_EVENT_COND for setting up persistent connection and set callback function (fRemoteConfigCallback).

    The access control event details are returned in the structure NET_DVR_ACS_EVENT_CFG by the output buffer (lpBuffer) of callback function.

  3. Optional: Call NET_DVR_STDXMLConfig to pass through the request URL: GET /ISAPI/AccessControl/AcsEventTotalNum/capabilities?format=json to get the capability of getting total number of access control events by specific conditions.
  4. Optional: Call NET_DVR_STDXMLConfig to pass through the request URL: POST /ISAPI/AccessControl/AcsEventTotalNum?format=json and set IpInBuffer to the message JSON_AcsEventTotalNumCond for getting the total number of access control events by specific conditions.
  5. Call NET_DVR_StopRemoteConfig to disconnect the persistent connection and finish searching.

Sample Code of Searching for Access Control Event

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

BOOL CALLBACK MSesGCallback(LONG lCommand, NET_DVR_ALARMER *pAlarmer, char *pAlarmInfo, DWORD dwBufLen, void* pUser)
{
	//As the operations with long time consumption are not allowed in the callback function,
        //do not call the API of HCNetSDK.DLL in the callback function.
	//The following code is for reference only, actually, processing data in the callback function is not suggested.
	//for example, process in the message response function as PostMessage
	switch (lCommand) 
	{
	case COMM_ALARM_ACS://Alarm information of access controller
		{
			NET_DVR_ACS_ALARM_INFO struAcsAlarmInfo = {0};
			memcpy(&struAcsAlarmInfo, pAlarmInfo, sizeof(struAcsAlarmInfo));
			//Handle other information in the alarm structure as desired...
			break;
		}
	case COMM_PASSNUM_INFO_ALARM://Number of passed persons
		{
			NET_DVR_PASSNUM_INFO_ALARM struPassnumInfo = {0};
			memcpy(&struPassnumInfo, pAlarmInfo, sizeof(struPassnumInfo));
			//Handle other information in the alarm structure as desired...
			break;
		}
	default:
		break;
	}
	return true;
}
void main()
{
	//---------------------------------------
	//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;
	}

	//Set alarm callback function for card swiping event
	NET_DVR_SetDVRMessageCallBack_V31(MSesGCallback, NULL);
	//Set up channel for uploading alarm information
	NET_DVR_SETUPALARM_PARAM struSetupParam={0};
	struSetupParam.dwSize=sizeof(NET_DVR_SETUPALARM_PARAM);
	
	LONG  lHandle = NET_DVR_SetupAlarmChan_V41(lUserID,&struSetupParam);
	if (lHandle < 0)
	{
		printf("NET_DVR_SetupAlarmChan_V41 error, %d\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup(); 
		return;
	}
	
	//Wait for 60s for receiving captured picture uploaded by device
	Sleep(60000);
	//Close alarm uploading channel
	if (!NET_DVR_CloseAlarmChan_V30(lHandle))
	{
		printf("NET_DVR_CloseAlarmChan_V30 error, %d\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup(); 
		return;
	}
	//Log out
	NET_DVR_Logout(lUserID);
	//Release SDK resource
	NET_DVR_Cleanup();
	return;
}

Call NET_DVR_Logout and NET_DVR_Cleanup to log out and release the resource.