红外遥控器操作海康威视摄像头云台

环境: win10(10.0.16299.0)+ vs2017
sdk版本:CH-HCNetSDK_Win32_V5.3.2.15_build20171122

内容分4个部分

1、控制台调用海康威视sdk操作摄像头云台

2、打开PC串口接收arduino发来的信号

3、arduino 端接收红外遥控器信号

4、整合后的代码


第一部分:控制台调用海康威视sdk操作摄像头云台

#include <cstdlib>  
#include <cstring>  
#include <iostream> 
#include "HCNetSDK.h"  
#include <time.h>  
#include <windows.h>

using namespace std;
void Demo_SDK_Version(); 


/*
sdk版本获取函数--------------------- */
void Demo_SDK_Version()
{
	unsigned int uiVersion = NET_DVR_GetSDKBuildVersion();

	char strTemp[1024] = { 0 };
	sprintf_s(strTemp, "HCNetSDK V%d.%d.%d.%d\n", \
		(0xff000000 & uiVersion) >> 24, \
		(0x00ff0000 & uiVersion) >> 16, \
		(0x0000ff00 & uiVersion) >> 8, \
		(0x000000ff & uiVersion));
	printf(strTemp);
}

//定义异常消息回调函数
void CALLBACK g_ExceptionCallBack(DWORD dwType, LONG lUserID, LONG lHandle, void *pUser)
{
	char tempbuf[256] = { 0 };
	switch (dwType)
	{
	case EXCEPTION_RECONNECT:    //预览时重连  
		printf("----------reconnect--------%d\n", time(NULL));
		break;
	default:
		break;
	}
}

int main() {
	// 初始化  
	NET_DVR_Init();
	//设置连接时间与重连时间  
	NET_DVR_SetConnectTime(2000, 1);
	NET_DVR_SetReconnect(10000, true);
	Demo_SDK_Version();//  获取 SDK  的版本号和 build  信息
	char sdklog[]="./sdkLog"; //windows 默认值为"C:\\SdkLog\\"
	NET_DVR_SetLogToFile(3, sdklog);//启用写日志文件 

	// 注册设备  
	LONG lUserID;
	NET_DVR_DEVICEINFO_V30 struDeviceInfo;
	char DeviceIP[16] = "22.166.156.51";
	char cUserName[100] = "admin";
	char cPassword[100] = "12345";
	char cUserChoose = 'r';//菜单

	lUserID = NET_DVR_Login_V30(DeviceIP, 8000, cUserName, cPassword, &struDeviceInfo);
	if (lUserID < 0)
	{
		printf("Login error, %d\n", NET_DVR_GetLastError());
		NET_DVR_Cleanup();
		cin >> cUserChoose;
		return 0;
	}

	//设置异常消息回调函数  
	NET_DVR_SetExceptionCallBack_V30(0, NULL, g_ExceptionCallBack, NULL);


	//功能
	
	
	while ('q' != cUserChoose)
	{
		printf("\n");
		printf("Input 1, 获取sdk版本\n");
		printf("      2, 测试云台\n");	
		printf("      3, 预置点3操作\n");
		printf("      4, 预置点1操作\n");
		printf("      q, 退出.\n");
		printf("Input:");

		cin >> cUserChoose;

		switch (cUserChoose)
		{
		case '1':
			Demo_SDK_Version();//  获取 SDK  的版本号和 build  信息
			break;
		case '2':
			//控制云台 向左	
			BOOL ret;
			NET_DVR_PTZControlWithSpeed_Other(lUserID, 1, PAN_LEFT, 0, 1);
			Sleep(1000);
			ret = NET_DVR_PTZControlWithSpeed_Other(lUserID, 1, PAN_LEFT, 1,1);

			if (!ret)
			{
				printf("云台控制失败!\n");
				NET_DVR_Cleanup();
				cin >> cUserChoose;
				return 0;				
			}
			
			break;
		
		case '3':

			NET_DVR_PTZPreset_Other(lUserID, 1, GOTO_PRESET, 3);
				break;
		case '4':

			NET_DVR_PTZPreset_Other(lUserID, 1, GOTO_PRESET, 1);

			break;
		default:
			break;
		}
	}



	//注销用户  
	NET_DVR_Logout(lUserID);
	//释放 SDK 资源
	NET_DVR_Cleanup();


	return 0;
}

