You can configure the week or holiday schedule to regularly control the authentication modes (e.g., by card, by card+password, by fingerprint, by fingerprint+card, and so on) in some specific time periods.
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.
#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); //--------------------------------------- //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 card reader authentication mode schedule, template 1 linked to card reader 1 NET_DVR_CARD_READER_PLAN struCardReaderPlan = {0}; struCardReaderPlan.dwSize = sizeof(struCardReaderPlan); struCardReaderPlan.dwTemplateNo = 1;//Schedule template 1 BOOL bRet1 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_CARD_READER_PLAN, 1, \ &struCardReaderPlan, sizeof(struCardReaderPlan)); if (!bRet1) { printf("Setting card reader authentication mode schedule failed, error:%d.\n", NET_DVR_GetLastError()); NET_DVR_Logout(lUserID); NET_DVR_Cleanup(); return; } //Set card reader authentication mode schedule template 1, template 1 links to week schedule 1 and holiday group 1 CString m_csTemplateName = "card reader authentication mode schedule template 1"; NET_DVR_PLAN_TEMPLATE struPlanTem = {0}; struPlanTem.dwSize = sizeof(struPlanTem); struPlanTem.byEnable = 1;//Enable or not: 0-No, 1-Yes strncpy((char *)struPlanTem.byTemplateName, (LPCTSTR)m_csTemplateName, TEMPLATE_NAME_LEN); struPlanTem.dwWeekPlanNo = 2;//Week schedule No.2 struPlanTem.dwHolidayGroupNo[0] = 2;//Holiday group No.2, up to 16 holiday groups can be linked to each schedule BOOL bRet2 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_VERIFY_PLAN_TEMPLATE, 1, \ &struPlanTem, sizeof(struPlanTem)); if (!bRet2) { printf("Setting card reader authentication mode schedule template failed, error:%d.\n", NET_DVR_GetLastError()); NET_DVR_Logout(lUserID); NET_DVR_Cleanup(); return; } //Set week schedule 2 for card reader authentication mode NET_DVR_WEEK_PLAN_CFG struWeekPlan2 = {0}; struWeekPlan2.dwSize = sizeof(struWeekPlan2); struWeekPlan2.byEnable = 1;//Enable week schedule NET_DVR_SINGLE_PLAN_SEGMENT struSinglePlanSegment = {0}; LPNET_DVR_SINGLE_PLAN_SEGMENT lpPlanSegment = &struSinglePlanSegment; struSinglePlanSegment.byEnable = 1; struSinglePlanSegment.byVerifyMode = 4;//Authentication mode: 0-invalid, 1-sleepy, 2-card+password, 3-card, //4-card or password, 5-fingerprint, 6-fingerprint+password, 7-fingerprint or card, //8-fingerprint+card, 9-fingerprint+card+password struSinglePlanSegment.struTimeSegment.struBeginTime.byHour = 0;//Start time struSinglePlanSegment.struTimeSegment.struBeginTime.byMinute = 0; struSinglePlanSegment.struTimeSegment.struBeginTime.bySecond = 0; struSinglePlanSegment.struTimeSegment.struEndTime.byHour = 23;//End time struSinglePlanSegment.struTimeSegment.struEndTime.byMinute = 59; struSinglePlanSegment.struTimeSegment.struEndTime.bySecond = 59; /*Up to 8 time periods can be set for each day, and you can set different authentication modes for each time period Here only takes setting one period for each day*/ for (int iDate = 0; iDate<MAX_DAYS; iDate++) { memcpy(&struWeekPlan2.struPlanCfg[iDate][0], lpPlanSegment, sizeof(struSinglePlanSegment)); } BOOL bRet3 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_VERIFY_WEEK_PLAN, 2, \ &struWeekPlan2, sizeof(struWeekPlan2)); if (!bRet3) { printf("Setting week schedule for card reader authentication mode failed,error:%d.\n", NET_DVR_GetLastError()); NET_DVR_Logout(lUserID); NET_DVR_Cleanup(); return; } //Set holiday group for card reader authentication mode CString m_csGroupName = "Holiday group 2"; NET_DVR_HOLIDAY_GROUP_CFG struHolidayGroup2 = {0}; struHolidayGroup2.dwSize = sizeof(struHolidayGroup2); struHolidayGroup2.byEnable = 1; strncpy((char *)struHolidayGroup2.byGroupName, (LPCTSTR)m_csGroupName, HOLIDAY_GROUP_NAME_LEN); struHolidayGroup2.dwHolidayPlanNo[0] = 2;//Holiday group 1 links to holiday schedule 1, //up to 16 holiday schedules can be linked to one holiday group BOOL bRet4 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_VERIFY_HOLIDAY_GROUP, 2, \ &struHolidayGroup2, sizeof(struHolidayGroup2)); if (!bRet4) { printf("设Setting holiday group for card reader authentication mode failed, error:%d.\n", NET_DVR_GetLastError()); NET_DVR_Logout(lUserID); NET_DVR_Cleanup(); return; } //Set holiday schedule for card reader authentication mode NET_DVR_HOLIDAY_PLAN_CFG struHolidayPlan2 = {0}; struHolidayPlan2.dwSize = sizeof(struHolidayPlan2); struHolidayPlan2.byEnable = 1; struHolidayPlan2.struBeginDate.wYear = 2017;//Holiday start date struHolidayPlan2.struBeginDate.byMonth = 10; struHolidayPlan2.struBeginDate.byDay = 1; struHolidayPlan2.struEndDate.wYear = 2017;//Holiday end date struHolidayPlan2.struEndDate.byMonth = 10; struHolidayPlan2.struEndDate.byDay = 7; //Copy the week schedule parameters to holiday schedule of card reader authentication mode memcpy(struHolidayPlan2.struPlanCfg, struWeekPlan2.struPlanCfg, sizeof(NET_DVR_SINGLE_PLAN_SEGMENT)*MAX_DAYS*MAX_TIMESEGMENT_V30); BOOL bRet5 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_VERIFY_HOLIDAY_PLAN, 2, \ &struHolidayPlan2, sizeof(struHolidayPlan2)); if (!bRet5) { printf("Setting holiday schedule for card reader authentication mode 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; }
Call NET_DVR_Logout and NET_DVR_Cleanup to log out and release the resource.