当前位置:   article > 正文

Java根据SDK二次开发海康人脸设备DS-K1T673M_ds-k1t对接代码

ds-k1t对接代码

前言: 咨询过很多次海康的官方客服,看了操作手册,然后再分析了集成的SDK文档,总结了以下的代码以及结论。

功能:我实现的二维码核验的功能

步骤:

1.设备初始化

2.加载日志

3.设备进行登录

4.配置门禁参数开启远程核验功能和相关参数

5.事件查询

6.设备通道布防,设备回调函数,事件监听报警

7.根据业务远程控门

具体业务需要具体实现,我的思路以及代码仅供参考

上代码:

文件先放进项目中

还要将两个类放入项目中,这个SDK里面有我就不提供了,需要的话私信我

导入依赖:

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-web</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.projectlombok</groupId>
  12. <artifactId>lombok</artifactId>
  13. <version>1.18.26</version>
  14. </dependency>
  15. <dependency>
  16. <groupId>io.minio</groupId>
  17. <artifactId>examples</artifactId>
  18. <version>0.2.3</version>
  19. </dependency>
  20. <dependency>
  21. <groupId>com.sun.jna</groupId>
  22. <artifactId>jna</artifactId>
  23. <version>3.0.9</version>
  24. </dependency>
  25. <dependency>
  26. <groupId>net.java.dev.jna</groupId>
  27. <artifactId>jna</artifactId>
  28. <version>5.13.0</version>
  29. </dependency>
  30. <!--工具类依赖-->
  31. <dependency>
  32. <groupId>org.apache.commons</groupId>
  33. <artifactId>commons-lang3</artifactId>
  34. <version>3.8.1</version>
  35. </dependency>
  36. <dependency>
  37. <groupId>org.springframework</groupId>
  38. <artifactId>spring-core</artifactId>
  39. <version>6.1.1</version>
  40. </dependency>
  41. <dependency>
  42. <groupId>cn.hutool</groupId>
  43. <artifactId>hutool-all</artifactId>
  44. <version>5.8.18</version>
  45. </dependency>
  46. </dependencies>
  47. <build>
  48. <plugins>
  49. <plugin>
  50. <groupId>org.apache.maven.plugins</groupId>
  51. <artifactId>maven-compiler-plugin</artifactId>
  52. <version>3.1</version>
  53. <configuration>
  54. <source>1.8</source>
  55. <target>1.8</target>
  56. <encoding>UTF-8</encoding>
  57. <compilerArguments>
  58. <extdirs>${project.basedir}/src/main/resources/lib</extdirs>
  59. </compilerArguments>
  60. </configuration>
  61. </plugin>
  62. </plugins>
  63. </build>

初始化登录代码:

  1. package com.ruoyi.verify.config;
  2. import com.ruoyi.verify.Commom.osSelect;
  3. import com.ruoyi.verify.SDKDome.HCNetSDK;
  4. import com.sun.jna.Native;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.context.annotation.Configuration;
  7. /**
  8. * 设备初始化
  9. */
  10. @Configuration
  11. @Slf4j
  12. public class InitConfig{
  13. public static HCNetSDK hCNetSDK = null;
  14. //用户句柄
  15. public static int lUserID = -1;
  16. //设备字符集
  17. public static int iCharEncodeType = 0;
  18. /**
  19. * 根据不同操作系统选择不同的库文件和库路径
  20. *
  21. * @return
  22. */
  23. private static boolean createSDKInstance() {
  24. if (hCNetSDK == null) {
  25. synchronized (HCNetSDK.class) {
  26. String strDllPath = "";
  27. try {
  28. //System.setProperty("jna.debug_load", "true");
  29. if (osSelect.isWindows()) {
  30. //win系统加载库路径
  31. strDllPath = System.getProperty("user.dir") + "\\lib\\HCNetSDK.dll";
  32. } else if (osSelect.isLinux()) {
  33. //Linux系统加载库路径
  34. strDllPath = System.getProperty("user.dir") + "/lib/libhcnetsdk.so";
  35. }
  36. hCNetSDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class);
  37. } catch (Exception ex) {
  38. log.info("loadLibrary: " + strDllPath + " Error: " + ex.getMessage());
  39. return false;
  40. }
  41. }
  42. }
  43. return true;
  44. }
  45. public static int creatUserId() throws Exception {
  46. //开始设备初始化操作
  47. if (hCNetSDK == null) {
  48. if (!createSDKInstance()) {
  49. log.info("Load SDK fail");
  50. return -1;
  51. }
  52. }
  53. //linux系统建议调用以下接口加载组件库
  54. if (osSelect.isLinux()) {
  55. HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
  56. HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
  57. //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
  58. String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1";
  59. String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1";
  60. System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
  61. ptrByteArray1.write();
  62. hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());
  63. System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
  64. ptrByteArray2.write();
  65. hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());
  66. String strPathCom = System.getProperty("user.dir") + "/lib/";
  67. HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
  68. System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
  69. struComPath.write();
  70. hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
  71. }
  72. /**初始化*/
  73. hCNetSDK.NET_DVR_Init();
  74. /**加载日志*/
  75. boolean i = hCNetSDK.NET_DVR_SetLogToFile(3, "./sdklog", false);
  76. /**登录*/
  77. int lUserID = login_V40("设备IP", "admin", "设备登录密码", (short) 8000);
  78. return lUserID;
  79. }
  80. /**
  81. * 设备登录
  82. *
  83. * @param ipadress IP地址
  84. * @param user 用户名
  85. * @param psw 密码
  86. * @param port 端口,默认8000
  87. */
  88. public static int login_V40(String ipadress, String user, String psw, short port) {
  89. //注册
  90. //设备登录信息
  91. HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();
  92. //设备ip地址
  93. String m_sDeviceIP = ipadress;
  94. m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
  95. System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
  96. //设备用户名
  97. String m_sUsername = user;
  98. m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
  99. System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
  100. //设备密码
  101. String m_sPassword = psw;
  102. m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
  103. System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
  104. //sdk端口
  105. m_strLoginInfo.wPort = port;
  106. //是否异步登录:0- 否,1- 是
  107. m_strLoginInfo.bUseAsynLogin = false;
  108. m_strLoginInfo.write();
  109. //设备信息
  110. HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();
  111. lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
  112. if (lUserID == -1) {
  113. log.info("登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
  114. return -1;
  115. } else {
  116. log.info("登录成功!");
  117. m_strDeviceInfo.read();
  118. iCharEncodeType = m_strDeviceInfo.byCharEncodeType;
  119. return lUserID;
  120. }
  121. }
  122. }