2、打开PC串口接收arduino发来的信号

/*
*  控制台串口收发_v0.1.c
*  2018.02.19 cngwj
*	1.控制台串口收发
*
*/


#include <iostream>  
#include <cstdlib>  
#include <windows.h>  




HANDLE hComm;
OVERLAPPED OverLapped;
COMSTAT Comstat;
DWORD dwCommEvents;

bool OpenPort();  //打开串口  
bool SetupDCB(int rate_arg);  //设置DCB  
bool SetupTimeout(DWORD ReadInterval, DWORD ReadTotalMultiplier, DWORD
ReadTotalConstant, DWORD WriteTotalMultiplier, DWORD WriteTotalConstant);   //设置超时  
void ReciveChar();   //接收字符  
bool WriteChar(char* szWriteBuffer, DWORD dwSend);  //发送字符  

bool OpenPort()
{
	hComm = CreateFile(L"COM6",
		GENERIC_READ | GENERIC_WRITE,
		0,
		0,
		OPEN_EXISTING,
		FILE_FLAG_OVERLAPPED,
		0);
	if (hComm == INVALID_HANDLE_VALUE)
		return FALSE;
	else
		return true;
}

bool SetupDCB(int rate_arg)
{
	DCB dcb;
	memset(&dcb, 0, sizeof(dcb));
	if (!GetCommState(hComm, &dcb))//获取当前DCB配置  
	{
		return FALSE;
	}
	dcb.DCBlength = sizeof(dcb);
	/* ---------- Serial Port Config ------- */
	dcb.BaudRate = rate_arg;
	dcb.Parity = NOPARITY;
	dcb.fParity = 0;
	dcb.StopBits = ONESTOPBIT;
	dcb.ByteSize = 8;
	dcb.fOutxCtsFlow = 0;
	dcb.fOutxDsrFlow = 0;
	dcb.fDtrControl = DTR_CONTROL_DISABLE;
	dcb.fDsrSensitivity = 0;
	dcb.fRtsControl = RTS_CONTROL_DISABLE;
	dcb.fOutX = 0;
	dcb.fInX = 0;
	dcb.fErrorChar = 0;
	dcb.fBinary = 1;
	dcb.fNull = 0;
	dcb.fAbortOnError = 0;
	dcb.wReserved = 0;
	dcb.XonLim = 2;
	dcb.XoffLim = 4;
	dcb.XonChar = 0x13;
	dcb.XoffChar = 0x19;
	dcb.EvtChar = 0;
	if (!SetCommState(hComm, &dcb))
	{
		return false;
	}
	else
		return true;
}

bool SetupTimeout(DWORD ReadInterval, DWORD ReadTotalMultiplier, DWORD
	ReadTotalConstant, DWORD WriteTotalMultiplier, DWORD WriteTotalConstant)
{
	COMMTIMEOUTS timeouts;
	timeouts.ReadIntervalTimeout = ReadInterval;
	timeouts.ReadTotalTimeoutConstant = ReadTotalConstant;
	timeouts.ReadTotalTimeoutMultiplier = ReadTotalMultiplier;
	timeouts.WriteTotalTimeoutConstant = WriteTotalConstant;
	timeouts.WriteTotalTimeoutMultiplier = WriteTotalMultiplier;
	if (!SetCommTimeouts(hComm, &timeouts))
	{
		return false;
	}
	else
		return true;
}

