Hikvision Java SDK in action

Hikvision SDK in action

1. Obtain the Hikvision SDK from the official website
2. Open IDEA, create a new project and import the SDK
insert image description here
Add Jna.jar and examples.jar in project Structure-> modules
insert image description here
Add Jna.jar and examples.jar in project Structure-> sdks
insert image description here

3. Modify HCNetSDK.java
to modify the loading path of HCNetSDK.dll

  HCNetSDK INSTANCE = (HCNetSDK) Native.loadLibrary(System.getProperty("user.dir") +"/HCNetSDK.dll",
            HCNetSDK.class);

Modify the PlayCtrl.dll loading path


    PlayCtrl INSTANCE = (PlayCtrl) Native.loadLibrary(System.getProperty("user.dir") +"/PlayCtrl.dll",
            PlayCtrl.class);

4. Run the program
Enter the IP, user name, password, port, click to register
insert image description here
and preview successfully
insert image description here
Playback function, the channel number is i+33
insert image description here
5. SDK program function call sequence
insert image description here
6. SDK actual combat - manual recording function
Create a scheduled task
task

    @Scheduled(fixedRate = 60000)//每小时执行一次    
        @Async
        public void startVideoTask() {
    
    
            try {
    
    
                HKUtil.startVideo(v.username,v.password,v.ip);
            }catch (Exception e){
    
    
                e.printStackTrace();
            }
        }

HKUtil.java

   public static void startVideo(String username,String password,String ip) {
    
    
//匿名内部类实现方式
        new Thread() {
    
    
            //重写run方法
            @Override
            public void run() {
    
    
                boolean initSuc = hCNetSDK.NET_DVR_Init();
                HKUtil a = new HKUtil();
                a.init(username,password,ip);
            }
        }.start();
    }
 /*************************************************
     函数:      "注册"  按钮单击响应函数
     函数描述:	注册登录设备
     *************************************************/
    public void init(String username,String password,String ip) {
    
    //GEN-FIRST:event_jButtonLoginActionPerformed
        //注册之前先注销已注册的用户,预览情况下不可注销
        if (bRealPlay) {
    
    
            System.out.println("注册新用户请先停止当前预览!");
            return;
        }

        if (lUserID.longValue() > -1) {
    
    
            //先注销
            hCNetSDK.NET_DVR_Logout_V30(lUserID);
            lUserID = new NativeLong(-1);
            m_iTreeNodeNum = 0;
            m_DeviceRoot.removeAllChildren();
        }
        //注册

        m_sDeviceIP = ip;//设备ip地址
        m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
        int iPort = 8000;
        lUserID = hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP,
                (short) iPort, username, password, m_strDeviceInfo);

        long userID = lUserID.longValue();
        if (userID == -1) {
    
    
            m_sDeviceIP = "";//登录未成功,IP置为空
            System.out.println("注册失败");
        } else {
    
    
            try {
    
    
                hCNetSDK.NET_DVR_StartDVRRecord(lUserID, new NativeLong(0xffff), new NativeLong());
                Thread.sleep(30000);
                hCNetSDK.NET_DVR_StopDVRRecord(lUserID, new NativeLong(0xffff));
                jButtonExitActionPerformed();
            } catch (Exception e) {
    
    
                e.printStackTrace();

            }
        }
    }

The process is roughly as follows:
Logout-"Build Login Parameters-"Login Registration-"Start Recording-"Sleep-"Stop Recording
Corresponding method:

 hCNetSDK.NET_DVR_Logout_V30(lUserID);//注销登录
 
 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();//构建登录参数
  
 hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP,(short) iPort, username,      password, m_strDeviceInfo);//登录注册
 
 hCNetSDK.NET_DVR_StartDVRRecord(lUserID, new NativeLong(0xffff), new NativeLong());//开始录制
 
 Thread.sleep(30000);//睡眠
 
 hCNetSDK.NET_DVR_StopDVRRecord(lUserID, new NativeLong(0xffff));//停止录制
             

The result is shown in the figure
insert image description here

Guess you like

Origin blog.csdn.net/m0_38110240/article/details/120720934