1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.netsdk.demo.customize.surfaceEventDemo.module;
 
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.sun.jna.ptr.IntByReference;
 
/**
 * 通用登录接口
 *
 * @author 47040
 * @since Created in 2021/3/25 18:56
 */
public class LogonModule {
 
    private static final NetSDKLib NetSdk = NetSDKLib.NETSDK_INSTANCE;
 
    // 登录按钮事件
    public NetSDKLib.LLong login(String ipAddress, Integer port, String userName, String password, NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo) {
        System.out.println("设备地址:" + ipAddress + "\n端口号:" + port + "\n用户名:" + userName + "\n密码:" + password);
 
        NetSDKLib.LLong m_hLoginHandle = NetSdk.CLIENT_LoginEx2(
                ipAddress, port, userName, password,
                0, null, m_stDeviceInfo, new IntByReference(0));
        if (m_hLoginHandle.longValue() == 0) {
            System.err.printf("Login Device[%s] Port[%d]Failed. Last Error[%s]\n", ipAddress, port, ToolKits.getErrorCode());
        } else {
            System.out.println("Login Success [ " + ipAddress + " ]");
        }
        return m_hLoginHandle;
    }
 
    // 登出按钮事件
    public void logout(NetSDKLib.LLong m_hLoginHandle) {
        if (m_hLoginHandle.longValue() != 0) {
            System.out.println("Logout Button Action");
 
            if (NetSdk.CLIENT_Logout(m_hLoginHandle)) {
                System.out.println("Logout Success.");
                m_hLoginHandle.setValue(0);
            }
        }
    }
 
}