Home > Java > Java Tutorial > body text

How to carry out secondary development of Java Hikvision SDK?

WBOY
Release: 2023-09-06 10:00:32
Original
1568 people have browsed it

How to carry out secondary development of Java Hikvision SDK?

How to carry out secondary development of Java Hikvision SDK?

Abstract:
With the continuous development of intelligent security technology, Hikvision’s SDK has become the first choice for many developers. This article will introduce how to carry out secondary development of Java Hikvision SDK and provide code examples to help developers get started quickly.

1. Preparation work
Before starting secondary development, the following preparation work needs to be done:

1. Download and install Hikvision SDK
First, you need to download and install Hikvision SDK from Hikvision Download and install Hikvision SDK from the official website. The installation process is relatively simple, just follow the prompts.

2. Create a Java project
Before integrating Hikvision SDK, you need to create a Java project first. You can use integrated development environments such as Eclipse, IntelliJ IDEA, or use the command line to create. Here we take Eclipse as an example to create a Java project in Eclipse.

2. Import SDK dependency packages
To integrate Hikvision SDK in a Java project, you need to import the SDK dependency packages. The specific steps are as follows:

1. Open Eclipse and copy the SDK dependency package to the lib directory of the project.

2. Right-click the project in Eclipse and select Properties -> Java Build Path.

3. Under the Libraries tab, click the Add JARs button and select the SDK dependency package just copied to the lib directory.

4. Click the Apply and Close button to complete the import of SDK dependency packages.

3. Write code
After the preparation work is completed, you can write code for secondary development. Below is a simple example for connecting to Hikvision devices and obtaining device information.

import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.hikvision.netsdk.*;

public class HKSDKDemo {
    private static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

    public static void main(String[] args) {
        // 初始化SDK
        hCNetSDK.NET_DVR_Init();

        // 登录设备
        NativeLong lUserID;
        HCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
        lUserID = hCNetSDK.NET_DVR_Login_V30("10.0.0.1", 8000, "admin", "password", deviceInfo);

        if (lUserID.longValue() == -1) {
            System.out.println("登录失败:" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }

        // 获取设备信息
        PointerByReference pDeviceCfg = new PointerByReference();
        IntByReference pcbSize = new IntByReference(deviceInfo.size());
        if (!hCNetSDK.NET_DVR_GetDVRConfig(lUserID, HCNetSDK.NET_DVR_GET_DEVICECFG_V40, new NativeLong(0),
                pDeviceCfg.getPointer(), deviceInfo.size(), pcbSize)) {
            System.out.println("获取设备信息失败:" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }

        HCNetSDK.NET_DVR_DEVICECFG_V40 deviceCfg = new HCNetSDK.NET_DVR_DEVICECFG_V40(pDeviceCfg.getValue());
        System.out.println("设备名称:" + new String(deviceCfg.byDevName));

        // 释放资源
        hCNetSDK.NET_DVR_Logout(lUserID);
        hCNetSDK.NET_DVR_Cleanup();
    }
}
Copy after login

Code explanation:
1. First, initialize the SDK through hCNetSDK.NET_DVR_Init().
2. Then, call hCNetSDK.NET_DVR_Login_V30() to log in to the device and return the login ID.
3. Next, obtain device information through hCNetSDK.NET_DVR_GetDVRConfig().
4. Finally, log out and release SDK resources through hCNetSDK.NET_DVR_Logout().

4. Run the code
After writing the code, you can click the Run button of Eclipse to run the code. If everything is OK, the console will display the name of the device.

Summary:
This article introduces how to carry out secondary development of Java Hikvision SDK. By importing SDK dependency packages and writing code, you can connect to Hikvision devices and obtain device information. Developers can further expand and optimize the code to achieve more functions according to their own needs. I hope this article will be helpful to developers who are conducting secondary development of Hikvision SDK.

The above is the detailed content of How to carry out secondary development of Java Hikvision SDK?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!