配置门禁参数类

  1. package com.ruoyi.verify.config;
  2. import com.ruoyi.verify.SDKDome.HCNetSDK;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.context.annotation.Configuration;
  5. /**
  6. * 获取门禁参数配置类
  7. */
  8. @Slf4j
  9. @Configuration
  10. public class DoorParam{
  11. /**
  12. * 配置门禁参数
  13. *
  14. * @param lUserID
  15. * @param szUrl 固定:"PUT /ISAPI/AccessControl/AcsCfg?format=json\r\n"
  16. * @return
  17. */
  18. public static String doorParam(int lUserID, String szUrl) {
  19. HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
  20. struXMLInput.read();
  21. HCNetSDK.BYTE_ARRAY stringRequest = new HCNetSDK.BYTE_ARRAY(1024);
  22. stringRequest.read();
  23. //输入ISAPI协议命令
  24. System.arraycopy(szUrl.getBytes(), 0, stringRequest.byValue, 0, szUrl.length());
  25. stringRequest.write();
  26. // 输入JSON数据
  27. String pBuf = "{\"AcsCfg\":{\"uploadCapPic\": true,\"remoteCheckDoorEnabled\": false,\"checkChannelType\": \"PrivateSDK\",\"channelIp\" : \"通道IP\"}}";
  28. HCNetSDK.BYTE_ARRAY lpBuf = new HCNetSDK.BYTE_ARRAY(1024);
  29. lpBuf.read();
  30. System.arraycopy(pBuf.getBytes(), 0, lpBuf.byValue, 0, pBuf.length());
  31. lpBuf.write();
  32. struXMLInput.dwSize = struXMLInput.size();
  33. struXMLInput.lpRequestUrl = stringRequest.getPointer();
  34. struXMLInput.dwRequestUrlLen = szUrl.length();
  35. struXMLInput.lpInBuffer = lpBuf.getPointer();
  36. struXMLInput.dwInBufferSize = lpBuf.byValue.length;
  37. struXMLInput.write();
  38. HCNetSDK.BYTE_ARRAY stringXMLOut = new HCNetSDK.BYTE_ARRAY(8 * 1024);
  39. stringXMLOut.read();
  40. HCNetSDK.BYTE_ARRAY struXMLStatus = new HCNetSDK.BYTE_ARRAY(1024);
  41. struXMLStatus.read();
  42. HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
  43. struXMLOutput.read();
  44. struXMLOutput.dwSize = struXMLOutput.size();
  45. struXMLOutput.lpOutBuffer = stringXMLOut.getPointer();
  46. struXMLOutput.dwOutBufferSize = stringXMLOut.size();
  47. struXMLOutput.lpStatusBuffer = struXMLStatus.getPointer();
  48. struXMLOutput.dwStatusSize = struXMLStatus.size();
  49. struXMLOutput.write();
  50. //配置门禁参数
  51. if (!InitConfig.hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput)) {
  52. int iErr = InitConfig.hCNetSDK.NET_DVR_GetLastError();
  53. System.err.println("NET_DVR_STDXMLConfig失败,错误号" + iErr + "----URL:" + szUrl);
  54. return null;
  55. } else {
  56. stringXMLOut.read();
  57. log.info("输出文本大小:" + struXMLOutput.dwReturnedXMLSize);
  58. //打印输出XML文本
  59. String strOutXML = new String(stringXMLOut.byValue).trim();
  60. log.info(strOutXML);
  61. struXMLStatus.read();
  62. String strStatus = new String(struXMLStatus.byValue).trim();
  63. log.info(strStatus);
  64. }
  65. //获取门禁参数
  66. szUrl = "GET /ISAPI/AccessControl/AcsCfg?format=json\r\n";
  67. HCNetSDK.BYTE_ARRAY stringResponse = new HCNetSDK.BYTE_ARRAY(1024);
  68. stringResponse.read();
  69. //输入ISAPI协议命令
  70. System.arraycopy(szUrl.getBytes(), 0, stringResponse.byValue, 0, szUrl.length());
  71. stringResponse.write();
  72. struXMLInput.lpRequestUrl = stringResponse.getPointer();
  73. struXMLInput.dwRequestUrlLen = szUrl.length();
  74. //获取时输入为空
  75. struXMLInput.lpInBuffer = null;
  76. struXMLInput.dwInBufferSize = 0;
  77. //分配输出内存
  78. HCNetSDK.BYTE_ARRAY szGetOutput = new HCNetSDK.BYTE_ARRAY(1024 * 8);
  79. struXMLOutput.lpOutBuffer = szGetOutput.getPointer();
  80. struXMLOutput.dwOutBufferSize = szGetOutput.size();
  81. if (!InitConfig.hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput)) {
  82. log.info("GET /ISAPI/AccessControl/AcsCfg?format=json failed, error code: " + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  83. return "GET /ISAPI/AccessControl/AcsCfg?format=json failed, error code: " + InitConfig.hCNetSDK.NET_DVR_GetLastError();
  84. } else {
  85. log.info("GET /ISAPI/AccessControl/AcsCfg?format=json successfully!");
  86. System.out.println(szGetOutput);
  87. }
  88. return szGetOutput.toString();
  89. }
  90. }

