海康威视热成像实时测温java

使用JNA,二个主要类,根据使用手册C翻译形成

package anruesi;

import com.sun.jna.NativeLong;

/**
 * @author sunsj
 * @date 2020/9/25 15:32
 */
public class ThermInfo {
    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
    static NativeLong lUserID = new NativeLong(-1);;

    public static void main(String[] args) {
        boolean initStatus = hCNetSDK.NET_DVR_Init();
        if(initStatus){
            System.out.println("初始化成功");
        }else{
            System.out.println("初始化失败"+hCNetSDK.NET_DVR_GetCardLastError_Card());
        }

        hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
        hCNetSDK.NET_DVR_SetReconnect(10000, true);

        HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
        lUserID = hCNetSDK.NET_DVR_Login_V30("172.16.6.201",
                (short) 8000, "admin", "password", m_strDeviceInfo);

        if (lUserID.longValue() == -1){
            System.out.println("登录失败,错误码为"+hCNetSDK.NET_DVR_GetLastError());
            hCNetSDK.NET_DVR_Cleanup();
            return;
        }else{
            System.out.println("登录成功!");
        }


        HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND thermometry = new HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND();
        thermometry.dwSize = thermometry.size();// 结构体大小
        thermometry.byRuleID = 1;// 规则ID
        thermometry.dwChan = 2;// 通道号

        thermometry.write();

        /**
         * 热成像通道
         */
        NativeLong lHandle = hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, 3629, thermometry.getPointer(), thermometry.size(), new GetThermInfoCallback(), null);

        if (lHandle.intValue() < 0){
            System.out.println("NET_DVR_GET_REALTIME_THERMOMETRY failed, error code: "+ hCNetSDK.NET_DVR_GetLastError());
        }else{
            System.out.println("NET_DVR_GET_REALTIME_THERMOMETRY is successful!");
        }


        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        if(!hCNetSDK.NET_DVR_StopRemoteConfig(lHandle)){
            System.out.println("NET_DVR_StopRemoteConfig failed, error code:"+ hCNetSDK.NET_DVR_GetLastError());
        }

        boolean logoutStatus = hCNetSDK.NET_DVR_Logout(lUserID);
        if(logoutStatus){
            System.out.println("Logout success");
        }else{
            System.out.println("Logout fail");
        }
        hCNetSDK.NET_DVR_Cleanup();

    }
}

 

回调类

 

package anruesi;

import com.sun.jna.Pointer;

/**
 * @author sunsj
 * @date 2020/9/25 16:02
 */
public class GetThermInfoCallback implements HCNetSDK.FRemoteConfigCallback {
    @Override
    public void invoke(int dwType, Pointer pBuffer, int dwBufLen, Pointer pUserData) {

        System.out.println("return callback invoke");
        System.out.println("-----dwType:"+dwType+"---------dwBufLen:"+dwBufLen);


        switch (dwType){
            case 0: //NET_SDK_CALLBACK_TYPE_STATUS
                HCNetSDK.REMOTECONFIGSTATUS struCfgStatus  = new HCNetSDK.REMOTECONFIGSTATUS();
                struCfgStatus.write();
                Pointer pCfgStatus = struCfgStatus.getPointer();
                pCfgStatus.write(0, pBuffer.getByteArray(0, struCfgStatus.size()), 0,struCfgStatus.size());
                struCfgStatus.read();

                int iStatus = 0;
                for(int i=0;i<4;i++)
                {
                    int ioffset = i*8;
                    int iByte = struCfgStatus.byStatus[i]&0xff;
                    iStatus = iStatus + (iByte << ioffset);
                }

                switch (iStatus){
                    case 1000:// NET_SDK_CALLBACK_STATUS_SUCCESS
                        System.out.println("实时测温回调成功,dwStatus:" + iStatus);
                        break;
                    case 1001:
                        System.out.println("正在获取实时测温回调数据中,dwStatus:" + iStatus);
                        break;
                    case 1002:
                        int iErrorCode = 0;
                        for(int i=0;i<4;i++)
                        {
                            int ioffset = i*8;
                            int iByte = struCfgStatus.byErrorCode[i]&0xff;
                            iErrorCode = iErrorCode + (iByte << ioffset);
                        }
                        System.out.println("获取实时测温回调数据失败, dwStatus:" + iStatus + "错误号:" + iErrorCode);
                        break;
                }
                break;
            case 2: //NET_SDK_CALLBACK_TYPE_DATA
                HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD m_struThermometryInfo = new HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD();
                m_struThermometryInfo.write();
                Pointer pInfoV30 = m_struThermometryInfo.getPointer();
                pInfoV30.write(0, pBuffer.getByteArray(0, m_struThermometryInfo.size()), 0,m_struThermometryInfo.size());
                m_struThermometryInfo.read();

                if(m_struThermometryInfo.byRuleCalibType == 0){
                    System.out.println("点测温信息:"+ m_struThermometryInfo.struPointThermCfg.fTemperature);
                }
                if(m_struThermometryInfo.byRuleCalibType == 1 || m_struThermometryInfo.byRuleCalibType == 2){
                    System.out.println("框/线测温信息:fMaxTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fMaxTemperature);
                    System.out.println("   fMinTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fMinTemperature);
                    System.out.println("  fAverageTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fAverageTemperature);
                    System.out.println("   fTemperatureDiff__"+m_struThermometryInfo.struLinePolygonThermCfg.fTemperatureDiff);
                    System.out.println("    fCenterPointTemperature__"+m_struThermometryInfo.fCenterPointTemperature);
                }
                break;
            default:
                break;
        }

    }

}

 

开发经过,首次部署测试,错误码为8

NET_DVR_NETWORK_SEND_ERROR 8 向设备发送失败。

解决

http://www.hikvision.com/Cn/download_more_401.html,官网下载的SDK,lib包不对,替换掉

 

接着,错误码为18

NET_DVR_CHAN_EXCEPTION 18 设备通道处于错误状态

解决:替换掉HCNetSDK.java

 

 

可运行DEMO下载

 

 

 

你可能感兴趣的:(物联网,热成像实时测温)