91 lines
3.3 KiB
C++
91 lines
3.3 KiB
C++
// ===========================================================================
|
|
// arisbridge.h —— MSVC 侧对 aris_bridge.dll 的封装
|
|
//
|
|
// 厂商的 libaris.dll 是 MinGW/GCC 编的 C++ 库,MSVC 程序无法直接链接;
|
|
// aris_bridge.dll 由 MinGW 编译,对外只暴露纯 C 函数(见同目录/third_party/
|
|
// aris-bridge/src/aris_bridge.h)。本类用 LoadLibrary 动态加载它,把 C 接口
|
|
// 转成 C++ 方法,供 DeviceManager 使用。
|
|
// ===========================================================================
|
|
|
|
#ifndef ARISBRIDGE_H
|
|
#define ARISBRIDGE_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class ArisBridge
|
|
{
|
|
public:
|
|
// 一台设备的静态参数
|
|
struct DeviceInfo {
|
|
std::string serialNumber;
|
|
int startPixel = 0;
|
|
int endPixel = 0;
|
|
int pixelCount = 0;
|
|
std::vector<float> wavelengths;
|
|
};
|
|
|
|
// 光谱数据回调(在 SDK 的采集线程里被调用)
|
|
typedef void (*DataHandler)(const std::string &serialNumber,
|
|
const std::vector<float> &wavelengths,
|
|
const std::vector<float> &intensities);
|
|
|
|
static ArisBridge &instance();
|
|
|
|
// 桥接 DLL 是否加载成功
|
|
bool isAvailable() const { return m_available; }
|
|
// 加载失败时的原因
|
|
const std::string &lastError() const { return m_lastError; }
|
|
|
|
int connect(); // 查找并初始化设备,返回设备数量;-1 表示失败
|
|
void disconnect(); // 停止测量并断开
|
|
int deviceCount() const;
|
|
|
|
DeviceInfo deviceInfo(int index) const;
|
|
void setSoftwareTrigger();
|
|
int startMeasure(int integrationTimeUs, int averaging);
|
|
void stopMeasure();
|
|
|
|
void setDataHandler(DataHandler handler) { m_handler = handler; }
|
|
|
|
private:
|
|
ArisBridge();
|
|
~ArisBridge();
|
|
ArisBridge(const ArisBridge &) = delete;
|
|
ArisBridge &operator=(const ArisBridge &) = delete;
|
|
|
|
bool load();
|
|
static void __cdecl dataTrampoline(const char *serial,
|
|
const float *wavelengths, int wavelengthCount,
|
|
const float *intensities, int intensityCount);
|
|
|
|
bool m_available = false;
|
|
std::string m_lastError;
|
|
void *m_module = nullptr;
|
|
DataHandler m_handler = nullptr;
|
|
|
|
// 从 aris_bridge.dll 解析出来的 C 函数
|
|
typedef int (__cdecl *FnConnect)(void);
|
|
typedef void (__cdecl *FnDisconnect)(void);
|
|
typedef int (__cdecl *FnDeviceCount)(void);
|
|
typedef int (__cdecl *FnDeviceInfo)(int, char *, int, int *, int *, int *);
|
|
typedef int (__cdecl *FnDeviceWavelengths)(int, float *, int);
|
|
typedef void (__cdecl *FnSetDataCallback)(void (__cdecl *)(const char *, const float *, int, const float *, int));
|
|
typedef void (__cdecl *FnNoArg)(void);
|
|
typedef int (__cdecl *FnStartMeasure)(int, int);
|
|
|
|
FnConnect m_connect = nullptr;
|
|
FnDisconnect m_disconnect = nullptr;
|
|
FnDeviceCount m_deviceCount = nullptr;
|
|
FnDeviceInfo m_deviceInfo = nullptr;
|
|
FnDeviceWavelengths m_deviceWavelengths = nullptr;
|
|
FnSetDataCallback m_setDataCallback = nullptr;
|
|
FnNoArg m_setSoftwareTrigger = nullptr;
|
|
FnStartMeasure m_startMeasure = nullptr;
|
|
FnNoArg m_stopMeasure = nullptr;
|
|
|
|
static ArisBridge *s_instance;
|
|
};
|
|
|
|
#endif // ARISBRIDGE_H
|