void ReciveChar()
{
	bool bRead = TRUE;
	bool bResult = TRUE;
	DWORD dwError = 0;
	DWORD BytesRead = 0;
	char RXBuff;
	for (;;)
	{
		bResult = ClearCommError(hComm, &dwError, &Comstat);
		if (Comstat.cbInQue == 0)
			continue;
		if (bRead)
		{
			bResult = ReadFile(hComm,  //通信设备(此处为串口)句柄,由CreateFile()返回值得到  
				&RXBuff,  //指向接收缓冲区  
				1,  //指明要从串口中读取的字节数  
				&BytesRead,   //  
				&OverLapped);  //OVERLAPPED结构  
			//std::cout << RXBuff << std::endl;
			std::cout << RXBuff;
			if (!bResult)
			{
				switch (dwError == GetLastError())
				{
				case ERROR_IO_PENDING:
					bRead = FALSE;
					break;
				default:
					break;
				}
			}
		}
		else
		{
			bRead = TRUE;
		}
	}
	if (!bRead)
	{
		bRead = TRUE;
		bResult = GetOverlappedResult(hComm,
			&OverLapped,
			&BytesRead,
			TRUE);
	}
}

bool WriteChar(const char* szWriteBuffer, DWORD dwSend)
{
	bool bWrite = TRUE;
	bool bResult = TRUE;
	DWORD BytesSent = 0;
	HANDLE hWriteEvent = NULL;
	ResetEvent(hWriteEvent);
	if (bWrite)
	{
		OverLapped.Offset = 0;
		OverLapped.OffsetHigh = 0;
		bResult = WriteFile(hComm,  //通信设备句柄,CreateFile()返回值得到  
			szWriteBuffer,  //指向写入数据缓冲区  
			dwSend,  //设置要写的字节数  
			&BytesSent,  //  
			&OverLapped);  //指向异步I/O数据  
		if (!bResult)
		{
			DWORD dwError = GetLastError();
			switch (dwError)
			{
			case ERROR_IO_PENDING:
				BytesSent = 0;
				bWrite = FALSE;
				break;
			default:
				break;
			}
		}
	}
	if (!bWrite)
	{
		bWrite = TRUE;
		bResult = GetOverlappedResult(hComm,
			&OverLapped,
			&BytesSent,
			TRUE);
		if (!bResult)
		{
			std::cout << "GetOverlappedResults() in WriteFile()" << std::endl;
		}
	}
	if (BytesSent != dwSend)
	{
		std::cout << "WARNING: WriteFile() error.. Bytes Sent:" << BytesSent << "; Message Length: " << strlen((char*)szWriteBuffer) << std::endl;
	}
	return TRUE;
}
int main()
{
	if (OpenPort())
		std::cout << "Open port success" << std::endl;
	if (SetupDCB(9600))
		std::cout << "Set DCB success" << std::endl;
	if (SetupTimeout(0, 0, 0, 0, 0))
		std::cout << "Set timeout success" << std::endl;
	PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
	WriteChar("Please send data:", 20);
	std::cout << "Received data:";
	ReciveChar();
	return EXIT_SUCCESS;
}

3、arduino 接收红外遥控器信号

#include <IRremote.h>  
 char code = 'x';   
 char code1 = 'y'; 
int PIN_RECV = 11;  
IRrecv irrecv(PIN_RECV);  
decode_results results;  

   
void setup()  
{  
  Serial.begin(9600);  
  irrecv.enableIRIn(); 
   pinMode(LED_BUILTIN, OUTPUT);//指示灯
   pinMode(12, OUTPUT);//指示灯
}  
   