查询所有事件

  1. package com.ruoyi.verify.config;
  2. import com.ruoyi.verify.SDKDome.HCNetSDK;
  3. import com.sun.jna.Pointer;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.context.annotation.Configuration;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.UnsupportedEncodingException;
  10. import java.nio.ByteBuffer;
  11. @Slf4j
  12. @Configuration
  13. public class SelectEvent{
  14. /**
  15. * 根据UserID查询事件,查询的是所有事件
  16. * @param lUserID
  17. * @throws UnsupportedEncodingException
  18. * @throws InterruptedException
  19. */
  20. public static void searchAllEvent(int lUserID) throws UnsupportedEncodingException, InterruptedException {
  21. //事件条数
  22. int i = 0;
  23. HCNetSDK.NET_DVR_ACS_EVENT_COND struAcsEventCond = new HCNetSDK.NET_DVR_ACS_EVENT_COND();
  24. struAcsEventCond.read();
  25. struAcsEventCond.dwSize = struAcsEventCond.size();
  26. //查询全部主次类型的报警
  27. // 主次事件类型设为0,代表查询所有事件
  28. struAcsEventCond.dwMajor = 0;
  29. struAcsEventCond.dwMinor = 0;
  30. //开始时间
  31. struAcsEventCond.struStartTime.dwYear = 2022;
  32. struAcsEventCond.struStartTime.dwMonth = 4;
  33. struAcsEventCond.struStartTime.dwDay = 27;
  34. struAcsEventCond.struStartTime.dwHour = 9;
  35. struAcsEventCond.struStartTime.dwMinute = 0;
  36. struAcsEventCond.struStartTime.dwSecond = 0;
  37. //结束时间
  38. struAcsEventCond.struEndTime.dwYear = 2025;
  39. struAcsEventCond.struEndTime.dwMonth = 4;
  40. struAcsEventCond.struEndTime.dwDay = 30;
  41. struAcsEventCond.struEndTime.dwHour = 16;
  42. struAcsEventCond.struEndTime.dwMinute = 0;
  43. struAcsEventCond.struEndTime.dwSecond = 0;
  44. struAcsEventCond.wInductiveEventType = 1;
  45. struAcsEventCond.byPicEnable = 1; //是否带图片,0-不带图片,1-带图片
  46. struAcsEventCond.write();
  47. Pointer ptrStruEventCond = struAcsEventCond.getPointer();
  48. int m_lSearchEventHandle = InitConfig.hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, HCNetSDK.NET_DVR_GET_ACS_EVENT, ptrStruEventCond, struAcsEventCond.size(), null, null);
  49. if (m_lSearchEventHandle<=-1)
  50. {
  51. log.info("NET_DVR_StartRemoteConfig调用失败,错误码:" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  52. }
  53. HCNetSDK.NET_DVR_ACS_EVENT_CFG struAcsEventCfg = new HCNetSDK.NET_DVR_ACS_EVENT_CFG();
  54. struAcsEventCfg.read();
  55. struAcsEventCfg.dwSize = struAcsEventCfg.size();
  56. struAcsEventCfg.write();
  57. Pointer ptrStruEventCfg = struAcsEventCfg.getPointer();
  58. while (true) {
  59. log.info("i=" + i);
  60. int dwEventSearch = InitConfig.hCNetSDK.NET_DVR_GetNextRemoteConfig(m_lSearchEventHandle, ptrStruEventCfg, struAcsEventCfg.size());
  61. if (dwEventSearch <= -1) {
  62. log.info("NET_DVR_GetNextRemoteConfig接口调用失败,错误码:" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  63. }
  64. if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT) {
  65. log.info("配置等待....");
  66. Thread.sleep(10);
  67. continue;
  68. } else if (dwEventSearch == HCNetSDK.NET_SDK_NEXT_STATUS__FINISH) {
  69. log.info("获取事件完成");
  70. break;
  71. } else if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED) {
  72. log.info("获取事件出现异常");
  73. break;
  74. } else if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS) {
  75. struAcsEventCfg.read();
  76. //获取的事件信息通过struAcsEventCfg结构体进行解析,
  77. log.info(i + "获取事件成功, 报警主类型:" + Integer.toHexString(struAcsEventCfg.dwMajor) + "报警次类型:" + Integer.toHexString(struAcsEventCfg.dwMinor) + "卡号:" + new String(struAcsEventCfg.struAcsEventInfo.byCardNo).trim());
  78. /**
  79. * 工号有两个字段,dwEmployeeNo表示工号,当值为0时,表示无效,解析byEmployeeNo参数
  80. */
  81. log.info("工号1:"+struAcsEventCfg.struAcsEventInfo.dwEmployeeNo);
  82. log.info("工号2:"+new String(struAcsEventCfg.struAcsEventInfo.byEmployeeNo));
  83. //人脸温度数据,需要设备和支持测温功能
  84. log.info("人脸温度:" + struAcsEventCfg.struAcsEventInfo.fCurrTemperature + "是否异常:" + struAcsEventCfg.struAcsEventInfo.byIsAbnomalTemperature);
  85. //口罩功能,需要设备支持此功能 0-保留,1-未知,2-不戴口罩,3-戴口罩
  86. log.info("是否带口罩:"+struAcsEventCfg.struAcsEventInfo.byMask);
  87. //人脸图片保存
  88. if (struAcsEventCfg.dwPicDataLen>0 || struAcsEventCfg.pPicData != null )
  89. {
  90. FileOutputStream fout;
  91. try {
  92. /**
  93. * 人脸图片保存路径
  94. */
  95. String filename = "..\\pic\\"+i+"_event.jpg";
  96. fout = new FileOutputStream(filename);
  97. //将字节写入文件
  98. long offset = 0;
  99. ByteBuffer buffers = struAcsEventCfg.pPicData.getByteBuffer(offset, struAcsEventCfg.dwPicDataLen);
  100. byte[] bytes = new byte[struAcsEventCfg.dwPicDataLen];
  101. buffers.rewind();
  102. buffers.get(bytes);
  103. fout.write(bytes);
  104. fout.close();
  105. } catch (FileNotFoundException e) {
  106. // TODO Auto-generated catch block
  107. e.printStackTrace();
  108. } catch (IOException e) {
  109. // TODO Auto-generated catch block
  110. e.printStackTrace();
  111. }
  112. }
  113. i++;
  114. continue;
  115. }
  116. }
  117. i = 0;
  118. if (!InitConfig.hCNetSDK.NET_DVR_StopRemoteConfig(m_lSearchEventHandle)) {
  119. log.info("NET_DVR_StopRemoteConfig接口调用失败,错误码:" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  120. } else {
  121. log.info("NET_DVR_StopRemoteConfig接口成功");
  122. }
  123. return ;
  124. }
  125. }

