#include "HCNetSDK.h" #include #include #include using namespace std; #include "hikptz.h" void ptzTrack(char *ip, char *userName, char *password, int port, int channel, int xBottom, int xTop, int yBottom, int yTop) { // 初始化 NET_DVR_Init(); //设置连接时间与重连时间 NET_DVR_SetConnectTime(2000, 1); NET_DVR_SetReconnect(10000, true); //设置异常消息回调函数 NET_DVR_SetExceptionCallBack_V30(0, NULL, NULL, NULL); // 注册设备 //登录参数,包括设备地址、登录用户、密码等 NET_DVR_USER_LOGIN_INFO struLoginInfo = {0}; struLoginInfo.bUseAsynLogin = 0; //同步登录方式 strcpy(struLoginInfo.sDeviceAddress, ip); //设备IP地址 struLoginInfo.wPort = port; //设备服务端口 strcpy(struLoginInfo.sUserName, userName); //设备登录用户名 strcpy(struLoginInfo.sPassword, password); //设备登录密码 //设备信息, 输出参数 NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0}; LONG lUserID; lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40); if (lUserID < 0) { printf("Login failed, error code: %d\n", NET_DVR_GetLastError()); NET_DVR_Cleanup(); return; } // LPNET_DVR_POINT_FRAME zoneInfo = {0}; // zoneInfo->xTop = xTop; // // zoneInfo->yTop = yTop; // // zoneInfo->xBottom = xBottom; // // zoneInfo->yBottom = yBottom; // int iChannel = channel; //设备通道号 DWORD dwPTZCommand = PAN_LEFT; DWORD dwStop = 0; if (!NET_DVR_PTZControl_Other(lUserID, iChannel, PAN_LEFT,dwStop)) { printf("PAN_LEFT start failed, error code: %d\n", NET_DVR_GetLastError()); NET_DVR_Logout(lUserID); NET_DVR_Cleanup(); return; } Sleep(3000); dwStop = 1; //停止转动 if(!NET_DVR_PTZControl_Other(lUserID, iChannel, PAN_LEFT, dwStop)) { printf("PAN_LEFT stop failed, error code: %d\n", NET_DVR_GetLastError()); } //注销用户 NET_DVR_Logout(lUserID); //释放SDK资源 NET_DVR_Cleanup(); return; } void toPreset(char *ip, char *userName, char *password, int port, int channel) { // 初始化 NET_DVR_Init(); //设置连接时间与重连时间 NET_DVR_SetConnectTime(2000, 1); NET_DVR_SetReconnect(10000, true); //--------------------------------------- //设置异常消息回调函数 NET_DVR_SetExceptionCallBack_V30(0, NULL, NULL, NULL); //--------------------------------------- // 注册设备 LONG lUserID; //登录参数,包括设备地址、登录用户、密码等 NET_DVR_USER_LOGIN_INFO struLoginInfo = {0}; struLoginInfo.bUseAsynLogin = 0; //同步登录方式 strcpy(struLoginInfo.sDeviceAddress, ip); //设备IP地址 struLoginInfo.wPort = port; //设备服务端口 strcpy(struLoginInfo.sUserName, userName); //设备登录用户名 strcpy(struLoginInfo.sPassword, password); //设备登录密码 //设备信息, 输出参数 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; } int iChannel = channel; //设备通道号 DWORD dwPTZCommand = GOTO_PRESET; //转到预置点 if (!NET_DVR_PTZPreset_Other(lUserID, iChannel, GOTO_PRESET, 1)) { printf("PAN_LEFT start failed, error code: %d\n", NET_DVR_GetLastError()); NET_DVR_Logout(lUserID); NET_DVR_Cleanup(); return; } //注销用户 NET_DVR_Logout(lUserID); //释放SDK资源 NET_DVR_Cleanup(); return; }