GrabBag/Device/GalaxyDevice/Inc/IGalaxyDevice.h

302 lines
8.1 KiB
C
Raw Normal View History

2026-03-28 10:49:55 +08:00
#ifndef IGALAXYDEVICE_H
#define IGALAXYDEVICE_H
#include <iostream>
#include <string>
#include <vector>
#include <functional>
// 设备信息结构
struct GalaxyDeviceInfo
{
std::string serialNumber; // 序列号
std::string modelName; // 型号名称
std::string displayName; // 显示名称
std::string ipAddress; // IP地址(如果是网口相机)
std::string macAddress; // MAC地址(如果是网口相机)
std::string deviceClass; // 设备类别(USB/GigE等)
unsigned int width; // 图像宽度
unsigned int height; // 图像高度
};
// 图像数据结构
struct GalaxyImageData
{
unsigned char* pData; // 图像数据指针
unsigned int width; // 图像宽度
unsigned int height; // 图像高度
unsigned int dataSize; // 数据大小
int pixelFormat; // 像素格式
unsigned long long frameID; // 帧ID
unsigned long long timestamp; // 时间戳
};
// ROI (Region of Interest) 结构
struct GalaxyROI
{
int offsetX; // X偏移
int offsetY; // Y偏移
int width; // ROI宽度
int height; // ROI高度
};
// 图像回调函数类型
using GalaxyImageCallback = std::function<void(const GalaxyImageData&)>;
/**
* @brief IGalaxyDevice 接口类
* 封装大恒Galaxy SDK,提供工业相机采集的C++接口
*/
class IGalaxyDevice
{
public:
virtual ~IGalaxyDevice() = default;
/**
* @brief 创建设备对象
* @param ppDevice 设备对象指针
* @return 0-成功,其他-失败
*/
static int CreateObject(IGalaxyDevice** ppDevice);
/**
* @brief 初始化SDK
* @return 0-成功,其他-失败
*/
virtual int InitSDK() = 0;
/**
* @brief 反初始化SDK(程序退出时调用)
* @return 0-成功,其他-失败
*/
virtual int UninitSDK() = 0;
/**
* @brief 获取SDK版本
* @param version SDK版本字符串
* @return 0-成功,其他-失败
*/
virtual int GetSDKVersion(std::string& version) = 0;
/**
* @brief 枚举网络中的Galaxy相机
* @param deviceList 返回的设备列表
* @param timeout 超时时间(毫秒),默认1000ms
* @return 0-成功,其他-失败
*/
virtual int EnumerateDevices(std::vector<GalaxyDeviceInfo>& deviceList, unsigned int timeout = 1000) = 0;
/**
* @brief 通过序列号打开相机
* @param serialNumber 相机序列号
* @return 0-成功,其他-失败
*/
virtual int OpenDevice(const std::string& serialNumber) = 0;
/**
* @brief 通过索引打开相机(从枚举列表中的索引)
* @param index 设备索引(从0开始)
* @return 0-成功,其他-失败
*/
virtual int OpenDeviceByIndex(unsigned int index) = 0;
/**
* @brief 关闭相机
* @return 0-成功,其他-失败
*/
virtual int CloseDevice() = 0;
/**
* @brief 检查是否已打开
* @return true-已打开,false-未打开
*/
virtual bool IsDeviceOpen() = 0;
/**
* @brief 获取已打开相机的设备信息
* @param deviceInfo 设备信息结构
* @return 0-成功,其他-失败
*/
virtual int GetDeviceInfo(GalaxyDeviceInfo& deviceInfo) = 0;
/**
* @brief 设置触发模式
* @param enable true-启用触发模式,false-连续采集模式
* @return 0-成功,其他-失败
*/
virtual int SetTriggerMode(bool enable) = 0;
/**
* @brief 软触发一次
* @return 0-成功,其他-失败
*/
virtual int SendSoftTrigger() = 0;
/**
* @brief 开始采集
* @return 0-成功,其他-失败
*/
virtual int StartAcquisition() = 0;
/**
* @brief 停止采集
* @return 0-成功,其他-失败
*/
virtual int StopAcquisition() = 0;
/**
* @brief 检查是否正在采集
* @return true-正在采集,false-未采集
*/
virtual bool IsAcquisitioning() = 0;
/**
* @brief 单次采集图像(触发模式)
* @param image 图像数据结构
* @param timeout 超时时间(毫秒),默认5000ms
* @return 0-成功,其他-失败
* @note 图像数据内存需要调用者释放
*/
virtual int CaptureImage(GalaxyImageData& image, unsigned int timeout = 5000) = 0;
/**
* @brief 注册图像回调(用于连续采集模式)
* @param callback 图像回调函数
* @return 0-成功,其他-失败
*/
virtual int RegisterImageCallback(GalaxyImageCallback callback) = 0;
/**
* @brief 取消注册图像回调
* @return 0-成功,其他-失败
*/
virtual int UnregisterImageCallback() = 0;
/**
* @brief 获取图像宽度
* @param width 图像宽度
* @return 0-成功,其他-失败
*/
virtual int GetWidth(unsigned int& width) = 0;
/**
* @brief 获取图像高度
* @param height 图像高度
* @return 0-成功,其他-失败
*/
virtual int GetHeight(unsigned int& height) = 0;
/**
* @brief 设置ROI(感兴趣区域)
* @param roi ROI结构
* @return 0-成功,其他-失败
*/
virtual int SetROI(const GalaxyROI& roi) = 0;
/**
* @brief 获取ROI(感兴趣区域)
* @param roi ROI结构
* @return 0-成功,其他-失败
*/
virtual int GetROI(GalaxyROI& roi) = 0;
/**
* @brief 设置曝光时间
* @param exposureTime 曝光时间(微秒)
* @return 0-成功,其他-失败
*/
virtual int SetExposureTime(double exposureTime) = 0;
/**
* @brief 获取曝光时间
* @param exposureTime 曝光时间(微秒)
* @return 0-成功,其他-失败
*/
virtual int GetExposureTime(double& exposureTime) = 0;
/**
* @brief 设置增益
* @param gain 增益值
* @return 0-成功,其他-失败
*/
virtual int SetGain(double gain) = 0;
/**
* @brief 获取增益
* @param gain 增益值
* @return 0-成功,其他-失败
*/
virtual int GetGain(double& gain) = 0;
/**
* @brief 设置帧率
* @param frameRate 帧率(fps)
* @return 0-成功,其他-失败
*/
virtual int SetFrameRate(double frameRate) = 0;
/**
* @brief 获取帧率
* @param frameRate 帧率(fps)
* @return 0-成功,其他-失败
*/
virtual int GetFrameRate(double& frameRate) = 0;
/**
* @brief 设置整型特性值
* @param featureName 特性名称
* @param value 特性值
* @return 0-成功,其他-失败
*/
virtual int SetIntFeature(const std::string& featureName, int64_t value) = 0;
/**
* @brief 获取整型特性值
* @param featureName 特性名称
* @param value 特性值
* @return 0-成功,其他-失败
*/
virtual int GetIntFeature(const std::string& featureName, int64_t& value) = 0;
/**
* @brief 设置浮点型特性值
* @param featureName 特性名称
* @param value 特性值
* @return 0-成功,其他-失败
*/
virtual int SetFloatFeature(const std::string& featureName, double value) = 0;
/**
* @brief 获取浮点型特性值
* @param featureName 特性名称
* @param value 特性值
* @return 0-成功,其他-失败
*/
virtual int GetFloatFeature(const std::string& featureName, double& value) = 0;
/**
* @brief 设置枚举型特性值
* @param featureName 特性名称
* @param value 特性值
* @return 0-成功,其他-失败
*/
virtual int SetEnumFeature(const std::string& featureName, int64_t value) = 0;
/**
* @brief 获取枚举型特性值
* @param featureName 特性名称
* @param value 特性值
* @return 0-成功,其他-失败
*/
virtual int GetEnumFeature(const std::string& featureName, int64_t& value) = 0;
/**
* @brief 执行命令特性
* @param featureName 特性名称
* @return 0-成功,其他-失败
*/
virtual int ExecuteCommand(const std::string& featureName) = 0;
};
#endif // IGALAXYDEVICE_H