大立科技DM63红外相机SDK开发Ⅰ-连接仪器

1、开发准备

为了方便发开,需要下载Visual Studio,本开发基于Visual Studio 2022,使用C++。

通过Visual Studio创建好项目后,将DMSDK V1.16.3内所有文件复制到创建好的项目文件内。

 

2、导入头文件

 通过Visual Studio在源文件处创建C++文件,用来开发,如下图所示。

在C++文件内包含所需要使用的头文件。

#include <iostream>
#include <windows.h>
//#include <stdio.h>
#include <conio.h> // 用于读取键盘输入
#include "DMSDK.h"
#pragma comment(lib, "DMSDK.lib")

 3、数据初始化,连接仪器

 将我们需要使用到的相关数据进行初始化,如IP地址、端口、用户名、密码等

DM_Init();
// 连接仪器
HWND hwnd = NULL(); // 替换为实际的消息处理窗口句柄
char ipAddress[] = "192.168.1.2";  // 替换为实际的仪器IP地址
int port = 80;                       // 替换为实际的命令端口
char userName[] = "admin";           // 替换为实际的用户名
char password[] = "admin";          // 替换为实际的密码

 通过DM_ConnectWithName函数进行连接,并判断是否连接成功

int handle = DM_ConnectWithName(hwnd, ipAddress, port, userName, password);
if (handle > 0) {
    std::cout << "连接成功,操作句柄:" << handle << std::endl;
    //进行相关操作..

}
else {
    std::cout << "连接失败" << std::endl;
}

4、仪器相关操作

连接成功后我们可以对仪器进行相应的控制,比如设置测温区域,得到仪器时间等

// 设置测温区域.
DM_SetArea(handle, 1, 100, 100, 300, 200, 90, 2);

//得到仪器时间
char DateTime[100];
DM_GetDateTime(handle, DateTime);
std::cout << "仪器时间:" << DateTime << std::endl;

5、断开连接

最后我们需要断开仪器的连接,并判断是否断开成功

// 断开连接
int disconnectResult = DM_Disconnect(handle);
if (disconnectResult >= 0) {
    std::cout << "断开连接成功" << std::endl;
}
else {
    std::cout << "断开连接失败" << std::endl;
}

6、总代码

#include <iostream>
#include <windows.h>
#include <conio.h> // 用于读取键盘输入
#include "DMSDK.h"
#pragma comment(lib, "DMSDK.lib")

int main() {
    DM_Init();
    // 连接仪器
    HWND hwnd = NULL(); // 替换为实际的消息处理窗口句柄
    char ipAddress[] = "192.168.1.2";  // 替换为实际的仪器IP地址
    int port = 80;                       // 替换为实际的命令端口
    char userName[] = "admin";           // 替换为实际的用户名
    char password[] = "admin";          // 替换为实际的密码
    int handle = DM_ConnectWithName(hwnd, ipAddress, port, userName, password);
    if (handle > 0) {
        std::cout << "连接成功,操作句柄:" << handle << std::endl;

        // 设置测温区域.
        DM_SetArea(handle, 1, 100, 100, 300, 200, 90, 2);

        //得到仪器时间
        char DateTime[100];
        DM_GetDateTime(handle, DateTime);
        std::cout << "仪器时间:" << DateTime << std::endl;

        //等待按下Esc键
        std::cout << "按下Esc键关闭连接..." << std::endl;
        while (!_kbhit() || _getch() != 27) { // 按下的键不是Esc键,则继续等待
            // 在此处可以执行其他操作
        }

        // 断开连接
        int disconnectResult = DM_Disconnect(handle);
        if (disconnectResult >= 0) {
            std::cout << "断开连接成功" << std::endl;
        }
        else {
            std::cout << "断开连接失败" << std::endl;
        }
    }
    else {
        std::cout << "连接失败" << std::endl;
    }
    return 0;
}

 

posted @ 2023-09-14 10:13  放氮气的蜗牛  阅读(52)  评论(0编辑  收藏  举报  来源