Best Practices in Secondary Development of Java Hikvision SDK
Abstract:
With the widespread application of modern monitoring technology, Hikvision provides SDK (Software Development Kit) has become the first choice for many developers. This article will introduce the best practices in secondary development of Java Hikvision SDK and provide some code examples.
import com.sun.jna.NativeLong; import com.sun.jna.Pointer; public class DeviceConnection { private static final int TIMEOUT = 5000; // 连接超时时间,单位为毫秒 public static NativeLong login(String ip, int port, String username, String password) { HCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30(); NativeLong lUserID = HCNetSDK.NET_DVR_Login_V30(ip, port, username, password, deviceInfo); if (lUserID.longValue() == -1) { System.err.println("登录设备失败,错误码:" + HCNetSDK.NET_DVR_GetLastError()); } return lUserID; } public static void logout(NativeLong lUserID) { if (!HCNetSDK.NET_DVR_Logout(lUserID)) { System.err.println("登出设备失败,错误码:" + HCNetSDK.NET_DVR_GetLastError()); } } public static void main(String[] args) { String ip = "192.168.1.100"; int port = 8000; String username = "admin"; String password = "123456"; NativeLong lUserID = login(ip, port, username, password); // do something... logout(lUserID); } }
import com.sun.jna.NativeLong; public class DeviceStatus { public static boolean isDeviceOnline(NativeLong lUserID) { HCNetSDK.NET_DVR_WORKSTATE_V30 deviceStatus = new HCNetSDK.NET_DVR_WORKSTATE_V30(); if (!HCNetSDK.NET_DVR_GetDVRWorkState_V30(lUserID, deviceStatus)) { System.err.println("获取设备状态失败,错误码:" + HCNetSDK.NET_DVR_GetLastError()); } return deviceStatus.dwDeviceStatic == 1; } public static void main(String[] args) { NativeLong lUserID = new NativeLong(12345); // 假设已经登录并获取到了lUserID if (isDeviceOnline(lUserID)) { System.out.println("设备在线"); } else { System.out.println("设备离线"); } } }
import com.sun.jna.NativeLong; public class DeviceSetting { public static boolean setDeviceTime(NativeLong lUserID) { HCNetSDK.NET_DVR_TIME time = new HCNetSDK.NET_DVR_TIME(); time.dwYear = 2022; time.dwMonth = 7; time.dwDay = 1; time.dwHour = 12; time.dwMinute = 0; time.dwSecond = 0; if (!HCNetSDK.NET_DVR_SetDVRConfig(lUserID, HCNetSDK.NET_DVR_SET_TIMECFG, 0, time.getPointer(), time.size(), null)) { System.err.println("设置设备时间失败,错误码:" + HCNetSDK.NET_DVR_GetLastError()); } return true; } public static void main(String[] args) { NativeLong lUserID = new NativeLong(12345); // 假设已经登录并获取到了lUserID if (setDeviceTime(lUserID)) { System.out.println("设置设备时间成功"); } else { System.out.println("设置设备时间失败"); } } }
Summary:
Through the above sample code, we have learned some best practices in the secondary development of Java Hikvision SDK, including device Connect, get device status and set device parameters. In actual development, we can further use the interface provided by Hikvision SDK to complete more complex functions according to project needs. I hope this article will be helpful to developers who are developing Java Hikvision SDK.
The above is the detailed content of Best practices in secondary development of Java Hikvision SDK. For more information, please follow other related articles on the PHP Chinese website!