【Card-Based Access Control】Searching For Access Control Event
サンプルプログラム
//
// Device Network SDK (Card-Based Access Control)
// Alarm and Event Receiving
// Search for Access Control Events
// 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;
}