| | |
| | | using MVSDK_Net; |
| | | using HalconDotNet; |
| | | using LB_SmartVisionCommon; |
| | | using MVSDK_Net; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | |
| | | private Thread _callbackThread; // 回调处理线程 |
| | | private List<IMVDefine.IMV_Frame> _frameList; // 图像缓存列表 |
| | | private readonly object _frameLock = new object(); // 帧缓存锁 |
| | | private IMVDefine.IMV_EPixelType type = IMVDefine.IMV_EPixelType.gvspPixelMono8; |
| | | private IMVDefine.IMV_PixelConvertParam stPixelConvertParam = new IMVDefine.IMV_PixelConvertParam(); |
| | | |
| | | HObject Hobj = new HObject(); |
| | | IntPtr pTemp = IntPtr.Zero; |
| | | IntPtr pConvertDstBuffer = IntPtr.Zero; |
| | | int nConvertBufSize = 0; |
| | | |
| | | |
| | | private IMVDefine.IMV_FrameCallBack frameCallBack; |
| | | |
| | | // CopyMemory API声明 |
| | | [System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")] |
| | |
| | | { |
| | | // 记录日志或抛出异常 |
| | | //throw new Exception($"枚举设备失败,错误码:{result}"); |
| | | Debug.WriteLine("枚举设备失败!"); |
| | | AsyncLogHelper.Error("枚举设备失败!"); |
| | | System.Diagnostics.Debug.WriteLine("枚举设备失败!"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录错误日志 |
| | | System.Diagnostics.Debug.WriteLine($"获取相机列表失败:{ex.Message}"); |
| | | AsyncLogHelper.Error($"获取相机列表失败:{ex.Message}"); |
| | | throw; |
| | | } |
| | | |
| | |
| | | |
| | | if (cameraIndex == -1) |
| | | { |
| | | AsyncLogHelper.Error($"未找到序列号为 {SN} 的相机"); |
| | | throw new Exception($"未找到序列号为 {SN} 的相机"); |
| | | } |
| | | |
| | |
| | | int result = _camera.IMV_CreateHandle(IMVDefine.IMV_ECreateHandleMode.modeByIndex, cameraIndex); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | AsyncLogHelper.Error($"创建设备句柄失败,错误码:{result}"); |
| | | throw new Exception($"创建设备句柄失败,错误码:{result}"); |
| | | } |
| | | _handleCreated = true; |
| | |
| | | result = _camera.IMV_Open(); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | AsyncLogHelper.Error($"打开相机失败,错误码:{result}"); |
| | | throw new Exception($"打开相机失败,错误码:{result}"); |
| | | } |
| | | |
| | |
| | | this.SN = SN; |
| | | isGrabbing = false; |
| | | |
| | | // 设置缓存个数为8 |
| | | _camera.IMV_SetBufferCount(8); |
| | | // 注册数据帧回调函数 |
| | | // Register data frame callback function |
| | | frameCallBack = onGetFrame; |
| | | int res = _camera.IMV_AttachGrabbing(frameCallBack, IntPtr.Zero); |
| | | if (res != IMVDefine.IMV_OK) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine("Attach grabbing failed! ErrorCode:[{0}]", res); |
| | | AsyncLogHelper.Error("Attach grabbing failed! ErrorCode:[{0}]" + res); |
| | | } |
| | | // 设置缓存个数为12 |
| | | _camera.IMV_SetBufferCount(12); |
| | | |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"初始化相机失败:{ex.Message}"); |
| | | AsyncLogHelper.Error($"初始化相机失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | // 数据帧回调函数 |
| | | // Data frame callback function |
| | | private void onGetFrame(ref IMVDefine.IMV_Frame frame, IntPtr pUser) |
| | | { |
| | | if (frame.frameHandle == IntPtr.Zero) |
| | | { |
| | | AsyncLogHelper.Info(SN + "frame is NULL"); |
| | | return; |
| | | } |
| | | try |
| | | { |
| | | Bitmap bitmap = ConvertFrameToBitmap(frame); |
| | | |
| | | // 释放帧数据 |
| | | // release frame |
| | | _camera.IMV_ReleaseFrame(ref frame); |
| | | CallBackImg = (Bitmap)bitmap.Clone(); |
| | | if (CallBackImg == null) |
| | | { |
| | | return; |
| | | } |
| | | if (GetTriggerMode(out TriggerMode mode, out TriggerSource source)) |
| | | { |
| | | if (mode == TriggerMode.On && source != TriggerSource.Software) |
| | | TriggerRunMessageReceived?.Invoke(SN, source.ToString()); // 触发运行事件 |
| | | } |
| | | bitmap.Dispose(); |
| | | } |
| | | catch { } |
| | | AsyncLogHelper.Info(SN + "Get frame blockId = {0}" + frame.frameInfo.blockId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 图像是否为Mono格式 |
| | | /// </summary> |
| | | /// <param name="enType"></param> |
| | | /// <returns></returns> |
| | | private bool IsMonoPixelFormat(IMVDefine.IMV_EPixelType enType) |
| | | { |
| | | switch (enType) |
| | | { |
| | | case IMVDefine.IMV_EPixelType.gvspPixelMono8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelMono10: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelMono10Packed: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelMono12: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelMono12Packed: |
| | | return true; |
| | | default: |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 图像是否为彩色 |
| | | /// </summary> |
| | | /// <param name="enType"></param> |
| | | /// <returns></returns> |
| | | private bool IsColorPixelFormat(IMVDefine.IMV_EPixelType enType) |
| | | { |
| | | switch (enType) |
| | | { |
| | | case IMVDefine.IMV_EPixelType.gvspPixelRGB8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBGR8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelRGBA8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBGRA8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelYUV422_8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelYUV422_8_UYVY: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGR8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayRG8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGB8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayBG8: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGB10: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGB10Packed: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayBG10: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayBG10Packed: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayRG10: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayRG10Packed: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGR10: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGR10Packed: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGB12: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGB12Packed: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayBG12: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayBG12Packed: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayRG12: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayRG12Packed: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGR12: |
| | | case IMVDefine.IMV_EPixelType.gvspPixelBayGR12Packed: |
| | | return true; |
| | | default: |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 关闭相机设备 |
| | |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"关闭相机失败,错误码:{result}"); |
| | | AsyncLogHelper.Info(SN + $"关闭相机失败,错误码:{result}"); |
| | | } |
| | | } |
| | | |
| | |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"关闭相机失败:{ex.Message}"); |
| | | AsyncLogHelper.Info(SN + $"关闭相机失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (_camera == null || !_camera.IMV_IsOpen()) |
| | | { |
| | | throw new Exception("相机未打开"); |
| | | AsyncLogHelper.Error(SN + "相机未打开"); |
| | | throw new Exception(SN + "相机未打开"); |
| | | } |
| | | |
| | | // 停止现有采集 |
| | |
| | | int result = _camera.IMV_StartGrabbing(); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"启动采集失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"启动采集失败,错误码:{result}"); |
| | | throw new Exception(SN + $"启动采集失败,错误码:{result}"); |
| | | } |
| | | |
| | | _isGrabbing = true; |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"启动采集失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"启动采集失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"启动采集失败:{ex.Message}"); |
| | | _isGrabbing = false; |
| | | isGrabbing = false; |
| | | return false; |
| | |
| | | int result = _camera.IMV_StopGrabbing(); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"停止采集失败,错误码:{result}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"停止采集失败,错误码:{result}"); |
| | | AsyncLogHelper.Info(SN + $"停止采集失败,错误码:{result}"); |
| | | } |
| | | |
| | | _isGrabbing = false; |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"停止采集失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"停止采集失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"停止采集失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (_camera == null || !_camera.IMV_IsOpen()) |
| | | { |
| | | throw new Exception("相机未打开"); |
| | | AsyncLogHelper.Error(SN + "相机未打开"); |
| | | throw new Exception(SN + "相机未打开"); |
| | | } |
| | | |
| | | int result = _camera.IMV_ExecuteCommandFeature("TriggerSoftware"); |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"软触发失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"软触发失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"软触发失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (_camera == null || !_camera.IMV_IsOpen()) |
| | | { |
| | | throw new Exception("相机未打开"); |
| | | AsyncLogHelper.Error(SN + "相机未打开"); |
| | | throw new Exception(SN + "相机未打开"); |
| | | } |
| | | |
| | | // 设置触发模式 |
| | |
| | | int result = _camera.IMV_SetEnumFeatureSymbol("TriggerMode", triggerMode); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"设置触发模式失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"设置触发模式失败,错误码:{result}"); |
| | | throw new Exception(SN + $"设置触发模式失败,错误码:{result}"); |
| | | } |
| | | |
| | | // 设置触发源 |
| | |
| | | result = _camera.IMV_SetEnumFeatureSymbol("TriggerSource", triggerSource); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"设置触发源失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"设置触发源失败,错误码:{result}"); |
| | | throw new Exception(SN + $"设置触发源失败,错误码:{result}"); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"设置触发模式失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"设置触发模式失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"设置触发模式失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (_camera == null || !_camera.IMV_IsOpen()) |
| | | { |
| | | throw new Exception("相机未打开"); |
| | | AsyncLogHelper.Error(SN + "相机未打开"); |
| | | throw new Exception(SN + "相机未打开"); |
| | | } |
| | | |
| | | // 获取触发模式 |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"获取触发模式失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"获取触发模式失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"获取触发模式失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (_camera == null || !_camera.IMV_IsOpen()) |
| | | { |
| | | throw new Exception("相机未打开"); |
| | | AsyncLogHelper.Error(SN + "相机未打开"); |
| | | throw new Exception(SN + "相机未打开"); |
| | | } |
| | | |
| | | // 验证曝光时间范围 |
| | |
| | | int result = _camera.IMV_GetDoubleFeatureMin("ExposureTime", ref minExp); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"获取曝光时间最小值失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"获取曝光时间最小值失败,错误码:{result}"); |
| | | throw new Exception(SN + $"获取曝光时间最小值失败,错误码:{result}"); |
| | | } |
| | | |
| | | result = _camera.IMV_GetDoubleFeatureMax("ExposureTime", ref maxExp); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"获取曝光时间最大值失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"获取曝光时间最大值失败,错误码:{result}"); |
| | | throw new Exception(SN + $"获取曝光时间最大值失败,错误码:{result}"); |
| | | } |
| | | |
| | | if (value < minExp || value > maxExp) |
| | | { |
| | | throw new Exception($"曝光时间超出范围,有效范围:{minExp} - {maxExp}"); |
| | | AsyncLogHelper.Error(SN + $"曝光时间超出范围,有效范围:{minExp} - {maxExp}"); |
| | | throw new Exception(SN + $"曝光时间超出范围,有效范围:{minExp} - {maxExp}"); |
| | | } |
| | | |
| | | // 设置曝光时间 |
| | | result = _camera.IMV_SetDoubleFeatureValue("ExposureTime", value); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"设置曝光时间失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"设置曝光时间失败,错误码:{result}"); |
| | | throw new Exception(SN + $"设置曝光时间失败,错误码:{result}"); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"设置曝光时间失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"设置曝光时间失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"设置曝光时间失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (_camera == null || !_camera.IMV_IsOpen()) |
| | | { |
| | | throw new Exception("相机未打开"); |
| | | AsyncLogHelper.Error(SN + "相机未打开"); |
| | | throw new Exception(SN + "相机未打开"); |
| | | } |
| | | |
| | | int result = _camera.IMV_GetDoubleFeatureValue("ExposureTime", ref value); |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"获取曝光时间失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"获取曝光时间失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"获取曝光时间失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (_camera == null || !_camera.IMV_IsOpen()) |
| | | { |
| | | throw new Exception("相机未打开"); |
| | | AsyncLogHelper.Error(SN + "相机未打开"); |
| | | throw new Exception(SN + "相机未打开"); |
| | | } |
| | | |
| | | string gainFeature = _camera.IMV_FeatureIsValid("Gain") ? "Gain" : "GainRaw"; |
| | |
| | | int result = _camera.IMV_GetDoubleFeatureMin(gainFeature, ref minGain); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"获取增益最小值失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"获取增益最小值失败,错误码:{result}"); |
| | | throw new Exception(SN + $"获取增益最小值失败,错误码:{result}"); |
| | | } |
| | | |
| | | result = _camera.IMV_GetDoubleFeatureMax(gainFeature, ref maxGain); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"获取增益最大值失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"获取增益最大值失败,错误码:{result}"); |
| | | throw new Exception(SN + $"获取增益最大值失败,错误码:{result}"); |
| | | } |
| | | |
| | | if (gain < minGain) gain = minGain; |
| | |
| | | result = _camera.IMV_SetDoubleFeatureValue(gainFeature, gain); |
| | | if (result != IMVDefine.IMV_OK) |
| | | { |
| | | throw new Exception($"设置增益失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"设置增益失败,错误码:{result}"); |
| | | throw new Exception(SN + $"设置增益失败,错误码:{result}"); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"设置增益失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"设置增益失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"设置增益失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | if (_camera == null || !_camera.IMV_IsOpen()) |
| | | { |
| | | throw new Exception("相机未打开"); |
| | | AsyncLogHelper.Error(SN + "相机未打开"); |
| | | throw new Exception(SN + "相机未打开"); |
| | | } |
| | | |
| | | string gainFeature = _camera.IMV_FeatureIsValid("Gain") ? "Gain" : "GainRaw"; |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"获取增益失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"获取增益失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"获取增益失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"设置触发极性失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"设置触发极性失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"设置触发极性失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"获取触发极性失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"获取触发极性失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"获取触发极性失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"设置触发滤波失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"设置触发滤波失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"设置触发滤波失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"获取触发滤波失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"获取触发滤波失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"获取触发滤波失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"设置触发延时失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"设置触发延时失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"设置触发延时失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"获取触发延时失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"获取触发延时失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"获取触发延时失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"设置信号线模式失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"设置信号线模式失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"设置信号线模式失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"设置信号线状态失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"设置信号线状态失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"设置信号线状态失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"获取信号线状态失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"获取信号线状态失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"获取信号线状态失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"自动白平衡失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"自动白平衡失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"自动白平衡失败:{ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | if ((uint)result != 0x80000001 && result != -119 && result != -102) // 超时错误代码 |
| | | { |
| | | // 非超时错误 |
| | | System.Diagnostics.Debug.WriteLine($"获取图像帧失败,错误码:{result}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"获取图像帧失败,错误码:{result}"); |
| | | AsyncLogHelper.Error(SN + $"获取图像帧失败,错误码:{result}"); |
| | | Thread.Sleep(10); // 出错时稍作等待 |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"采集线程异常:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"采集线程异常:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"采集线程异常:{ex.Message}"); |
| | | Thread.Sleep(10); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"处理图像帧失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"处理图像帧失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"处理图像帧失败:{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Diagnostics.Debug.WriteLine($"图像格式转换失败:{ex.Message}"); |
| | | System.Diagnostics.Debug.WriteLine(SN + $"图像格式转换失败:{ex.Message}"); |
| | | AsyncLogHelper.Error(SN + $"图像格式转换失败:{ex.Message}"); |
| | | return null; |
| | | } |
| | | } |