通道布防,设置回调函数,实时获取事件

  1. package com.ruoyi.verify.config;
  2. import com.ruoyi.verify.SDKDome.HCNetSDK;
  3. import com.sun.jna.NativeLong;
  4. import com.sun.jna.Pointer;
  5. import com.sun.jna.ptr.IntByReference;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.context.annotation.Configuration;
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.io.FileOutputStream;
  11. import java.io.IOException;
  12. import java.nio.ByteBuffer;
  13. import java.nio.charset.StandardCharsets;
  14. import java.text.DateFormat;
  15. import java.text.SimpleDateFormat;
  16. import java.util.Arrays;
  17. import java.util.Date;
  18. /**
  19. * 设置通道上传
  20. */
  21. @Slf4j
  22. @Configuration
  23. public class UpChannel{
  24. // 报警回调函数实现
  25. public static HCNetSDK.FMSGCallBack_V31 fMSFCallBack_V31;
  26. /**
  27. * 建立布防上传通道,用于传输数据
  28. *
  29. * @param lUserID 唯一标识符
  30. * @param lAlarmHandle 报警处理器
  31. */
  32. public int setupAlarmChan(int lUserID, int lAlarmHandle) {
  33. // 根据设备注册生成的lUserID建立布防的上传通道,即数据的上传通道
  34. if (lUserID == -1) {
  35. log.info("请先注册");
  36. return lUserID;
  37. }
  38. if (lAlarmHandle < 0) {
  39. // 设备尚未布防,需要先进行布防
  40. if (fMSFCallBack_V31 == null) {
  41. fMSFCallBack_V31 = new FMSGCallBack_V31();
  42. Pointer pUser = null;
  43. if (!InitConfig.hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fMSFCallBack_V31, pUser)) {
  44. log.info("设置回调函数失败!", InitConfig.hCNetSDK.NET_DVR_GetLastError());
  45. }
  46. }
  47. // 这里需要对设备进行相应的参数设置,不设置或设置错误都会导致设备注册失败
  48. HCNetSDK.NET_DVR_SETUPALARM_PARAM m_strAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM();
  49. m_strAlarmInfo.dwSize = m_strAlarmInfo.size();
  50. // 智能交通布防优先级:0 - 一等级(高),1 - 二等级(中),2 - 三等级(低)
  51. m_strAlarmInfo.byLevel = 1;
  52. // 智能交通报警信息上传类型:0 - 老报警信息(NET_DVR_PLATE_RESULT), 1 - 新报警信息(NET_ITS_PLATE_RESULT)
  53. m_strAlarmInfo.byAlarmInfoType = 1;
  54. // 布防类型(仅针对门禁主机、人证设备):0 - 客户端布防(会断网续传),1 - 实时布防(只上传实时数据)
  55. m_strAlarmInfo.byDeployType = 1;
  56. // 抓拍,这个类型要设置为 0 ,最重要的一点设置
  57. m_strAlarmInfo.byFaceAlarmDetection = 0;
  58. m_strAlarmInfo.write();
  59. // 布防成功,返回布防成功的数据传输通道号
  60. lAlarmHandle = InitConfig.hCNetSDK.NET_DVR_SetupAlarmChan_V41(lUserID, m_strAlarmInfo);
  61. if (lAlarmHandle == -1) {
  62. log.info("设备布防失败,错误码=========={}", InitConfig.hCNetSDK.NET_DVR_GetLastError());
  63. // 注销 释放sdk资源
  64. logout(lUserID);
  65. return lAlarmHandle;
  66. } else {
  67. log.info("设备布防成功");
  68. return lAlarmHandle;
  69. }
  70. }
  71. return lAlarmHandle;
  72. }
  73. /**
  74. * 设置报警信息回调函数,根据上传的数据进行回调触发
  75. */
  76. public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
  77. // lCommand 上传消息类型,这个是设备上传的数据类型,比如现在测试的门禁设备,回传回来的是 COMM_ALARM_ACS = 0x5002; 门禁主机报警信息
  78. // pAlarmer 报警设备信息
  79. // pAlarmInfo 报警信息 根据 lCommand 来选择接收的报警信息数据结构
  80. // dwBufLen 报警信息缓存大小
  81. // pUser 用户数据
  82. @Override
  83. public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
  84. alarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser);
  85. return true;
  86. }
  87. }
  88. /**
  89. * 报警撤防
  90. *
  91. * @param lAlarmHandle 报警处理器
  92. */
  93. public int closeAlarmChan(int lAlarmHandle) {
  94. if (lAlarmHandle > -1) {
  95. if (InitConfig.hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle)) {
  96. log.info("撤防成功");
  97. lAlarmHandle = -1;
  98. return lAlarmHandle;
  99. }
  100. return lAlarmHandle;
  101. }
  102. return lAlarmHandle;
  103. }
  104. /**
  105. * 接收设备上传的报警信息,进行上传数据的业务逻辑处理
  106. *
  107. * @param lCommand 上传消息类型
  108. * @param pAlarmer 报警设备信息
  109. * @param pAlarmInfo 报警信息
  110. * @param dwBufLen 报警信息缓存大小
  111. * @param pUser 用户数据
  112. */
  113. public static Pointer alarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
  114. System.out.println("报警监听中================================");
  115. AlarmDataHandle(lCommand,pAlarmer,pAlarmInfo,dwBufLen,pUser);
  116. String sAlarmType = new String();
  117. String[] newRow = new String[3];
  118. //报警时间
  119. Date today = new Date();
  120. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  121. String[] sIP = new String[2];
  122. sAlarmType = new String("lCommand=0x") + Integer.toHexString(lCommand);
  123. // lCommand是传的报警类型
  124. switch (lCommand) {
  125. // 摄像头实时人脸抓拍上传
  126. case HCNetSDK.COMM_UPLOAD_FACESNAP_RESULT:
  127. // 分配存储空间
  128. HCNetSDK.NET_VCA_FACESNAP_RESULT strFaceSnapInfo = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
  129. strFaceSnapInfo.write();
  130. Pointer pFaceSnapInfo = strFaceSnapInfo.getPointer();
  131. // 写入传入数据
  132. pFaceSnapInfo.write(0, pAlarmInfo.getByteArray(0, strFaceSnapInfo.size()), 0, strFaceSnapInfo.size());
  133. strFaceSnapInfo.read();
  134. sAlarmType = sAlarmType + ":人脸抓拍上传[人脸评分:" + strFaceSnapInfo.dwFaceScore + ",抓拍人脸的方式:" + strFaceSnapInfo.struFeature.byRes4 + ",性别:" + strFaceSnapInfo.struFeature.bySex + "]";
  135. newRow[0] = dateFormat.format(today);
  136. // 报警类型
  137. newRow[1] = sAlarmType;
  138. // 报警设备IP地址
  139. sIP = new String(strFaceSnapInfo.struDevInfo.struDevIP.sIpV4).split("\0", 2);
  140. newRow[2] = sIP[0];
  141. log.info("人脸抓拍========{}", Arrays.toString(newRow));
  142. // 设置日期格式
  143. SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
  144. // new Date()为获取当前系统时间
  145. String time = df.format(new Date());
  146. // 人脸图片写文件
  147. File file = new File(System.getProperty("user.dir") + "\\pic1\\");
  148. if (!file.exists()) {
  149. file.mkdir();
  150. }
  151. try {
  152. FileOutputStream big = new FileOutputStream(System.getProperty("user.dir") + "\\pic1\\" + time + "background.jpg");
  153. if (strFaceSnapInfo.dwFacePicLen > 0) {
  154. if (strFaceSnapInfo.dwFacePicLen > 0) {
  155. try {
  156. big.write(strFaceSnapInfo.pBuffer2.getByteArray(0, strFaceSnapInfo.dwBackgroundPicLen), 0, strFaceSnapInfo.dwBackgroundPicLen);
  157. big.close();
  158. } catch (IOException e) {
  159. e.printStackTrace();
  160. }
  161. }
  162. }
  163. } catch (FileNotFoundException e) {
  164. e.printStackTrace();
  165. }
  166. break;
  167. // 门禁主机类型实时人脸抓拍上传,走这里
  168. case HCNetSDK.COMM_ALARM_ACS:
  169. // 分配存储空间
  170. System.out.println("============ 这是门禁主机的报警信息 ============");
  171. HCNetSDK.NET_DVR_ACS_ALARM_INFO strFaceSnapInfo1 = new HCNetSDK.NET_DVR_ACS_ALARM_INFO();
  172. strFaceSnapInfo1.write();
  173. Pointer pFaceSnapInfo1 = strFaceSnapInfo1.getPointer();
  174. // 写入传入数据
  175. pFaceSnapInfo1.write(0, pAlarmInfo.getByteArray(0, strFaceSnapInfo1.size()), 0, strFaceSnapInfo1.size());
  176. strFaceSnapInfo1.read();
  177. // 设置日期格式
  178. SimpleDateFormat df1 = new SimpleDateFormat("yyyyMMddHHmmss");
  179. // new Date()为获取当前系统时间
  180. String time1 = df1.format(new Date());
  181. // 人脸图片写文件
  182. File file1 = new File(System.getProperty("user.dir") + "\\pic3\\");
  183. if (!file1.exists()) {
  184. file1.mkdir();
  185. }
  186. try {
  187. FileOutputStream big = new FileOutputStream(System.getProperty("user.dir") + "\\pic3\\" + time1 + ".jpg");
  188. if (strFaceSnapInfo1.dwPicDataLen > 0) {
  189. System.out.println("========== 图片有数据 ========");
  190. if (strFaceSnapInfo1.dwPicDataLen > 0) {
  191. try {
  192. System.out.println("============ 图片上传成功 =============");
  193. big.write(strFaceSnapInfo1.pPicData.getByteArray(0, strFaceSnapInfo1.dwPicDataLen), 0, strFaceSnapInfo1.dwPicDataLen);
  194. big.close();
  195. System.out.println("设备唯一编码=================" + strFaceSnapInfo1.struAcsEventInfo.byDeviceNo);
  196. System.out.println("数据采集时间=================" + strFaceSnapInfo1.struTime.dwYear + strFaceSnapInfo1.struTime.dwMonth + strFaceSnapInfo1.struTime.dwDay + strFaceSnapInfo1.struTime.dwHour + strFaceSnapInfo1.struTime.dwMinute + strFaceSnapInfo1.struTime.dwSecond);
  197. System.out.println("人员工号=================" + strFaceSnapInfo1.struAcsEventInfo.dwEmployeeNo);
  198. System.out.println("人员姓名=================" + strFaceSnapInfo1.sNetUser);
  199. System.out.println("通进类型(0:入场,1:离场)=================" + strFaceSnapInfo1.struAcsEventInfo.dwDoorNo);
  200. System.out.println("图片唯一标识(工号加时间)=================" + strFaceSnapInfo1.struAcsEventInfo.dwEmployeeNo + time1 + ".jpg");
  201. System.out.println("人员类型(0:白名单,1:访客,2:黑名单)=================" + strFaceSnapInfo1.struAcsEventInfo.byCardType);
  202. } catch (IOException e) {
  203. e.printStackTrace();
  204. }
  205. }
  206. }
  207. } catch (FileNotFoundException e) {
  208. e.printStackTrace();
  209. }
  210. break;
  211. default:
  212. newRow[0] = dateFormat.format(today);
  213. // 报警类型
  214. newRow[1] = sAlarmType;
  215. // 报警设备IP地址
  216. sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
  217. newRow[2] = sIP[0];
  218. log.info("其他报警信息=========={}", Arrays.toString(newRow));
  219. break;
  220. }
  221. return pAlarmInfo;
  222. }
  223. // 抓拍图片
  224. public static void getDVRPic(int userId) throws IOException {
  225. // 设置通道号,其中 1 正常,-1不正常
  226. NativeLong chanLong = new NativeLong(1);
  227. // 返回Boolean值,判断是否获取设备能力
  228. HCNetSDK.NET_DVR_WORKSTATE_V30 devwork = new HCNetSDK.NET_DVR_WORKSTATE_V30();
  229. if (!InitConfig.hCNetSDK.NET_DVR_GetDVRWorkState_V30(userId, devwork)) {
  230. System.out.println("返回设备状态失败");
  231. }
  232. // JPEG图像信息结构体
  233. HCNetSDK.NET_DVR_JPEGPARA jpeg = new HCNetSDK.NET_DVR_JPEGPARA();
  234. jpeg.wPicSize = 2; // 设置图片的分辨率
  235. jpeg.wPicQuality = 2; // 设置图片质量
  236. IntByReference a = new IntByReference();
  237. SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
  238. Date date = new Date();
  239. int random = (int) (Math.random() * 1000);
  240. String fileNameString = sdf.format(date) + random + ".jpg";
  241. // 设置字节缓存
  242. ByteBuffer jpegBuffer = ByteBuffer.allocate(1024 * 1024);
  243. // 抓图到文件
  244. boolean is = InitConfig.hCNetSDK.NET_DVR_CaptureJPEGPicture(userId, chanLong.intValue(), jpeg, fileNameString.getBytes(StandardCharsets.UTF_8));
  245. if (is) {
  246. System.out.println("图片抓取成功,返回长度:" + a.getValue());
  247. } else {
  248. System.out.println("图片抓取失败:" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  249. }
  250. }
  251. /**
  252. * 获取实时报警的事件
  253. * @param lCommand
  254. * @param pAlarmer
  255. * @param pAlarmInfo
  256. * @param dwBufLen
  257. * @param pUser
  258. */
  259. public static void AlarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
  260. HCNetSDK.NET_DVR_ACS_ALARM_INFO strACSInfo;
  261. Pointer pACSInfo;
  262. if (lCommand == 20482) {
  263. System.out.println("===============1111111111111==========");
  264. strACSInfo = new HCNetSDK.NET_DVR_ACS_ALARM_INFO();
  265. strACSInfo.write();
  266. pACSInfo = strACSInfo.getPointer();
  267. pACSInfo.write(0, pAlarmInfo.getByteArray(0, strACSInfo.size()), 0, strACSInfo.size());
  268. strACSInfo.read();
  269. System.out.println("=========22222222=============");
  270. // strACSInfo.byAcsEventInfoExtendV20=1;
  271. // 5代表主事件类型 次事件类型9对应的16进制0x09代表无此卡号
  272. if (strACSInfo.dwMajor == 5 && strACSInfo.dwMinor == 9) {
  273. String deviceIP = (new String(pAlarmer.sDeviceIP)).trim();
  274. String punchTime = strACSInfo.struTime.toStringTime();
  275. String empCode = Integer.toString(strACSInfo.struAcsEventInfo.dwEmployeeNo);
  276. String cardNo = (new String(strACSInfo.struAcsEventInfo.byCardNo)).trim();
  277. System.out.println("======设备ip:====" + deviceIP);
  278. System.out.println("======编号:====" + empCode);
  279. System.out.println("======卡号:====" + cardNo);
  280. System.out.println("======时间:====" + punchTime);
  281. HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND_V20 v20 = new HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND_V20();
  282. v20.write();
  283. Pointer pp = v20.getPointer();
  284. pp.write(0, strACSInfo.pAcsEventInfoExtendV20.getByteArray(0, v20.size()), 0, v20.size());
  285. v20.read();
  286. // System.out.println(v20);
  287. System.out.println("======体温:====" + v20.fCurrTemperature);
  288. // 在项目中可以对接数据库,进行自己的业务逻辑操作
  289. }
  290. }
  291. }
  292. /**
  293. * 注销
  294. *
  295. * @param lUserID 设备注册成功唯一标识符
  296. */
  297. public void logout(int lUserID) {
  298. // 注销
  299. InitConfig.hCNetSDK.NET_DVR_Logout(lUserID);
  300. // 释放sdk资源
  301. InitConfig.hCNetSDK.NET_DVR_Cleanup();
  302. }
  303. }