void loop() {  

  if (irrecv.decode(&results))
  {    
       // Serial.println(results.value);   
       digitalWrite(LED_BUILTIN, HIGH);          
     
  //遥控菜单
  switch (results.value)
    {     
    case 50137335:    
        code = '0';    
		digitalWrite(12, HIGH); 		
		break;
    case 50167935:    
        code = '1';      
		digitalWrite(12, HIGH); 
		break;
    case 50151615:   
        code = '2';     
		digitalWrite(12, HIGH); 	   
		break;    
    case 50184255:  
		code = '3';    
		digitalWrite(12, HIGH); 		
		break; 
    case 50143455:  
		code = '4'; 
		digitalWrite(12, HIGH); 
		break;     
	case 50176095:  
		code = '5'; 
		digitalWrite(12, HIGH); 
		break;  
	case 50159775:  
		code = '6';  
		digitalWrite(12, HIGH); 
		break;  
    case 50192415:  
		code = '7';  
		digitalWrite(12, HIGH); 
		break;  
    case 50139375:  
		code = '8';  
		digitalWrite(12, HIGH); 
		break;  
    case 50172015:  
		code = '9';  
		digitalWrite(12, HIGH); 
		break;   
    case 50155695:    
        code = 'a'; 
        code1 = 'a';  
		digitalWrite(12, HIGH); 
		break;
    case 50198535:    
        code = 'b'; 
        code1 = 'b';  
		digitalWrite(12, HIGH); 
		break;    
    case 50182215:  
       code = 'c'; 
       code1 = 'c';  
		digitalWrite(12, HIGH); 
		break; 
    case 50165895:  
       code = 'd'; 
       code1 = 'd'; 
		digitalWrite(12, HIGH);  
    break;   
    case 50141415:  
       code = 'e'; 
       code1 = 'e';  
		digitalWrite(12, HIGH); 
    break; 
    case 50174055:  
      code = 'f'; 
      code1 = 'f'; 
		digitalWrite(12, HIGH);  
      break;         
    case 50157735:  
      code = 'h'; 
      code1 = 'h';  
		digitalWrite(12, HIGH); 
      break;  
    case 50190375:  
      code = 'i'; 
      code1 = 'i'; 
		digitalWrite(12, HIGH); 
    break;  
      
    case 50185275:  
       code = 'q';  
		digitalWrite(12, HIGH); 
    break; 
      
//通道选择 大写字母  

    case 50186295:    
        code = 'A';    
         digitalWrite(12, HIGH); 
        break;
    case 50145495:    
        code = 'B';   
		digitalWrite(12, HIGH); 		
    break;    
    case 50178135: 
        code = 'C'; 
		digitalWrite(12, HIGH); 
    break; 
    case 50161815:  
        code = 'D';  
		digitalWrite(12, HIGH); 		
        break;   
    case 50194455:  
        code = 'E'; 
		digitalWrite(12, HIGH); 		
        break;    
    case  50188335:  
        code = 'F';
		digitalWrite(12, HIGH); 		
        break;    
    default:
        //Serial.print(results.value);   
        // Serial.print("x"); 
        if (!(code1 == code)){           
             code = 'x';              
          }
    break;
    } 
  
  delay(300); 
  Serial.print(code); 
  digitalWrite(LED_BUILTIN, LOW); 
  digitalWrite(12, LOW); 
    irrecv.resume();  
  } 
 
}  

4、整合后的代码

/************************************************************************
* Copyright(c) 2018  一念无明
* All rights reserved.
*
* File:    海康威视sdk_0.3.c
* Brief: 红外遥控操作海康威视摄像机
* Version: 0.3
* Author: 一念无明
* Email:zhunmeng@live.com
* Date:    2018.2.7
* History:
2018.2.13 控制台调用海康威视sdk
2018.2.15 加入串口
2018.2.23 加入遥控器操作
2018.2.25 加入多通道选择



************************************************************************/
//-------------------------------------------------------------------------
//头文件
#include <cstdlib>  
#include <cstring>  
#include <iostream> 
#include "HCNetSDK.h"  
#include <windows.h>
//获取系统时间
#include <time.h>

using namespace std;

//注册设备
LONG IUserID;//摄像机设备
NET_DVR_DEVICEINFO_V30 struDeviceInfo;//设备信息
char *sDVRIP;//抓拍摄像机设备IP地址
short wDVRPort = 8000;//设备端口号
char sUserName[] = "admin";//登录的用户名
char sPassword[] = "12345";//用户密码

