跳转至

异常报警

功能说明

可以监控设备上线、下线,NVR 通道上线、下线。

接口概览

接口名称 功能描述
NET_SDK_SetSDKMessageCallBack SDK 操作异常回调函数

流程说明

---
title: 异常报警
---
flowchart TD
    A(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
    B(用户注册设备<br><strong>NET_SDK_Login</strong>或<br><strong>NET_SDK_LoginEx</strong>)
    C(异常报警回调函数<br><strong>NET_SDK_SetSDKMessageCallBack</strong>)
    D(注销设备<br><strong>NET_SDK_Logout</strong>)
    E(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)

    A --> B --> C --> D --> E

示例代码

 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

void excertionCallback(DWORD dwType, LONG lUserID, LONG lHandle, void *pUser)
{
    if (NETWORK_DISCONNECT == dwType)
    {
        cout << "type: " << dwType << " userID: " << lUserID << " channel: " << lHandle << "-----NETWORK_DISCONNECT" << endl;
    }
    else if (NETWORK_RECONNECT == dwType)
    {
        cout << "type: " << dwType << " userID: " << lUserID << " channel: " << lHandle << "-----NETWORK_RECONNECT" << endl;
    }
    else if (NETWORK_CH_DISCONNECT == dwType)
    {
        cout << "type: " << dwType << " userID: " << lUserID << " channel: " << lHandle << "-----NETWORK_CH_DISCONNECT" << endl;
    }
    else if (NETWORK_CH_RECONNECT == dwType)
    {
        cout << "type: " << dwType << " userID: " << lUserID << " channel: " << lHandle << "-----NETWORK_CH_RECONNECT" << endl;
    }
    else
    {
        cout << "Unknow error code: " << dwType << endl;
    }
}

void AbnormalAlarmProcess()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.177";
    DWORD device_port = 6036;
    // init sdk
    NET_SDK_Init();
    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return;
    }

    // SDK operation abnormal callback function
    bool isOk = NET_SDK_SetSDKMessageCallBack(0, 0, excertionCallback, NULL);

    if (isOk)
    {
        cout << "Set message callback successfully" << endl;
    }
    else
    {
        cout << "Set message callback failed" << endl;
    }

    Sleep(100000);
    // logout
    NET_SDK_Logout(userid);
    NET_SDK_Cleanup();
}
错误码