📄 ptzcommand.c
字号:
/*
* This sample code is written by block mode. If you want to use nonblock mode,
* please reference the HttpOperation_NonBlock sample.
*
*/
#include "Utility.h"
#define PTZCOMMAND_NUMBER 16
int main(int argc, char* argv[])
{
SCODE scRet = S_OK;
HANDLE hServerMgr = NULL;
HANDLE hDevice = NULL;
TCHAR szModelName[MAX_PATH] = {0};
TSERVER_INFO tServerInfo;
// PTZCommand parameters
char szInputBuf[MAX_PATH] = {0};
char szExtCommandBuf[64] = {0};
DWORD dwCamNumber = 1; // Index of camera to control, starting from 1.
int iCommandNum = 0;
ESRVCTRL_PTZ_COMMAND aePtzCommand[PTZCOMMAND_NUMBER] = {eSrvCtrlPTZMoveUp, eSrvCtrlPTZMoveDown, eSrvCtrlPTZMoveLeft, eSrvCtrlPTZMoveRight, eSrvCtrlPTZMoveHome,
eSrvCtrlPTZZoomIn, eSrvCtrlPTZZoomOut, eSrvCtrlPTZFocusNear, eSrvCtrlPTZFocusFar, eSrvCtrlPTZFocusAuto,
eSrvCtrlPTZStartPan, eSrvCtrlPTZStartPatrol, eSrvCtrlPTZStopPan, eSrvCtrlPTZIrisOpen, eSrvCtrlPTZIrisClose, eSrvCtrlPTZIrisAuto};
// example input: -I192.168.0.1 -H80 -Uroot -Proot -T30000
if (ParseInputArgument(argc, argv, &tServerInfo, eSrvMgrPTZCommand) != S_OK)
{
return 0;
}
// 1. Initialization
scRet = ServerManagerInitBlock(&hServerMgr, &hDevice, szModelName, tServerInfo);
if (S_OK != scRet)
{
printf("ServerManagerInitBlock failed...\n");
return 0;
}
// 2. Send the PTZ commands
while (1)
{
printf("To end this program, please press Enter directly.\n\n");
printf("Please input the PTZ command.\n");
printf("(1) Up, (2) Down, (3) Left, (4) Right, (5) Home, (6) Zoom in, (7) Zoom out\n");
printf("(8) Focus Near, (9) Focus Far, (10) Focus Auto, (11) Auto Pan, (12) Auto Partol\n");
printf("(13) Stop Pan, (14) Iris Open, (15) Iris Close, (16) Iris Auto:\n");
// check the input command
if (fgets(szInputBuf, MAX_PATH, stdin) == NULL)
{
break;
}
if (strlen(szInputBuf) > 0 && szInputBuf[strlen(szInputBuf) - 1] == '\n')
{
szInputBuf[strlen(szInputBuf) - 1] = 0;
}
if (szInputBuf[0] == 0)
{
break;
}
// mapping the PTZ command
iCommandNum = atoi(szInputBuf);
if (iCommandNum < 1 || iCommandNum > PTZCOMMAND_NUMBER)
{
printf("Input value incorrect or out of range!\n\n");
continue;
}
scRet = ServerManager_SendPTZCommandBlock(hDevice, dwCamNumber, aePtzCommand[iCommandNum-1], szExtCommandBuf, FALSE);
if (S_OK != scRet)
{
printf("Send PTZCommand failed: %X\n", scRet);
}
}
// 3. Release all resource
ServerManagerRelease(&hServerMgr, &hDevice);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -