using MVSDK_Net;
|
using System;
|
using System.Collections.Generic;
|
using System.Drawing;
|
using System.Drawing.Imaging;
|
using System.Linq;
|
using System.Runtime.InteropServices;
|
using System.Threading;
|
using System.Windows.Forms;
|
|
namespace LB_VisionProcesses.Cameras
|
{
|
/// <summary>
|
/// 华睿2D工业相机实现类
|
/// 基于MVSDK_Net SDK封装
|
/// </summary>
|
public class HRCamera : BaseCamera
|
{
|
#region 私有字段
|
|
private MyCamera _camera; // 华睿相机设备对象
|
private Thread _grabThread; // 图像采集线程
|
private bool _isGrabbing; // 采集状态标志
|
private bool _threadRunning; // 线程运行标志
|
private Thread _callbackThread; // 回调处理线程
|
private List<IMVDefine.IMV_Frame> _frameList; // 图像缓存列表
|
private readonly object _frameLock = new object(); // 帧缓存锁
|
|
// CopyMemory API声明
|
[System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
|
private static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
|
|
#endregion
|
|
#region 构造函数和析构函数
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public HRCamera()
|
{
|
_camera = new MyCamera();
|
_frameList = new List<IMVDefine.IMV_Frame>();
|
Brand = CameraBrand.HRCamera;
|
_isGrabbing = false;
|
_threadRunning = false;
|
}
|
|
/// <summary>
|
/// 析构函数
|
/// </summary>
|
~HRCamera()
|
{
|
Dispose(false);
|
}
|
|
#endregion
|
|
#region 设备管理操作
|
|
/// <summary>
|
/// 获取相机SN枚举列表
|
/// </summary>
|
/// <returns>相机SN列表</returns>
|
public override List<string> GetListEnum()
|
{
|
List<string> cameraList = new List<string>();
|
|
try
|
{
|
// 枚举所有设备
|
IMVDefine.IMV_DeviceList deviceList = new IMVDefine.IMV_DeviceList();
|
IMVDefine.IMV_EInterfaceType interfaceType = IMVDefine.IMV_EInterfaceType.interfaceTypeAll;
|
|
int result = MyCamera.IMV_EnumDevices(ref deviceList, (uint)interfaceType);
|
|
if (result == IMVDefine.IMV_OK && deviceList.nDevNum > 0)
|
{
|
for (int i = 0; i < deviceList.nDevNum; i++)
|
{
|
IMVDefine.IMV_DeviceInfo deviceInfo = (IMVDefine.IMV_DeviceInfo)
|
Marshal.PtrToStructure(
|
deviceList.pDevInfo + Marshal.SizeOf(typeof(IMVDefine.IMV_DeviceInfo)) * i,
|
typeof(IMVDefine.IMV_DeviceInfo));
|
|
string cameraInfo = $"{deviceInfo.cameraName}[{deviceInfo.serialNumber}]";
|
cameraList.Add(cameraInfo);
|
}
|
}
|
else
|
{
|
// 记录日志或抛出异常
|
throw new Exception($"枚举设备失败,错误码:{result}");
|
}
|
}
|
catch (Exception ex)
|
{
|
// 记录错误日志
|
System.Diagnostics.Debug.WriteLine($"获取相机列表失败:{ex.Message}");
|
throw;
|
}
|
|
return cameraList;
|
}
|
|
/// <summary>
|
/// 初始化相机设备
|
/// </summary>
|
/// <param name="SN">相机序列号</param>
|
/// <param name="Handle">窗口句柄(可选)</param>
|
/// <returns>初始化是否成功</returns>
|
public override bool InitDevice(string SN, object Handle = null)
|
{
|
try
|
{
|
// 如果相机已打开,先关闭
|
if (_camera != null && _camera.IMV_IsOpen())
|
{
|
CloseDevice();
|
}
|
|
// 枚举设备并匹配SN
|
List<string> cameraList = GetListEnum();
|
int cameraIndex = -1;
|
|
for (int i = 0; i < cameraList.Count; i++)
|
{
|
if (cameraList[i].Contains(SN))
|
{
|
cameraIndex = i;
|
break;
|
}
|
}
|
|
if (cameraIndex == -1)
|
{
|
throw new Exception($"未找到序列号为 {SN} 的相机");
|
}
|
|
// 创建设备句柄
|
int result = _camera.IMV_CreateHandle(IMVDefine.IMV_ECreateHandleMode.modeByIndex, cameraIndex);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"创建设备句柄失败,错误码:{result}");
|
}
|
|
// 打开设备
|
result = _camera.IMV_Open();
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"打开相机失败,错误码:{result}");
|
}
|
|
// 设置设备属性
|
SN = SN;
|
isGrabbing = false;
|
|
// 设置缓存个数为8
|
_camera.IMV_SetBufferCount(8);
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"初始化相机失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 关闭相机设备
|
/// </summary>
|
/// <returns>关闭是否成功</returns>
|
public override bool CloseDevice()
|
{
|
try
|
{
|
if (_camera == null)
|
return true;
|
|
// 停止采集
|
if (_camera.IMV_IsGrabbing())
|
{
|
StopGrabbing();
|
}
|
|
// 关闭设备
|
if (_camera.IMV_IsOpen())
|
{
|
int result = _camera.IMV_Close();
|
if (result != IMVDefine.IMV_OK)
|
{
|
System.Diagnostics.Debug.WriteLine($"关闭相机失败,错误码:{result}");
|
}
|
}
|
|
// 释放资源
|
_isGrabbing = false;
|
isGrabbing = false;
|
|
// 清理帧缓存
|
lock (_frameLock)
|
{
|
foreach (var frame in _frameList)
|
{
|
var tempFrame = frame; // 创建临时变量
|
_camera.IMV_ReleaseFrame(ref tempFrame);
|
}
|
_frameList.Clear();
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"关闭相机失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
#endregion
|
|
#region 图像采集操作
|
|
/// <summary>
|
/// 开始图像采集
|
/// </summary>
|
/// <returns>采集启动是否成功</returns>
|
public override bool StartGrabbing()
|
{
|
try
|
{
|
if (_camera == null || !_camera.IMV_IsOpen())
|
{
|
throw new Exception("相机未打开");
|
}
|
|
// 停止现有采集
|
if (_isGrabbing)
|
{
|
StopGrabbing();
|
}
|
|
// 启动采集
|
int result = _camera.IMV_StartGrabbing();
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"启动采集失败,错误码:{result}");
|
}
|
|
_isGrabbing = true;
|
isGrabbing = true;
|
|
// 启动采集线程
|
_threadRunning = true;
|
_grabThread = new Thread(GrabThreadProc);
|
_grabThread.IsBackground = true;
|
_grabThread.Start();
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"启动采集失败:{ex.Message}");
|
_isGrabbing = false;
|
isGrabbing = false;
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 停止图像采集
|
/// </summary>
|
/// <returns>停止是否成功</returns>
|
public override bool StopGrabbing()
|
{
|
try
|
{
|
if (_camera == null || !_isGrabbing)
|
return true;
|
|
// 停止线程
|
_threadRunning = false;
|
if (_grabThread != null && _grabThread.IsAlive)
|
{
|
_grabThread.Join(1000);
|
_grabThread = null;
|
}
|
|
// 停止采集
|
int result = _camera.IMV_StopGrabbing();
|
if (result != IMVDefine.IMV_OK)
|
{
|
System.Diagnostics.Debug.WriteLine($"停止采集失败,错误码:{result}");
|
}
|
|
_isGrabbing = false;
|
isGrabbing = false;
|
|
// 清理缓存
|
lock (_frameLock)
|
{
|
foreach (var frame in _frameList)
|
{
|
var tempFrame = frame; // 创建临时变量
|
_camera.IMV_ReleaseFrame(ref tempFrame);
|
}
|
_frameList.Clear();
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"停止采集失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 执行软触发
|
/// </summary>
|
/// <returns>触发是否成功</returns>
|
public override bool SoftTrigger()
|
{
|
try
|
{
|
if (_camera == null || !_camera.IMV_IsOpen())
|
{
|
throw new Exception("相机未打开");
|
}
|
|
int result = _camera.IMV_ExecuteCommandFeature("TriggerSoftware");
|
return result == IMVDefine.IMV_OK;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"软触发失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
#endregion
|
|
#region 参数设置和获取
|
|
/// <summary>
|
/// 设置触发模式
|
/// </summary>
|
/// <param name="mode">触发模式</param>
|
/// <param name="source">触发源</param>
|
/// <returns>设置是否成功</returns>
|
public override bool SetTriggerMode(TriggerMode mode, TriggerSource source = TriggerSource.Line0)
|
{
|
try
|
{
|
if (_camera == null || !_camera.IMV_IsOpen())
|
{
|
throw new Exception("相机未打开");
|
}
|
|
// 设置触发模式
|
string triggerMode = mode == TriggerMode.On ? "On" : "Off";
|
int result = _camera.IMV_SetEnumFeatureSymbol("TriggerMode", triggerMode);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"设置触发模式失败,错误码:{result}");
|
}
|
|
// 设置触发源
|
if (mode == TriggerMode.On)
|
{
|
string triggerSource = GetTriggerSourceString(source);
|
result = _camera.IMV_SetEnumFeatureSymbol("TriggerSource", triggerSource);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"设置触发源失败,错误码:{result}");
|
}
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"设置触发模式失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 获取触发模式
|
/// </summary>
|
/// <param name="mode">触发模式</param>
|
/// <param name="source">触发源</param>
|
/// <returns>获取是否成功</returns>
|
public override bool GetTriggerMode(out TriggerMode mode, out TriggerSource source)
|
{
|
mode = TriggerMode.Off;
|
source = TriggerSource.Software;
|
|
try
|
{
|
if (_camera == null || !_camera.IMV_IsOpen())
|
{
|
throw new Exception("相机未打开");
|
}
|
|
// 获取触发模式
|
IMVDefine.IMV_String triggerMode = new IMVDefine.IMV_String();
|
int result = _camera.IMV_GetEnumFeatureSymbol("TriggerMode", ref triggerMode);
|
if (result == IMVDefine.IMV_OK)
|
{
|
mode = triggerMode.str == "On" ? TriggerMode.On : TriggerMode.Off;
|
}
|
|
// 获取触发源
|
IMVDefine.IMV_String triggerSource = new IMVDefine.IMV_String();
|
result = _camera.IMV_GetEnumFeatureSymbol("TriggerSource", ref triggerSource);
|
if (result == IMVDefine.IMV_OK)
|
{
|
source = GetTriggerSourceFromString(triggerSource.str);
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"获取触发模式失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 设置曝光时间
|
/// </summary>
|
/// <param name="value">曝光时间(微秒)</param>
|
/// <returns>设置是否成功</returns>
|
public override bool SetExpouseTime(double value)
|
{
|
try
|
{
|
if (_camera == null || !_camera.IMV_IsOpen())
|
{
|
throw new Exception("相机未打开");
|
}
|
|
// 验证曝光时间范围
|
double minExp = 0, maxExp = 0;
|
int result = _camera.IMV_GetDoubleFeatureMin("ExposureTime", ref minExp);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"获取曝光时间最小值失败,错误码:{result}");
|
}
|
|
result = _camera.IMV_GetDoubleFeatureMax("ExposureTime", ref maxExp);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"获取曝光时间最大值失败,错误码:{result}");
|
}
|
|
if (value < minExp || value > maxExp)
|
{
|
throw new Exception($"曝光时间超出范围,有效范围:{minExp} - {maxExp}");
|
}
|
|
// 设置曝光时间
|
result = _camera.IMV_SetDoubleFeatureValue("ExposureTime", value);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"设置曝光时间失败,错误码:{result}");
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"设置曝光时间失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 获取曝光时间
|
/// </summary>
|
/// <param name="value">曝光时间</param>
|
/// <returns>获取是否成功</returns>
|
public override bool GetExpouseTime(out double value)
|
{
|
value = 0;
|
|
try
|
{
|
if (_camera == null || !_camera.IMV_IsOpen())
|
{
|
throw new Exception("相机未打开");
|
}
|
|
int result = _camera.IMV_GetDoubleFeatureValue("ExposureTime", ref value);
|
return result == IMVDefine.IMV_OK;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"获取曝光时间失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 设置增益
|
/// </summary>
|
/// <param name="gain">增益值</param>
|
/// <returns>设置是否成功</returns>
|
public override bool SetGain(double gain)
|
{
|
try
|
{
|
if (_camera == null || !_camera.IMV_IsOpen())
|
{
|
throw new Exception("相机未打开");
|
}
|
|
// 验证增益范围
|
double minGain = 0, maxGain = 0;
|
int result = _camera.IMV_GetDoubleFeatureMin("GainRaw", ref minGain);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"获取增益最小值失败,错误码:{result}");
|
}
|
|
result = _camera.IMV_GetDoubleFeatureMax("GainRaw", ref maxGain);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"获取增益最大值失败,错误码:{result}");
|
}
|
|
if (gain < minGain || gain > maxGain)
|
{
|
throw new Exception($"增益值超出范围,有效范围:{minGain} - {maxGain}");
|
}
|
|
// 设置增益
|
result = _camera.IMV_SetDoubleFeatureValue("GainRaw", gain);
|
if (result != IMVDefine.IMV_OK)
|
{
|
throw new Exception($"设置增益失败,错误码:{result}");
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"设置增益失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 获取增益值
|
/// </summary>
|
/// <param name="gain">增益值</param>
|
/// <returns>获取是否成功</returns>
|
public override bool GetGain(out double gain)
|
{
|
gain = 0;
|
|
try
|
{
|
if (_camera == null || !_camera.IMV_IsOpen())
|
{
|
throw new Exception("相机未打开");
|
}
|
|
int result = _camera.IMV_GetDoubleFeatureValue("GainRaw", ref gain);
|
return result == IMVDefine.IMV_OK;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"获取增益失败:{ex.Message}");
|
return false;
|
}
|
}
|
|
// 其他参数设置方法类似,这里省略部分实现...
|
|
#endregion
|
|
#region 辅助方法
|
|
/// <summary>
|
/// 图像采集线程处理函数
|
/// </summary>
|
private void GrabThreadProc()
|
{
|
IMVDefine.IMV_Frame frame = new IMVDefine.IMV_Frame();
|
|
while (_threadRunning)
|
{
|
try
|
{
|
// 获取图像帧
|
int result = _camera.IMV_GetFrame(ref frame, 100);
|
|
if (result == IMVDefine.IMV_OK)
|
{
|
// 处理图像帧
|
ProcessFrame(frame);
|
}
|
else if (result != 0x80000001) // 超时错误代码(常见值)
|
{
|
// 非超时错误
|
System.Diagnostics.Debug.WriteLine($"获取图像帧失败,错误码:{result}");
|
}
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"采集线程异常:{ex.Message}");
|
}
|
|
Thread.Sleep(1);
|
}
|
}
|
|
/// <summary>
|
/// 处理图像帧
|
/// </summary>
|
/// <param name="frame">图像帧</param>
|
private void ProcessFrame(IMVDefine.IMV_Frame frame)
|
{
|
try
|
{
|
// 将图像数据转换为Bitmap
|
Bitmap bitmap = ConvertFrameToBitmap(frame);
|
|
if (bitmap != null)
|
{
|
// 触发图像采集事件
|
CameraEventArgs args = new CameraEventArgs(SN, bitmap);
|
ImageGrabbed?.Invoke(this, args);
|
|
// 更新回调图像
|
CallBackImg = bitmap;
|
}
|
|
// 释放帧
|
_camera.IMV_ReleaseFrame(ref frame);
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"处理图像帧失败:{ex.Message}");
|
}
|
}
|
|
/// <summary>
|
/// 将图像帧转换为Bitmap
|
/// </summary>
|
/// <param name="frame">图像帧</param>
|
/// <returns>Bitmap对象</returns>
|
private Bitmap ConvertFrameToBitmap(IMVDefine.IMV_Frame frame)
|
{
|
try
|
{
|
Bitmap bitmap = null;
|
|
switch (frame.frameInfo.pixelFormat)
|
{
|
case IMVDefine.IMV_EPixelType.gvspPixelMono8:
|
bitmap = CreateMono8Bitmap(frame);
|
break;
|
case IMVDefine.IMV_EPixelType.gvspPixelBGR8:
|
bitmap = CreateBgr8Bitmap(frame);
|
break;
|
default:
|
// 其他格式需要转换
|
bitmap = ConvertToBGR8(frame);
|
break;
|
}
|
|
return bitmap;
|
}
|
catch (Exception ex)
|
{
|
System.Diagnostics.Debug.WriteLine($"图像格式转换失败:{ex.Message}");
|
return null;
|
}
|
}
|
|
/// <summary>
|
/// 创建Mono8格式Bitmap
|
/// </summary>
|
private Bitmap CreateMono8Bitmap(IMVDefine.IMV_Frame frame)
|
{
|
Bitmap bitmap = new Bitmap((int)frame.frameInfo.width, (int)frame.frameInfo.height, PixelFormat.Format8bppIndexed);
|
|
// 设置灰度调色板
|
ColorPalette palette = bitmap.Palette;
|
for (int i = 0; i < 256; i++)
|
{
|
palette.Entries[i] = Color.FromArgb(i, i, i);
|
}
|
bitmap.Palette = palette;
|
|
// 复制图像数据
|
BitmapData bmpData = bitmap.LockBits(
|
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
|
ImageLockMode.WriteOnly,
|
bitmap.PixelFormat);
|
|
// 使用CopyMemory API进行内存复制
|
CopyMemory(bmpData.Scan0, frame.pData, (uint)Math.Min(frame.frameInfo.size, (uint)(bmpData.Stride * bitmap.Height)));
|
|
bitmap.UnlockBits(bmpData);
|
return bitmap;
|
}
|
|
/// <summary>
|
/// 创建BGR8格式Bitmap
|
/// </summary>
|
private Bitmap CreateBgr8Bitmap(IMVDefine.IMV_Frame frame)
|
{
|
Bitmap bitmap = new Bitmap((int)frame.frameInfo.width, (int)frame.frameInfo.height, PixelFormat.Format24bppRgb);
|
|
BitmapData bmpData = bitmap.LockBits(
|
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
|
ImageLockMode.WriteOnly,
|
bitmap.PixelFormat);
|
|
// 使用CopyMemory API进行内存复制
|
CopyMemory(bmpData.Scan0, frame.pData, (uint)Math.Min(frame.frameInfo.size, (uint)(bmpData.Stride * bitmap.Height)));
|
|
bitmap.UnlockBits(bmpData);
|
return bitmap;
|
}
|
|
/// <summary>
|
/// 转换为BGR8格式
|
/// </summary>
|
private Bitmap ConvertToBGR8(IMVDefine.IMV_Frame frame)
|
{
|
IMVDefine.IMV_PixelConvertParam convertParam = new IMVDefine.IMV_PixelConvertParam
|
{
|
nWidth = frame.frameInfo.width,
|
nHeight = frame.frameInfo.height,
|
ePixelFormat = frame.frameInfo.pixelFormat,
|
pSrcData = frame.pData,
|
nSrcDataLen = frame.frameInfo.size,
|
nPaddingX = frame.frameInfo.paddingX,
|
nPaddingY = frame.frameInfo.paddingY,
|
eBayerDemosaic = IMVDefine.IMV_EBayerDemosaic.demosaicBilinear,
|
eDstPixelFormat = IMVDefine.IMV_EPixelType.gvspPixelBGR8,
|
nDstBufSize = frame.frameInfo.width * frame.frameInfo.height * 3
|
};
|
|
IntPtr dstBuffer = Marshal.AllocHGlobal((int)convertParam.nDstBufSize);
|
convertParam.pDstBuf = dstBuffer;
|
|
try
|
{
|
int result = _camera.IMV_PixelConvert(ref convertParam);
|
if (result == IMVDefine.IMV_OK)
|
{
|
return CreateBgr8BitmapFromBuffer(dstBuffer, frame.frameInfo.width, frame.frameInfo.height);
|
}
|
return null;
|
}
|
finally
|
{
|
Marshal.FreeHGlobal(dstBuffer);
|
}
|
}
|
|
/// <summary>
|
/// 从缓冲区创建BGR8 Bitmap
|
/// </summary>
|
private Bitmap CreateBgr8BitmapFromBuffer(IntPtr buffer, uint width, uint height)
|
{
|
Bitmap bitmap = new Bitmap((int)width, (int)height, PixelFormat.Format24bppRgb);
|
|
BitmapData bmpData = bitmap.LockBits(
|
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
|
ImageLockMode.WriteOnly,
|
bitmap.PixelFormat);
|
|
// 使用CopyMemory API进行安全的内存复制
|
CopyMemory(bmpData.Scan0, buffer, (uint)(width * height * 3));
|
|
bitmap.UnlockBits(bmpData);
|
return bitmap;
|
}
|
|
/// <summary>
|
/// 将触发源枚举转换为字符串
|
/// </summary>
|
private string GetTriggerSourceString(TriggerSource source)
|
{
|
return source switch
|
{
|
TriggerSource.Software => "Software",
|
TriggerSource.Line0 => "Line0",
|
TriggerSource.Line1 => "Line1",
|
TriggerSource.Line2 => "Line2",
|
TriggerSource.Line3 => "Line3",
|
TriggerSource.Line4 => "Line4",
|
TriggerSource.Line5 => "Line5",
|
_ => "Software"
|
};
|
}
|
|
/// <summary>
|
/// 将字符串转换为触发源枚举
|
/// </summary>
|
private TriggerSource GetTriggerSourceFromString(string source)
|
{
|
return source switch
|
{
|
"Software" => TriggerSource.Software,
|
"Line0" => TriggerSource.Line0,
|
"Line1" => TriggerSource.Line1,
|
"Line2" => TriggerSource.Line2,
|
"Line3" => TriggerSource.Line3,
|
"Line4" => TriggerSource.Line4,
|
"Line5" => TriggerSource.Line5,
|
_ => TriggerSource.Software
|
};
|
}
|
|
#endregion
|
|
#region 未实现的抽象方法(简化版实现)
|
|
public override bool SetTriggerPolarity(TriggerPolarity polarity)
|
{
|
// 华睿相机可能不支持该功能,返回成功
|
return true;
|
}
|
|
public override bool GetTriggerPolarity(out TriggerPolarity polarity)
|
{
|
polarity = TriggerPolarity.RisingEdge;
|
return true;
|
}
|
|
public override bool SetTriggerFliter(double flitertime)
|
{
|
// 暂不支持
|
return true;
|
}
|
|
public override bool GetTriggerFliter(out double flitertime)
|
{
|
flitertime = 0;
|
return true;
|
}
|
|
public override bool SetTriggerDelay(double delay)
|
{
|
// 暂不支持
|
return true;
|
}
|
|
public override bool GetTriggerDelay(out double delay)
|
{
|
delay = 0;
|
return true;
|
}
|
|
public override bool SetLineMode(IOLines line, LineMode mode)
|
{
|
// 暂不支持
|
return true;
|
}
|
|
public override bool SetLineStatus(IOLines line, LineStatus linestatus)
|
{
|
// 暂不支持
|
return true;
|
}
|
|
public override bool GetLineStatus(IOLines line, out LineStatus lineStatus)
|
{
|
lineStatus = LineStatus.Low;
|
return true;
|
}
|
|
public override bool AutoBalanceWhite()
|
{
|
// 暂不支持自动白平衡
|
return true;
|
}
|
|
#endregion
|
|
#region IDisposable实现
|
|
private bool _disposed = false;
|
|
protected virtual void Dispose(bool disposing)
|
{
|
if (!_disposed)
|
{
|
if (disposing)
|
{
|
// 释放托管资源
|
}
|
|
// 释放非托管资源
|
CloseDevice();
|
|
_disposed = true;
|
}
|
}
|
|
public override void Dispose()
|
{
|
Dispose(true);
|
GC.SuppressFinalize(this);
|
}
|
|
#endregion
|
}
|
}
|