卡下发删除卡代码

  1. package com.ruoyi.verify.config;
  2. import com.ruoyi.verify.SDKDome.HCNetSDK;
  3. import com.sun.jna.Pointer;
  4. import com.sun.jna.ptr.IntByReference;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.context.annotation.Configuration;
  7. import java.io.UnsupportedEncodingException;
  8. import static com.ruoyi.verify.config.InitConfig.iCharEncodeType;
  9. /**
  10. * 下发卡和删除卡
  11. */
  12. @Slf4j
  13. @Configuration
  14. public class SendAndDeleteCard{
  15. /**
  16. * 卡下发
  17. *
  18. * @param lUserID 用户登录句柄
  19. * @param CardNo 卡号
  20. * @param EmployeeNo 工号 卡下发的时候可以一起下发工号
  21. * @param iPlanTemplateNumber 关联门计划模板,计划模板的配置可以参考卡计划模板配置模块,(下发卡前要设置好计划模板)
  22. * @throws UnsupportedEncodingException
  23. * @throws InterruptedException
  24. */
  25. public static void setOneCard(int lUserID, String CardNo, int EmployeeNo, short iPlanTemplateNumber) throws UnsupportedEncodingException, InterruptedException {
  26. HCNetSDK.NET_DVR_CARD_COND struCardCond = new HCNetSDK.NET_DVR_CARD_COND();
  27. struCardCond.read();
  28. struCardCond.dwSize = struCardCond.size();
  29. //下发一张
  30. struCardCond.dwCardNum = 1;
  31. struCardCond.write();
  32. Pointer ptrStruCond = struCardCond.getPointer();
  33. int m_lSetCardCfgHandle = InitConfig.hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, HCNetSDK.NET_DVR_SET_CARD, ptrStruCond, struCardCond.size(), null, null);
  34. if (m_lSetCardCfgHandle == -1) {
  35. log.info("建立下发卡长连接失败,错误码为" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  36. return;
  37. } else {
  38. log.info("建立下发卡长连接成功!");
  39. }
  40. HCNetSDK.NET_DVR_CARD_RECORD struCardRecord = new HCNetSDK.NET_DVR_CARD_RECORD();
  41. struCardRecord.read();
  42. struCardRecord.dwSize = struCardRecord.size();
  43. for (int i = 0; i < HCNetSDK.ACS_CARD_NO_LEN; i++) {
  44. struCardRecord.byCardNo[i] = 0;
  45. }
  46. for (int i = 0; i < CardNo.length(); i++) {
  47. struCardRecord.byCardNo[i] = CardNo.getBytes()[i];
  48. }
  49. struCardRecord.byCardType = 1; //普通卡
  50. struCardRecord.byLeaderCard = 0; //是否为首卡,0-否,1-是
  51. struCardRecord.byUserType = 0;
  52. struCardRecord.byDoorRight[0] = 1; //门1有权限
  53. struCardRecord.wCardRightPlan[0] = iPlanTemplateNumber; //关联门计划模板,计划模板的配置可以参考卡计划模板配置模块,(下发卡前要设置好计划模板)
  54. struCardRecord.wCardRightPlan[1] = (short) 2;
  55. struCardRecord.struValid.byEnable = 1; //卡有效期使能,下面是卡有效期从2020-1-1 11:11:11到2030-1-1 11:11:11
  56. struCardRecord.struValid.struBeginTime.wYear = 2020;
  57. struCardRecord.struValid.struBeginTime.byMonth = 1;
  58. struCardRecord.struValid.struBeginTime.byDay = 1;
  59. struCardRecord.struValid.struBeginTime.byHour = 11;
  60. struCardRecord.struValid.struBeginTime.byMinute = 11;
  61. struCardRecord.struValid.struBeginTime.bySecond = 11;
  62. struCardRecord.struValid.struEndTime.wYear = 2030;
  63. struCardRecord.struValid.struEndTime.byMonth = 1;
  64. struCardRecord.struValid.struEndTime.byDay = 1;
  65. struCardRecord.struValid.struEndTime.byHour = 11;
  66. struCardRecord.struValid.struEndTime.byMinute = 11;
  67. struCardRecord.struValid.struEndTime.bySecond = 11;
  68. struCardRecord.dwEmployeeNo = EmployeeNo; //工号 卡下发的时候可以一起下发工号
  69. if ((iCharEncodeType == 0) || (iCharEncodeType == 1) || (iCharEncodeType == 2)) {
  70. byte[] strCardName = "jx".getBytes("GBK"); //姓名
  71. for (int i = 0; i < HCNetSDK.NAME_LEN; i++) {
  72. struCardRecord.byName[i] = 0;
  73. }
  74. System.arraycopy(strCardName, 0, struCardRecord.byName, 0, strCardName.length);
  75. }
  76. if (iCharEncodeType == 6) {
  77. byte[] strCardName = "jx".getBytes("UTF-8"); //姓名
  78. for (int i = 0; i < HCNetSDK.NAME_LEN; i++) {
  79. struCardRecord.byName[i] = 0;
  80. }
  81. System.arraycopy(strCardName, 0, struCardRecord.byName, 0, strCardName.length);
  82. }
  83. struCardRecord.write();
  84. HCNetSDK.NET_DVR_CARD_STATUS struCardStatus = new HCNetSDK.NET_DVR_CARD_STATUS();
  85. struCardStatus.read();
  86. struCardStatus.dwSize = struCardStatus.size();
  87. struCardStatus.write();
  88. IntByReference pInt = new IntByReference(0);
  89. while (true) {
  90. int dwState = InitConfig.hCNetSDK.NET_DVR_SendWithRecvRemoteConfig(m_lSetCardCfgHandle, struCardRecord.getPointer(), struCardRecord.size(), struCardStatus.getPointer(), struCardStatus.size(), pInt);
  91. struCardStatus.read();
  92. if (dwState == -1) {
  93. log.info("NET_DVR_SendWithRecvRemoteConfig接口调用失败,错误码:" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  94. break;
  95. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_NEED_WAIT) {
  96. log.info("配置等待");
  97. Thread.sleep(10);
  98. continue;
  99. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FAILED) {
  100. log.info("下发卡失败, 卡号: " + new String(struCardStatus.byCardNo).trim() + ", 错误码:" + struCardStatus.dwErrorCode);
  101. break;
  102. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_EXCEPTION) {
  103. log.info("下发卡异常, 卡号: " + new String(struCardStatus.byCardNo).trim() + ", 错误码:" + struCardStatus.dwErrorCode);
  104. break;
  105. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_SUCCESS) {
  106. if (struCardStatus.dwErrorCode != 0) {
  107. log.info("下发卡成功,但是错误码" + struCardStatus.dwErrorCode + ", 卡号:" + new String(struCardStatus.byCardNo).trim());
  108. } else {
  109. log.info("下发卡成功, 卡号: " + new String(struCardStatus.byCardNo).trim() + ", 状态:" + struCardStatus.byStatus);
  110. }
  111. continue;
  112. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FINISH) {
  113. log.info("下发卡完成");
  114. break;
  115. }
  116. }
  117. if (!InitConfig.hCNetSDK.NET_DVR_StopRemoteConfig(m_lSetCardCfgHandle)) {
  118. log.info("NET_DVR_StopRemoteConfig接口调用失败,错误码:" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  119. } else {
  120. log.info("NET_DVR_StopRemoteConfig接口成功\n");
  121. }
  122. }
  123. /**
  124. * 删除单张卡(删除单张卡号之前要先删除这张卡关联的人脸和指纹信息)
  125. *
  126. * @param lUserID 用户登录句柄
  127. * @param CardNo 卡号
  128. * @throws UnsupportedEncodingException
  129. * @throws InterruptedException
  130. */
  131. public static void delOneCard(int lUserID, String CardNo) throws UnsupportedEncodingException, InterruptedException {
  132. HCNetSDK.NET_DVR_CARD_COND struCardCond = new HCNetSDK.NET_DVR_CARD_COND();
  133. struCardCond.read();
  134. struCardCond.dwSize = struCardCond.size();
  135. struCardCond.dwCardNum = 1; //删除一张卡号
  136. struCardCond.write();
  137. Pointer ptrStruCond = struCardCond.getPointer();
  138. int m_lDelCardCfgHandle = InitConfig.hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, HCNetSDK.NET_DVR_DEL_CARD, ptrStruCond, struCardCond.size(), null, null);
  139. if (m_lDelCardCfgHandle == -1) {
  140. log.info("建立删除卡长连接失败,错误码为" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  141. return;
  142. } else {
  143. log.info("建立删除卡长连接成功!");
  144. }
  145. HCNetSDK.NET_DVR_CARD_SEND_DATA struCardData = new HCNetSDK.NET_DVR_CARD_SEND_DATA();
  146. struCardData.read();
  147. struCardData.dwSize = struCardData.size();
  148. for (int i = 0; i < HCNetSDK.ACS_CARD_NO_LEN; i++) {
  149. struCardData.byCardNo[i] = 0;
  150. }
  151. for (int i = 0; i < CardNo.length(); i++) {
  152. struCardData.byCardNo[i] = CardNo.getBytes()[i];
  153. }
  154. struCardData.write();
  155. HCNetSDK.NET_DVR_CARD_STATUS struCardStatus = new HCNetSDK.NET_DVR_CARD_STATUS();
  156. struCardStatus.read();
  157. struCardStatus.dwSize = struCardStatus.size();
  158. struCardStatus.write();
  159. IntByReference pInt = new IntByReference(0);
  160. while (true) {
  161. int dwState = InitConfig.hCNetSDK.NET_DVR_SendWithRecvRemoteConfig(m_lDelCardCfgHandle, struCardData.getPointer(), struCardData.size(), struCardStatus.getPointer(), struCardStatus.size(), pInt);
  162. struCardStatus.read();
  163. if (dwState == -1) {
  164. log.info("NET_DVR_SendWithRecvRemoteConfig接口调用失败,错误码:" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  165. break;
  166. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_NEED_WAIT) {
  167. log.info("配置等待");
  168. Thread.sleep(10);
  169. continue;
  170. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FAILED) {
  171. log.info("删除卡失败, 卡号: " + new String(struCardStatus.byCardNo).trim() + ", 错误码:" + struCardStatus.dwErrorCode);
  172. break;
  173. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_EXCEPTION) {
  174. log.info("删除卡异常, 卡号: " + new String(struCardStatus.byCardNo).trim() + ", 错误码:" + struCardStatus.dwErrorCode);
  175. break;
  176. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_SUCCESS) {
  177. if (struCardStatus.dwErrorCode != 0) {
  178. log.info("删除卡成功,但是错误码" + struCardStatus.dwErrorCode + ", 卡号:" + new String(struCardStatus.byCardNo).trim());
  179. } else {
  180. log.info("删除卡成功, 卡号: " + new String(struCardStatus.byCardNo).trim() + ", 状态:" + struCardStatus.byStatus);
  181. }
  182. continue;
  183. } else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FINISH) {
  184. log.info("删除卡完成");
  185. break;
  186. }
  187. }
  188. if (!InitConfig.hCNetSDK.NET_DVR_StopRemoteConfig(m_lDelCardCfgHandle)) {
  189. log.info("NET_DVR_StopRemoteConfig接口调用失败,错误码:" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  190. } else {
  191. log.info("NET_DVR_StopRemoteConfig接口成功\n");
  192. }
  193. }
  194. }

远程控门

  1. package com.ruoyi.verify.config;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.context.annotation.Configuration;
  4. /**
  5. * 远程控制门开关类
  6. */
  7. @Slf4j
  8. @Configuration
  9. public class DoorGateway{
  10. /**
  11. * 远程控门
  12. *
  13. * @param lUserID 用户登录句柄
  14. * @param lGatewayIndex 门禁序号(楼层编号、锁ID),从1开始,-1表示对所有门(或者梯控的所有楼层)进行操作
  15. * @param dwStaic 命令值:0- 关闭(对于梯控,表示受控),1- 打开(对于梯控,表示开门),2- 常开(对于梯控,表示自由、通道状态),3- 常关(对于梯控,表示禁用),4- 恢复(梯控,普通状态),5- 访客呼梯(梯控),6- 住户呼梯(梯控)
  16. */
  17. public static void controlGateway(int lUserID, int lGatewayIndex, int dwStaic) {
  18. boolean b_Gate = InitConfig.hCNetSDK.NET_DVR_ControlGateway(lUserID, lGatewayIndex, dwStaic);
  19. if (b_Gate == false) {
  20. log.info("NET_DVR_ControlGateway远程控门失败,错误码为" + InitConfig.hCNetSDK.NET_DVR_GetLastError());
  21. } else {
  22. log.info("远程控门成功");
  23. }
  24. }
  25. }

代码导入之后自己重新导个包,有些代码需要稍微改动,根据自己的业务进行修改

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/383218
推荐阅读
相关标签
  

闽ICP备14008679号