HANDLE hComm; //句柄
OVERLAPPED OverLapped;
COMSTAT Comstat;
DWORD dwCommEvents;
char sec = { 0 }; //接收串口信号
//---------------------------------------------------------------------------------
//函数声明
void Init();//初始化
void Connect();//设置连接事件与重连时间
bool Login(char *sDVRIP, short wDVRPort, char *sUserName, char *sPassword);//注册摄像机设备

void Demo_SDK_Version(); //获取sdk版本
bool OpenPort();  //打开串口  
bool SetupDCB(int rate_arg);  //设置DCB  
bool SetupTimeout(DWORD ReadInterval, DWORD ReadTotalMultiplier, DWORD ReadTotalConstant, DWORD WriteTotalMultiplier, DWORD WriteTotalConstant);   //设置超时  
void fflush();//清空缓冲区
void ReciveChar(char *par);   //接收字符  
void menu();
//---------------------------------------------------------------------------------------------------
//函数定义

//初始化
void Init()
{
	NET_DVR_Init();//初始化
	Demo_SDK_Version();//获取 SDK  的版本号和 build  信息
}

//设置连接事件与重连时间
void Connect()
{
	NET_DVR_SetConnectTime(2000, 1);
	NET_DVR_SetReconnect(10000, true);
}

//注册摄像机设备
bool Login(char *sDVRIP, short wDVRPort, char *sUserName, char *sPassword)
{
	IUserID = NET_DVR_Login_V30(sDVRIP, wDVRPort, sUserName, sPassword, &struDeviceInfo);

	if (IUserID < 0)
	{
		std::cout << "Login Failed! Error number:" << NET_DVR_GetLastError() << std::endl;
		NET_DVR_Cleanup();
		return false;
	}
	else
	{
		std::cout << "Login Successfully!" << std::endl;
		return true;
	}

}

//Demo_SDK_Version()海康威视sdk版本获取函数
void Demo_SDK_Version()
{
	unsigned int uiVersion = NET_DVR_GetSDKBuildVersion();

	char strTemp[1024] = { 0 };
	sprintf_s(strTemp, "HCNetSDK V%d.%d.%d.%d\n", \
		(0xff000000 & uiVersion) >> 24, \
		(0x00ff0000 & uiVersion) >> 16, \
		(0x0000ff00 & uiVersion) >> 8, \
		(0x000000ff & uiVersion));
	printf(strTemp);
}

//定义异常消息回调函数
void CALLBACK g_ExceptionCallBack(DWORD dwType, LONG lUserID, LONG lHandle, void *pUser)
{
	char tempbuf[256] = { 0 };
	switch (dwType)
	{
	case EXCEPTION_RECONNECT:    //预览时重连  
		printf("----------reconnect--------%d\n", time(NULL));
		break;
	default:
		break;
	}
}

//打开串口  
bool OpenPort() {
	LPCSTR S_Port = { "COM6" };
	hComm = CreateFile(S_Port,
		GENERIC_READ | GENERIC_WRITE,
		0,
		0,
		OPEN_EXISTING,
		FILE_FLAG_OVERLAPPED,
		0);
	if (hComm == INVALID_HANDLE_VALUE)
		return FALSE;
	else
		return true;
}

//设置DCB  
bool SetupDCB(int rate_arg)
{
	DCB dcb;
	memset(&dcb, 0, sizeof(dcb));
	if (!GetCommState(hComm, &dcb))//获取当前DCB配置  
	{
		return FALSE;
	}
	dcb.DCBlength = sizeof(dcb);
	/* ---------- Serial Port Config ------- */
	dcb.BaudRate = rate_arg;
	dcb.Parity = NOPARITY;
	dcb.fParity = 0;
	dcb.StopBits = ONESTOPBIT;
	dcb.ByteSize = 8;
	dcb.fOutxCtsFlow = 0;
	dcb.fOutxDsrFlow = 0;
	dcb.fDtrControl = DTR_CONTROL_DISABLE;
	dcb.fDsrSensitivity = 0;
	dcb.fRtsControl = RTS_CONTROL_DISABLE;
	dcb.fOutX = 0;
	dcb.fInX = 0;
	dcb.fErrorChar = 0;
	dcb.fBinary = 1;
	dcb.fNull = 0;
	dcb.fAbortOnError = 0;
	dcb.wReserved = 0;
	dcb.XonLim = 2;
	dcb.XoffLim = 4;
	dcb.XonChar = 0x13;
	dcb.XoffChar = 0x19;
	dcb.EvtChar = 0;
	if (!SetCommState(hComm, &dcb))
	{
		return false;
	}
	else
		return true;
}

