在20年写了一篇实时测温demo博客,看来帮了不少人。今天刚好又有需求,需要采温。也碰到了不少问题,特此记录
摄像头:海康 型号:DS-2TD2528T-7/Q 序列:EA0406775
服务器:winServer
之前写的demo下载下来。
先把lib 放在D盘下,这边的lib仅限于win64的,如果是其他平台。
海康官网平台下载
后续把账号密码一改,直接发布试一下。
结果
排查故障
询问海康
配置开启功能
登录之后,配置
有些用户会发现,没有本地这一项,那么请看下图。下载插件,刷新即可。
等我配置好之后,重启之后还是code11。静下心来,自己研究程序。
应该是哪里传值不对。
海康的人让我下载Demo看下,其实就是他们的一个测试exe。间接了解海康测温原理,抓图分析。这个工具可以很明显是摄像头没有配置好,还是程序有问题。
这边可以看到,是程序自己没有配置好。
开始琢磨。byRuleID 规则ID是1,我不是很明白 ,dwChan通道ID 是2没有问题。
最后查看相关文档,规则ID 普通模式下只能是0。专家模式下如果只获取对应ID的温度就输入对应规则ID。看图
普通模式和专家模式是互斥的。
最后程序调整下。成功了
runnable
- /**
- * @author cmy
- * @date 2023/9/14 14:03
- */
- @Slf4j
- public class ReadDataThread implements Runnable {
-
- HCNetSDK hCNetSDK;
- ThermInfoCallback thermInfoCallback;
- DeviceBean bean;
-
- public ReadDataThread(HCNetSDK hCNetSDK, ThermInfoCallback thermInfoCallback, DeviceBean bean){
- this.hCNetSDK = hCNetSDK;
- this.thermInfoCallback = thermInfoCallback;
- this.bean = bean;
- }
-
- @Override
- public void run() {
- HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
-
- NativeLong lUserID = new NativeLong(-1);
- lUserID = hCNetSDK.NET_DVR_Login_V30(bean.getIp(),
- bean.getPort(), bean.getUserName(), bean.getPassWord(), m_strDeviceInfo);
-
- if (lUserID.longValue() == -1){
- log.error(bean.getIp()+"登录失败,错误码为"+hCNetSDK.NET_DVR_GetLastError());
- return;
- }else{
- log.info(bean.getIp()+"登录成功!"+lUserID);
- }
-
-
- HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND thermometry = new HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND();
- thermometry.dwSize = thermometry.size();
- thermometry.byRuleID = 0;
- thermometry.dwChan = 2;
- thermometry.write();
- Pointer pUserData = new Memory(37);
- //TODO 传数据
- pUserData.setString(0, bean.getIp());
- pUserData.setInt(13,222);
-
-
-
- while (true){
- NativeLong lHandle = hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, 3629, thermometry.getPointer(), thermometry.size(), thermInfoCallback, pUserData);
-
- if (lHandle.intValue() < 0){
- log.error(bean.getIp()+"NET_DVR_GET_REALTIME_THERMOMETRY failed, error code: "+ hCNetSDK.NET_DVR_GetLastError());
- break;
- }else{
- log.info(bean.getIp()+"NET_DVR_GET_REALTIME_THERMOMETRY is successful!");
- }
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
-
-
- // if(!hCNetSDK.NET_DVR_StopRemoteConfig(lHandle)){
- // log.error(bean.getIp()+"NET_DVR_StopRemoteConfig failed, error code:"+ hCNetSDK.NET_DVR_GetLastError());
- // }
- //
- // boolean logoutStatus = hCNetSDK.NET_DVR_Logout(lUserID);
- // if(logoutStatus){
- // log.info(bean.getIp()+"Logout success");
- // }else{
- // log.error(bean.getIp()+"Logout fail");
- // }
- }
- }
main
- static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
-
- @Override
- public void run() {
- boolean initStatus = hCNetSDK.NET_DVR_Init();
- if(initStatus){
- log.info("初始化成功");
- }else{
- log.error("初始化失败"+hCNetSDK.NET_DVR_GetCardLastError_Card());
- }
- hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
- hCNetSDK.NET_DVR_SetReconnect(10000, true);
- hCNetSDK.NET_DVR_SetLogToFile(3,"D:\\log",false);
-
-
- List
deviceList = new ArrayList<>(3); - deviceList.add(new DeviceBean("192.168.1.70",(short) 8000,"admin","a12345678"));
- deviceList.add(new DeviceBean("192.168.1.81",(short) 8000,"admin","a12345678"));
- deviceList.add(new DeviceBean("192.168.1.91",(short) 8000,"admin","a12345678"));
-
-
-
-
- for(DeviceBean bean : deviceList){
- new Thread(new ReadDataThread(hCNetSDK, new ThermInfoCallback(), bean)).start();
- }
-
-
- }
callback
- @Slf4j
- public class ThermInfoCallback implements HCNetSDK.FRemoteConfigCallback {
- @Override
- public void invoke(int dwType, Pointer pBuffer, int dwBufLen, Pointer pUserData) {
-
- log.info("dwType:"+dwType+"dwBufLen:"+dwBufLen+"pUserData:"+pUserData.getString(0));
-
- switch (dwType){
- case 0:
- 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:
- log.error("实时测温回调成功,dwStatus:" + iStatus);
- break;
- case 1001:
- log.error("正在获取实时测温回调数据中,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);
- }
- log.error(pUserData.getString(0)+"获取实时测温回调数据失败, dwStatus:" + iStatus + "错误号:" + iErrorCode);
- break;
- default:
- break;
- }
- break;
- case 2:
- 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){
- log.info("框/线测温信息:fMaxTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fMaxTemperature);
- log.info(" fMinTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fMinTemperature);
- log.info(" fAverageTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fAverageTemperature);
- log.info(" fTemperatureDiff__"+m_struThermometryInfo.struLinePolygonThermCfg.fTemperatureDiff);
- log.info(" fCenterPointTemperature__"+m_struThermometryInfo.fCenterPointTemperature);
- }
- break;
- default:
- break;
- }
-
- }
- }
在此说明一下pUserData传值到callback,看此博客Pointer传值