Java-大華視頻監控設備端SDK-win64對接集成


Java-大華視頻監控設備端SDK-win64對接集成

主要軟件版本及系統環境

注意:如果開發環境或者服務器是linux, 請注意是否有坑T T,建議查看doc內相關文檔內容

開發操作系統:Windows11-64位

服務器操作系統:Windows Server 2019

sdk版本:General_NetSDK_ChnEng_JAVA_Win64_IS_V3.055.0000000.0.R.210602

sdk下載地址:https://supportfile.dahuatech.com/partnerService%2F91fefa7805504c28b56e2c81c1cfde2d.zip?auth_key=1649222601-0-0-33bbdb17b57b201070ddc897d2bf9f12&filename=General_NetSDK_ChnEng_JAVA_Win64_IS_V3.055.0000000.0.R.210602.zip

安裝大華jar包到本地maven庫

# 因為maven官方倉庫沒有,所以需要自行手動安裝,maven請添加環境變量(不添加的話就去maven的bin下面執行),然后在控制台執行如下指令,Dfile的內容是INetSDK.jar在你自己本地計算機的位置
mvn install:install-file -Dfile=C:\Users\Administrator\Desktop\General_NetSDK_ChnEng_JAVA_Win64_IS_V3.055.0000000.0.R.211118\libs\INetSDK.jar -DgroupId=com.dahua.netsdk -DartifactId=dahua-netsdk-jni -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true

文件復制和配置修改

1.修改pom.xml

主要就是新增2個sdk 的依賴,其次是需要在build下的添加一個resource,需要將動態庫一起打包,不然服務運行的時候會找不到.dll文件

<!-- 大華攝像頭sdk start -->
<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>5.4.0</version>
</dependency>
<dependency>
    <groupId>com.dahua.netsdk</groupId>
    <artifactId>dahua-netsdk-jni</artifactId>
    <version>1.0.0</version>
</dependency>
<!-- 大華攝像頭sdk end -->

<build>
    <resources>
        <resource>
            <directory>libs</directory>
            <filtering>false</filtering>
            <includes>
                <include>**/*.dll</include>
            </includes>
        </resource>
    </resources>
</build>


2.復制netsdk文件夾內所有內容到項目的com下

源文件在下載文件中的src文件夾內,復制netsdk文件夾至com路徑下

src

​ -main

​ --java

​ ---com

​ ----netsdk

​ ----build(這是我本地的文件,和netsdk同級就行)

3.復制配置文件

源文件在下載文件中的res文件夾里

復制dynamic-lib-load.xml,res_en_US.properties,res_zh_CN.properties到resources下

src

​ -main

​ --resources

​ ---dynamic-lib-load.xml

​ ---res_en_US.properties

​ ---res_zh_CN.properties

4.修改netsdk項目部分文件

修改com/netsdk/common/Res.java文件內"res"-》"resources"

5.雲台控制工具類

注意:

①這個文件可以直接拿去用,在這個類的底部有一個main方法,可以直接調用進行測試。

②參數說明:

  • @param m_strIp 具體的視頻設備ip,具體可以咨詢廠商
  • @param m_nPort 設備的端口一般為37777,具體可以咨詢廠商
  • @param m_strUser 登錄名一般admin,具體可以咨詢廠商
  • @param m_strPassword 密碼一般admin123,具體可以咨詢廠商
  • @param nChannelID 通道id 默認為0,具體可以咨詢廠商
  • @param lParam1 默認 0,當有左上或左下等操作時才會傳值 (1-8)
  • @param lParam2 垂直/水平 移動速度 (1-8)

③@Slf4j注解是lombok里面的,如果沒有的話就注釋掉自己手動寫一個

private static final Logger log = LoggerFactory.getLogger(PTZControlUtil.class);

PTZControlUtil

package com.netsdk.utils;

import com.netsdk.demo.module.LoginModule;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.sun.jna.Pointer;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author lycj
 * @Description 雲台控制工具類
 * @Date 2022/3/30 14:43
 * @Version 1.0
 */