//设置超时  
bool SetupTimeout(DWORD ReadInterval, DWORD ReadTotalMultiplier, DWORD ReadTotalConstant, DWORD WriteTotalMultiplier, DWORD WriteTotalConstant)
{
	COMMTIMEOUTS timeouts;
	timeouts.ReadIntervalTimeout = ReadInterval;
	timeouts.ReadTotalTimeoutConstant = ReadTotalConstant;
	timeouts.ReadTotalTimeoutMultiplier = ReadTotalMultiplier;
	timeouts.WriteTotalTimeoutConstant = WriteTotalConstant;
	timeouts.WriteTotalTimeoutMultiplier = WriteTotalMultiplier;
	if (!SetCommTimeouts(hComm, &timeouts))
	{
		return false;
	}
	else
		return true;
}

//清空缓冲区
void fflush() {
	//PurgeComm()函数--清空缓冲区 
	PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
}

//接收字符
void ReciveChar(char* prt)
{
	bool bRead = TRUE;
	bool bResult = TRUE;
	DWORD dwError = 0;
	DWORD BytesRead = 0;
	char RXBuff;

	bResult = ClearCommError(hComm, &dwError, &Comstat);
	for (; Comstat.cbInQue>0;)
	{
		bResult = ClearCommError(hComm, &dwError, &Comstat);
		if (Comstat.cbInQue == 0)
			continue;
		if (bRead)
		{
			bResult = ReadFile(hComm,  //通信设备(此处为串口)句柄,由CreateFile()返回值得到  
				&RXBuff,  //指向接收缓冲区  
				1,  //指明要从串口中读取的字节数  
				&BytesRead,   //  
				&OverLapped);  //OVERLAPPED结构  
							   //std::cout << RXBuff << std::endl;
			std::cout << RXBuff;
			*prt = RXBuff;

			if (!bResult)
			{
				switch (dwError == GetLastError())
				{
				case ERROR_IO_PENDING:
					bRead = FALSE;
					break;
				default:
					break;
				}
			}
		}
		else
		{
			bRead = TRUE;
		}
	}
	if (!bRead)
	{
		bRead = TRUE;
		bResult = GetOverlappedResult(hComm,
			&OverLapped,
			&BytesRead,
			TRUE);
	}

}
//红外遥控菜单功能
void menu() {

	//遥控菜单功能
	BOOL ret;  //云台控制返回参数
	printf("\n");
	printf("Input 0, 注销用户\n");
	printf("      1, 预置点1\n");
	printf("      2, 预置点2\n");
	printf("      A, 办公楼\n");
	printf("      B, 办公楼前\n");
	printf("      C, 宿舍楼\n");
	printf("      a, 云台左转\n");
	printf("      b, 云台右转\n");
	printf("      c, 云台上仰\n");
	printf("      d, 云台下俯\n");
	printf("      e, 放大\n");
	printf("      f, 缩小\n");
	printf("      q, 退出.\n");
	printf("Input:");

	fflush();//清空缓冲区
	char A_IP[] = "22.166.156.49";
	char B_IP[] = "22.166.156.50";
	char C_IP[] = "22.166.156.51";
	char D_IP[] = "";
	char E_IP[] = "";
	char F_IP[] = "";
	while ('q' != sec)
	{

		fflush();//清空缓冲区	
		Sleep(100);
		sec = { 0 };
		ReciveChar(&sec);//接收串口控制信号				

		NET_DVR_SetExceptionCallBack_V30(0, NULL, g_ExceptionCallBack, NULL);//设置异常消息回调函数  
		switch (sec)
		{
		case 'A':
			NET_DVR_Logout(IUserID);
			sDVRIP = A_IP;
			Login(sDVRIP, wDVRPort, sUserName, sPassword); //注册设备
			break;
		case 'B':
			NET_DVR_Logout(IUserID);
			sDVRIP = B_IP;
			Login(sDVRIP, wDVRPort, sUserName, sPassword); 
			break;
		case 'C':
			NET_DVR_Logout(IUserID);
			sDVRIP = C_IP;
			Login(sDVRIP, wDVRPort, sUserName, sPassword); 
			break;
		case 'D':
			NET_DVR_Logout(IUserID);
			sDVRIP = D_IP;
			Login(sDVRIP, wDVRPort, sUserName, sPassword); 
			break;
		case 'E':
			NET_DVR_Logout(IUserID);
			sDVRIP = E_IP;
			Login(sDVRIP, wDVRPort, sUserName, sPassword); 
			break;
		case 'F':
			NET_DVR_Logout(IUserID);
			sDVRIP = F_IP;
			Login(sDVRIP, wDVRPort, sUserName, sPassword); 
			break;
		case '0':
			//注销用户  
			NET_DVR_Logout(IUserID);
			printf("注销用户");
			break;

		case '1':
			//预置点1
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 1);
			printf("预置点1");
			break;
		case '2':
			//预置点2
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 2);
			printf("预置点2");
			break;
		case '3':
			//预置点2
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 3);
			printf("预置点3");
			break;
		case '4':
			//预置点2
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 4);
			printf("预置点4");
			break;
		case '5':
			//预置点2
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 5);
			printf("预置点5");
			break;
		case '6':
			//预置点2
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 6);
			printf("预置点6");
			break;
		case '7':
			//预置点2
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 7);
			printf("预置点7");
			break;
		case '8':
			//预置点2
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 8);
			printf("预置点8");
			break;
		case '9':
			//预置点2
			NET_DVR_PTZPreset_Other(IUserID, 1, GOTO_PRESET, 9);
			printf("预置点9");
			break;

		case 'a':
			//云台 左	
			printf("左");
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, PAN_LEFT, 0, 4);
			Sleep(250);
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, PAN_LEFT, 1, 4);
			break;

		case 'b':
			//云台 右	
			printf("右");
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, PAN_RIGHT, 0, 4);
			Sleep(250);
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, PAN_RIGHT, 1, 4);
			break;
		case 'c':
			//云台 上		
			printf("上");
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, TILT_UP, 0, 4);
			Sleep(250);
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, TILT_UP, 1, 4);
			break;
		case 'd':
			//云台 下	
			printf("下");
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, TILT_DOWN, 0, 4);
			Sleep(250);
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, TILT_DOWN, 1, 4);
			break;
		case 'e':
				
			printf("放大");
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, ZOOM_IN, 0, 4);
			Sleep(500);
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, ZOOM_IN, 1, 4);
			break;

		case 'f':
				
			printf("缩小");
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, ZOOM_OUT, 0, 4);
			Sleep(500);
			NET_DVR_PTZControlWithSpeed_Other(IUserID, 1, ZOOM_OUT, 1, 4);
			break;

		case 'x':
			printf("按键未定义!\n");
			break;
		default:

			break;
		}
	}



}


int main() {
	Init();//初始化sdk
	Connect();//设置连接事件与重连时间	
			  //打开串口
	if (OpenPort())
		std::cout << "Open port success" << std::endl;
	//设置波特率
	if (SetupDCB(9600))
		std::cout << "Set DCB success" << std::endl;
	//设置超时  
	if (SetupTimeout(0, 0, 0, 0, 0))
		std::cout << "Set timeout success" << std::endl;

	menu(); //红外遥控功能
	NET_DVR_Cleanup();//释放 SDK 资源
	return 0;
}

引用 https://www.cnblogs.com/happyamyhope/p/6594117.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值