Home >Java >javaTutorial >How to use Java Hikvision SDK for secondary development of custom functions

How to use Java Hikvision SDK for secondary development of custom functions

PHPz
PHPzOriginal
2023-09-06 09:28:421138browse

How to use Java Hikvision SDK for secondary development of custom functions

How to use Java Hikvision SDK for secondary development of custom functions

Introduction:
With the continuous advancement of technology, monitoring equipment has become more and more important in our lives. play an increasingly important role. As one of the leaders in domestic surveillance equipment, Hikvision’s SDK provides a powerful development platform, allowing developers to conduct secondary development according to their own needs. This article will introduce how to use Java Hikvision SDK for secondary development of custom functions, aiming to help developers better use Hikvision SDK for project development.

1. Introduction to Hikvision-Java-SDK
Hikvision-Java-SDK is a Java development toolkit provided by Hikvision to developers. It is mainly used to interact with and customize Hikvision devices. Functional development. Its core functions include real-time preview, video playback, PTZ control, device information acquisition, etc. By using Hikvision-Java-SDK, developers can easily communicate with Hikvision devices and implement customized functions.

2. Environment preparation

  1. JDK environment: Ensure that the Java development environment has been correctly installed and configured;
  2. Hikvision-Java-SDK: From Hikvision Download and install the latest version of Hikvision-Java-SDK from the official website (https://www.hikvision.com/);
  3. Development tools: It is recommended to use Java development tools such as IntelliJ IDEA.

3. Create a Java project and import the SDK

  1. Create a new Java project and open it with development tools;
  2. Place the downloaded Hikvision- Unzip the Java-SDK compressed package and copy the jar files to the lib folder of the project;
  3. Right-click the project in the development tool and select "Open Module Settings" to enter the project settings window;
  4. Select "Libraries" on the left side of the project settings window, then click the " " button in the upper right corner and select "Java";
  5. In the pop-up dialog box, select the lib folder and click "OK" to complete the import.

4. Sample Code
The following takes the real-time preview function of monitoring equipment as an example to demonstrate how to use Hikvision-Java-SDK to develop custom functions. Please follow the steps below:

  1. Create a new Java class named HikvisionUtils;
  2. Import the required packages in the SDK in the HikvisionUtils class, the example is as follows :

    import com.sun.jna.NativeLong;
    import com.sun.jna.Pointer;
    import com.sun.jna.ptr.IntByReference;
    import com.sun.jna.ptr.NativeLongByReference;
    import com.sun.jna.ptr.PointerByReference;
    import com.sun.jna.win32.StdCallLibrary;
    import com.sun.jna.win32.W32APIOptions;
  3. Define the function interface required in the SDK in the HikvisionUtils class. The example is as follows:

    public interface HCNetSDK extends StdCallLibrary {
     HCNetSDK INSTANCE = (HCNetSDK) Native.loadLibrary("HCNetSDK", HCNetSDK.class, new HashMap<String, Object>() {
         {put(OPTION_TYPE_MAPPER, W32APIOptions.UNICODE);}
     });
    
     boolean NET_DVR_Init();
     void NET_DVR_Cleanup();
     NativeLong NET_DVR_Login_V30(String sDVRIP, short wDVRPort, String sUserName, String sPassword, NET_DVR_DEVICEINFO_V30 lpDeviceInfo);
    }
  4. Implement real-time preview in the HikvisionUtils class Function, examples are as follows:

    public class HikvisionUtils {
     public static void main(String[] args) {
         // 初始化SDK
         HCNetSDK.INSTANCE.NET_DVR_Init();
    
         // 登录设备
         String ip = "192.168.1.100";
         int port = 8000;
         String username = "admin";
         String password = "123456";
         NET_DVR_DEVICEINFO_V30 deviceInfo = new NET_DVR_DEVICEINFO_V30();
         NativeLong userID = HCNetSDK.INSTANCE.NET_DVR_Login_V30(ip, (short) port, username, password, deviceInfo);
         if (userID.intValue() < 0) {
             System.out.println("登录失败");
         } else {
             System.out.println("登录成功");
    
             // 获取通道号
             int channelID = 1;
             
             // 创建预览参数
             NET_DVR_PREVIEWINFO previewInfo = new NET_DVR_PREVIEWINFO();
             previewInfo.lChannel = new NativeLong(channelID);
             previewInfo.dwStreamType = 0;  // 主码流
             previewInfo.dwLinkMode = 0x0000;  // TCP方式
             previewInfo.bBlocked = 1;  // 阻塞取流
    
             // 开始预览
             NativeLong playHandle = HCNetSDK.INSTANCE.NET_DVR_RealPlay_V30(userID, previewInfo, null, null, true);
             if (playHandle.intValue() < 0) {
                 System.out.println("预览失败");
             } else {
                 System.out.println("预览成功");
                 
                 // 此处可执行其他自定义功能的操作
                 
                 // 停止预览
                 HCNetSDK.INSTANCE.NET_DVR_StopRealPlay(playHandle);
             }
    
             // 注销登录
             HCNetSDK.INSTANCE.NET_DVR_Logout(userID);
         }
    
         // 释放SDK资源
         HCNetSDK.INSTANCE.NET_DVR_Cleanup();
     }
    }

5. Run the program
After completing the above steps, you can run the code in the HikvisionUtils class to realize the real-time preview function of the monitoring device. Before running the program, make sure that the device's IP address, port number, username, and password have been correctly configured.

6. Summary
Through the introduction of this article, we have learned how to use Java Hikvision SDK for secondary development of custom functions. Hikvision SDK provides rich functional interfaces and sample codes, and also supports secondary development for custom functions. I hope this article can help developers who are doing secondary development of Hikvision equipment. I also hope that everyone can have a deeper understanding of the development and application of monitoring equipment by reading this article.

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

Statement:
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