@Slf4j
public class PTZControlUtil
{
    // 初始化sdk
    public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;

    // 設備信息
    private static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();

    // 登陸句柄
    private static NetSDKLib.LLong m_hLoginHandle = new NetSDKLib.LLong(0);

    // 網絡斷線處理
    private static DisConnect disConnect = new DisConnect();

    // 設備連接恢復,實現設備連接恢復接口
    private static HaveReConnect haveReConnect = new HaveReConnect();


    /**
     * 雲台控制
     * 向上移動
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam1       默認 0,當有左上或左下等操作時才會傳值 (1-8)
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean upControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam1, int lParam2)
    {

        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始向上移動,若超過角度則會變為左右移動
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startUpControl(nChannelID, lParam1, lParam2);
        }
        log.info("操作完成");
        // 停止移動
        result = stopUpControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 向下移動
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam1       默認 0,當有左上或左下等操作時才會傳值 (1-8)
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean downControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam1, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始向下移動,若超過角度則會變為左右移動
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startDownControl(nChannelID, lParam1, lParam2);
        }
        log.info("操作完成");
        // 停止移動
        result = stopDownControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 向左移動
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam1       默認 0,當有左上或左下等操作時才會傳值 (1-8)
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean leftControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam1, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始向左移動,若超過角度則會變為左右移動
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startLeftControl(nChannelID, lParam1, lParam2);
        }
        log.info("操作完成");
        // 停止移動
        result = stopLeftControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();
        return result;

    }

    /**
     * 雲台控制
     * 向右移動
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam1       默認 0,當有左上或左下等操作時才會傳值 (1-8)
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean rightControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam1, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始向右移動,若超過角度則會變為左右移動
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startRightControl(nChannelID, lParam1, lParam2);
        }
        log.info("操作完成");
        // 停止移動
        result = stopRightControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 向左上移動
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam1       默認 0,當有左上或左下等操作時才會傳值 (1-8)
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean leftUpControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam1, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始向左上移動,若超過角度則會變為左右移動
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startLeftUpControl(nChannelID, lParam1, lParam2);
        }
        log.info("操作完成");
        // 停止移動
        result = stopLeftUpControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 向右上移動
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam1       默認 0,當有左上或左下等操作時才會傳值 (1-8)
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean rightUpControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam1, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始向右上移動,若超過角度則會變為左右移動
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startRightUpControl(nChannelID, lParam1, lParam2);
        }
        log.info("操作完成");
        // 停止移動
        result = stopRightUpControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 向左下移動
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam1       默認 0,當有左上或左下等操作時才會傳值 (1-8)
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean leftDownControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam1, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始向左下移動,若超過角度則會變為左右移動
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startLeftDownControl(nChannelID, lParam1, lParam2);
        }
        log.info("操作完成");
        // 停止移動
        result = stopLeftDownControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 向右下移動
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam1       默認 0,當有左上或左下等操作時才會傳值 (1-8)
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean rightDownControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam1, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始向右下移動,若超過角度則會變為左右移動
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startRightDownControl(nChannelID, lParam1, lParam2);
        }
        log.info("操作完成");
        // 停止移動
        result = stopRightDownControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 變倍+
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean zoomAddControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始變倍+
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startZoomAddControl(nChannelID, lParam2);
        }
        log.info("操作完成");
        // 停止變倍
        result = stopZoomAddControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 變倍-
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean zoomDecControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始變倍-
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startZoomDecControl(nChannelID, lParam2);
        }
        log.info("操作完成");
        // 停止變倍
        result = stopZoomDecControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 變焦+
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean focusAddControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始變焦+
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startFocusAddControl(nChannelID, lParam2);
        }
        log.info("操作完成");
        // 停止變焦
        result = stopFocusAddControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 變焦-
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean focusDecControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始變焦-
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startFocusDecControl(nChannelID, lParam2);
        }
        log.info("操作完成");
        // 停止變焦
        result = stopFocusDecControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 光圈+
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean irisAddControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始變焦+
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startIrisAddControl(nChannelID, lParam2);
        }
        log.info("操作完成");
        // 停止變焦
        result = stopIrisAddControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    /**
     * 雲台控制
     * 光圈-
     * @param m_strIp       ip
     * @param m_nPort       端口
     * @param m_strUser     登錄名
     * @param m_strPassword 密碼
     * @param nChannelID    通道id 默認為0
     * @param lParam2       垂直/水平 移動速度 (1-8)
     */
    public static boolean irisDecControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, int lParam2)
    {
        boolean result;

        // 初始化
        LoginModule.init(disConnect, haveReConnect);
        // 若未登錄,先登錄。
        if (m_hLoginHandle.longValue() == 0)
        {
            login(m_strIp, m_nPort, m_strUser, m_strPassword);
        }
        // 開始變焦-
        if (m_hLoginHandle.longValue() != 0)
        {
            result = startIrisDecControl(nChannelID, lParam2);
        }
        log.info("操作完成");
        // 停止變焦
        result = stopIrisDecControl(nChannelID);
        // 退出
        logout();
        log.info("退出登錄...");
        // 釋放資源
        LoginModule.cleanup();

        return result;
    }

    // 向上
    private static boolean startUpControl(int nChannelID, int lParam1, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_UP_CONTROL,
                    lParam1, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    private static boolean stopUpControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_UP_CONTROL,
                0, 0, 0, 1);
    }


    /**
     * 向下
     */
    public static boolean startDownControl(int nChannelID, int lParam1, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_DOWN_CONTROL,
                    lParam1, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    public static boolean stopDownControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_DOWN_CONTROL,
                0, 0, 0, 1);
    }

    /**
     * 向左
     */
    public static boolean startLeftControl(int nChannelID, int lParam1, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_LEFT_CONTROL,
                    lParam1, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    public static boolean stopLeftControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_LEFT_CONTROL,
                0, 0, 0, 1);
    }

    /**
     * 向右
     */
    public static boolean startRightControl(int nChannelID, int lParam1, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_RIGHT_CONTROL,
                    lParam1, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    public static boolean stopRightControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_RIGHT_CONTROL,
                0, 0, 0, 1);
    }

    /**
     * 向左上
     */
    public static boolean startLeftUpControl(int nChannelID, int lParam1, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTTOP,
                    lParam1, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    public static boolean stopLeftUpControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTTOP,
                0, 0, 0, 1);
    }

    /**
     * 向右上
     */
    public static boolean startRightUpControl(int nChannelID, int lParam1, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTTOP,
                    lParam1, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    public static boolean stopRightUpControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTTOP,
                0, 0, 0, 1);
    }

    /**
     * 向左下
     */
    public static boolean startLeftDownControl(int nChannelID, int lParam1, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTDOWN,
                    lParam1, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    public static boolean stopLeftDownControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTDOWN,
                0, 0, 0, 1);
    }

    /**
     * 向右下
     */
    public static boolean startRightDownControl(int nChannelID, int lParam1, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTDOWN,
                    lParam1, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    public static boolean stopRightDownControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTDOWN,
                0, 0, 0, 1);
    }

    /**
     * 變倍+
     */
    public static boolean startZoomAddControl(int nChannelID, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_ADD_CONTROL,
                    0, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }

    }

    public static boolean stopZoomAddControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_ADD_CONTROL,
                0, 0, 0, 1);
    }

    /**
     * 變倍-
     */
    public static boolean startZoomDecControl(int nChannelID, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_DEC_CONTROL,
                    0, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }

    }

    public static boolean stopZoomDecControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_DEC_CONTROL,
                0, 0, 0, 1);
    }

    /**
     * 變焦+
     */
    public static boolean startFocusAddControl(int nChannelID, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_ADD_CONTROL,
                    0, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }

    }

    public static boolean stopFocusAddControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_ADD_CONTROL,
                0, 0, 0, 1);
    }

    /**
     * 變焦-
     */
    public static boolean startFocusDecControl(int nChannelID, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_DEC_CONTROL,
                    0, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }

    }

    public static boolean stopFocusDecControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_DEC_CONTROL,
                0, 0, 0, 1);
    }

    /**
     * 光圈+
     */
    public static boolean startIrisAddControl(int nChannelID, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_ADD_CONTROL,
                    0, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }

    }

    public static boolean stopIrisAddControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_ADD_CONTROL,
                0, 0, 0, 1);
    }

    /**
     * 光圈-
     */
    public static boolean startIrisDecControl(int nChannelID, int lParam2)
    {
        if (m_hLoginHandle.longValue() != 0)
        {
            return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                    NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_DEC_CONTROL,
                    0, lParam2, 0, 0);
        } else
        {
            log.error("登錄句柄不存在!");
            return false;
        }
    }

    public static boolean stopIrisDecControl(int nChannelID)
    {
        return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
                NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_DEC_CONTROL,
                0, 0, 0, 1);
    }


    /**
     * 登錄
     * @param m_strIp       ip
     * @param m_nPort       端口號
     * @param m_strUser     賬號
     * @param m_strPassword 密碼
     * @return 成功則 true
     */
    public static boolean login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword)
    {
        //IntByReference nError = new IntByReference(0);
        //入參
        NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam = new NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY();
        pstInParam.nPort = m_nPort;
        pstInParam.szIP = m_strIp.getBytes();
        pstInParam.szPassword = m_strPassword.getBytes();
        pstInParam.szUserName = m_strUser.getBytes();
        //出參
        NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam = new NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY();
        pstOutParam.stuDeviceInfo = m_stDeviceInfo;
        m_hLoginHandle = netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam);
        log.info(netsdk.getClass().toString());
        if (m_hLoginHandle.longValue() == 0)
        {
            log.error("登錄失敗!\n", m_strIp, m_nPort, ToolKits.getErrorCodePrint());
        } else
        {
            log.info("登錄成功: [ " + m_strIp + " ]");
        }

        return m_hLoginHandle.longValue() == 0 ? false : true;
    }

    /**
     * 退出登錄
     */
    private static void logout()
    {
        if (m_hLoginHandle.longValue() == 0)
        {
            return;
        }

        boolean bRet = netsdk.CLIENT_Logout(m_hLoginHandle);
        if (bRet)
        {
            m_hLoginHandle.setValue(0);
        }

    }

    // 設備斷線回調: 通過 CLIENT_Init 設置該回調函數,當設備出現斷線時,SDK會調用該函數
    private static class DisConnect implements NetSDKLib.fDisConnect
    {
        public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser)
        {
            System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort);
        }
    }

    // 網絡連接恢復,設備重連成功回調
    // 通過 CLIENT_SetAutoReconnect 設置該回調函數,當已斷線的設備重連成功時,SDK會調用該函數
    private static class HaveReConnect implements NetSDKLib.fHaveReConnect
    {
        public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser)
        {
            System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort);
        }
    }
    
    public static void main(String[] args)
    {
        String m_strIp = "192.168.11.174";//    ip
        int m_nPort = 37777;//    端口
        String m_strUser = "admin";//   登錄名
        String m_strPassword = "admin123";// 密碼
        int nChannelID = 0;//   通道id 默認為0
        int lParam1 = 0;//       默認 0,當有左上或左下等操作時才會傳值 (1-8)
        int lParam2 = 5;//      垂直/水平 移動速度 (1-8)
        upControlPtz(m_strIp, m_nPort, m_strUser, m_strPassword, nChannelID, lParam1, lParam2);
    }

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM