From 68a4b459eeb18effb8b3096add3d88c15629ab69 Mon Sep 17 00:00:00 2001
From: C3032 <1057644574@qq.com>
Date: 星期一, 23 三月 2026 11:01:16 +0800
Subject: [PATCH] 修复了 master 分支中的编译错误
---
LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs | 489 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 443 insertions(+), 46 deletions(-)
diff --git a/LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs b/LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
index 6aab716..f176eab 100644
--- a/LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
+++ b/LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
@@ -1,4 +1,7 @@
-锘縰sing MVSDK_Net;
+锘縰sing HalconDotNet;
+using LB_SmartVisionCommon;
+using LB_VisionProcesses.Cameras.LBCameras;
+using MVSDK_Net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -26,6 +29,18 @@
private Thread _callbackThread; // 鍥炶皟澶勭悊绾跨▼
private List<IMVDefine.IMV_Frame> _frameList; // 鍥惧儚缂撳瓨鍒楄〃
private readonly object _frameLock = new object(); // 甯х紦瀛橀攣
+ // 鏂板锛欳ollectedImages鎿嶄綔閿侊紝淇濊瘉绾跨▼瀹夊叏
+ private readonly object _collectedImagesLock = 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")]
@@ -92,13 +107,15 @@
{
// 璁板綍鏃ュ織鎴栨姏鍑哄紓甯�
//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;
}
@@ -145,6 +162,7 @@
if (cameraIndex == -1)
{
+ AsyncLogHelper.Error($"鏈壘鍒板簭鍒楀彿涓� {SN} 鐨勭浉鏈�");
throw new Exception($"鏈壘鍒板簭鍒楀彿涓� {SN} 鐨勭浉鏈�");
}
@@ -152,6 +170,7 @@
int result = _camera.IMV_CreateHandle(IMVDefine.IMV_ECreateHandleMode.modeByIndex, cameraIndex);
if (result != IMVDefine.IMV_OK)
{
+ AsyncLogHelper.Error($"鍒涘缓璁惧鍙ユ焺澶辫触锛岄敊璇爜锛歿result}");
throw new Exception($"鍒涘缓璁惧鍙ユ焺澶辫触锛岄敊璇爜锛歿result}");
}
_handleCreated = true;
@@ -160,6 +179,7 @@
result = _camera.IMV_Open();
if (result != IMVDefine.IMV_OK)
{
+ AsyncLogHelper.Error($"鎵撳紑鐩告満澶辫触锛岄敊璇爜锛歿result}");
throw new Exception($"鎵撳紑鐩告満澶辫触锛岄敊璇爜锛歿result}");
}
@@ -167,17 +187,228 @@
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
+ {
+ // 1. 灏嗗抚杞崲涓築itmap
+ Bitmap bitmap = ConvertFrameToBitmap(frame);
+ // 閲婃斁鍘熷甯ф暟鎹紙SDK灞傞潰閲婃斁锛�
+ _camera.IMV_ReleaseFrame(ref frame);
+
+ // 2. 绌哄�兼牎楠岋細杞崲澶辫触鍒欑洿鎺ヨ繑鍥�
+ if (bitmap == null)
+ {
+ AsyncLogHelper.Warn(SN + "甯ц浆鎹负Bitmap澶辫触锛岃烦杩囧鐞�");
+ return;
+ }
+ // 3. 绾跨▼瀹夊叏鍦板皢Bitmap娣诲姞鍒癈ollectedImages瀛楀吀
+ lock (_collectedImagesLock)
+ {
+ // 纭繚褰撳墠鐩告満SN瀵瑰簲鐨勫垪琛ㄥ瓨鍦�
+ if (!CollectedImages.ContainsKey(SN))
+ {
+ CollectedImages[SN] = new List<Bitmap>();
+ }
+ CollectedImages[SN].Add(bitmap);
+ AsyncLogHelper.Info(SN + $"鍥惧儚宸插姞鍏ョ紦瀛橈紝褰撳墠缂撳瓨鏁伴噺锛歿CollectedImages[SN].Count}");
+ }
+
+ // 4. 澶勭悊CollectedImages涓殑鍥惧儚锛氶亶鍘嗘秷璐瑰垪琛ㄧ涓�涓厓绱犵洿鍒颁负绌�
+ ProcessCollectedImages();
+ //Task.Factory.StartNew(() =>
+ //{
+ // 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>
+ /// 澶勭悊CollectedImages涓殑缂撳瓨鍥惧儚
+ /// 鏍稿績閫昏緫锛氶亶鍘嗗彇绗竴涓浘鍍� -> 璧嬪�肩粰CallBackImg -> 瑙﹀彂浜嬩欢 -> 閲婃斁骞剁Щ闄�
+ /// </summary>
+ private void ProcessCollectedImages()
+ {
+ Task.Factory.StartNew(() =>
+ {
+ // 鍔犻攣淇濊瘉绾跨▼瀹夊叏锛岄槻姝㈠绾跨▼鍚屾椂鎿嶄綔鍒楄〃
+ lock (_collectedImagesLock)
+ {
+ // 鏍¢獙褰撳墠鐩告満鐨勫浘鍍忓垪琛ㄦ槸鍚﹀瓨鍦ㄤ笖鏈夋暟鎹�
+ if (!CollectedImages.ContainsKey(SN) || CollectedImages[SN].Count == 0)
+ {
+ AsyncLogHelper.Info(SN + "褰撳墠鏃犵紦瀛樺浘鍍忥紝璺宠繃澶勭悊");
+ return;
+ }
+ // 寰幆澶勭悊锛氱洿鍒板垪琛ㄤ负绌�
+ while (CollectedImages[SN].Count > 0)
+ {
+ try
+ {
+ // 1 鍙栧垪琛ㄧ涓�涓储寮曠殑鍥惧儚璧嬪�肩粰CallBackImg
+ Bitmap firstBitmap = CollectedImages[SN][0];
+ ImageGrabbed?.Invoke(this, new LBCameraEventArgs(SN, firstBitmap, true));
+ CallBackImg = (Bitmap)firstBitmap.Clone(); // 鍏嬮殕閬垮厤鍘熷璞¤閲婃斁鍚庡紩鐢ㄥけ鏁�
+
+ // 2 鑾峰彇瑙﹀彂妯″紡骞跺垽鏂槸鍚﹁Е鍙戣繍琛屼簨浠�
+ if (GetTriggerMode(out TriggerMode mode, out TriggerSource source))
+ {
+ // 纭Е鍙戞ā寮忎笅瑙﹀彂杩愯浜嬩欢
+ if (mode == TriggerMode.On && source != TriggerSource.Software)
+ {
+ AsyncLogHelper.Info(SN + $"瑙﹀彂纭Е鍙戜簨浠讹紝瑙﹀彂婧愶細{source}");
+ TriggerRunMessageReceived?.Invoke(SN, source.ToString());
+ }
+ }
+ else
+ {
+ AsyncLogHelper.Warn(SN + "鑾峰彇瑙﹀彂妯″紡澶辫触锛岃烦杩囦簨浠惰Е鍙�");
+ }
+
+ // 3 閲婃斁绗竴涓浘鍍忚祫婧愬苟浠庡垪琛ㄧЩ闄�
+ // 鍏堥噴鏀綛itmap鍐呭瓨锛屽啀绉婚櫎鍒楄〃鍏冪礌
+ firstBitmap.Dispose();
+ CollectedImages[SN].RemoveAt(0);
+ AsyncLogHelper.Info(SN + $"宸叉秷璐圭紦瀛樺浘鍍忥紝鍓╀綑缂撳瓨鏁伴噺锛歿CollectedImages[SN].Count}");
+ }
+ catch (Exception ex)
+ {
+ AsyncLogHelper.Error(SN + $"澶勭悊缂撳瓨鍥惧儚寮傚父锛歿ex.Message}", ex);
+ // 鍗曚釜鍥惧儚澶勭悊澶辫触鏃讹紝绉婚櫎璇ュ浘鍍忛伩鍏嶉樆濉炲悗缁鐞�
+ if (CollectedImages[SN].Count > 0)
+ {
+ try
+ {
+ CollectedImages[SN][0]?.Dispose(); // 灏濊瘯閲婃斁
+ CollectedImages[SN].RemoveAt(0);
+ }
+ catch (Exception innerEx)
+ {
+ AsyncLogHelper.Error(SN + $"娓呯悊寮傚父鍥惧儚澶辫触锛歿innerEx.Message}", innerEx);
+ }
+ }
+ // 鍗曚釜鍥惧儚澶勭悊澶辫触涓嶇粓姝㈠惊鐜紝缁х画澶勭悊涓嬩竴涓�
+ // 4. 鎵�鏈夊浘鍍忓鐞嗗畬鎴愬悗锛屾竻绌篊allBackImg
+ if (CallBackImg != null)
+ {
+ CallBackImg.Dispose();
+ CallBackImg = null;
+ }
+ continue;
+ }
+ // 4. 鎵�鏈夊浘鍍忓鐞嗗畬鎴愬悗锛屾竻绌篊allBackImg
+ if (CallBackImg != null)
+ {
+ CallBackImg.Dispose();
+ CallBackImg = null;
+ }
+ }
+ }
+ });
+ }
+
+ /// <summary>
+ /// 鍥惧儚鏄惁涓篗ono鏍煎紡
+ /// </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>
/// 鍏抽棴鐩告満璁惧
@@ -203,6 +434,7 @@
if (result != IMVDefine.IMV_OK)
{
System.Diagnostics.Debug.WriteLine($"鍏抽棴鐩告満澶辫触锛岄敊璇爜锛歿result}");
+ AsyncLogHelper.Info(SN + $"鍏抽棴鐩告満澶辫触锛岄敊璇爜锛歿result}");
}
}
@@ -233,6 +465,7 @@
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"鍏抽棴鐩告満澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Info(SN + $"鍏抽棴鐩告満澶辫触锛歿ex.Message}");
return false;
}
}
@@ -251,7 +484,8 @@
{
if (_camera == null || !_camera.IMV_IsOpen())
{
- throw new Exception("鐩告満鏈墦寮�");
+ AsyncLogHelper.Error(SN + "鐩告満鏈墦寮�");
+ throw new Exception(SN + "鐩告満鏈墦寮�");
}
// 鍋滄鐜版湁閲囬泦
@@ -264,7 +498,8 @@
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;
@@ -280,7 +515,8 @@
}
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;
@@ -310,7 +546,8 @@
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;
@@ -331,7 +568,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鍋滄閲囬泦澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鍋滄閲囬泦澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"鍋滄閲囬泦澶辫触锛歿ex.Message}");
return false;
}
}
@@ -346,7 +584,8 @@
{
if (_camera == null || !_camera.IMV_IsOpen())
{
- throw new Exception("鐩告満鏈墦寮�");
+ AsyncLogHelper.Error(SN + "鐩告満鏈墦寮�");
+ throw new Exception(SN + "鐩告満鏈墦寮�");
}
int result = _camera.IMV_ExecuteCommandFeature("TriggerSoftware");
@@ -354,7 +593,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"杞Е鍙戝け璐ワ細{ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"杞Е鍙戝け璐ワ細{ex.Message}");
+ AsyncLogHelper.Error(SN + $"杞Е鍙戝け璐ワ細{ex.Message}");
return false;
}
}
@@ -375,7 +615,8 @@
{
if (_camera == null || !_camera.IMV_IsOpen())
{
- throw new Exception("鐩告満鏈墦寮�");
+ AsyncLogHelper.Error(SN + "鐩告満鏈墦寮�");
+ throw new Exception(SN + "鐩告満鏈墦寮�");
}
// 璁剧疆瑙﹀彂妯″紡
@@ -383,7 +624,8 @@
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}");
}
// 璁剧疆瑙﹀彂婧�
@@ -393,7 +635,8 @@
result = _camera.IMV_SetEnumFeatureSymbol("TriggerSource", triggerSource);
if (result != IMVDefine.IMV_OK)
{
- throw new Exception($"璁剧疆瑙﹀彂婧愬け璐ワ紝閿欒鐮侊細{result}");
+ AsyncLogHelper.Error(SN + $"璁剧疆瑙﹀彂婧愬け璐ワ紝閿欒鐮侊細{result}");
+ throw new Exception(SN + $"璁剧疆瑙﹀彂婧愬け璐ワ紝閿欒鐮侊細{result}");
}
}
@@ -401,7 +644,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"璁剧疆瑙﹀彂妯″紡澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"璁剧疆瑙﹀彂妯″紡澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"璁剧疆瑙﹀彂妯″紡澶辫触锛歿ex.Message}");
return false;
}
}
@@ -421,7 +665,8 @@
{
if (_camera == null || !_camera.IMV_IsOpen())
{
- throw new Exception("鐩告満鏈墦寮�");
+ AsyncLogHelper.Error(SN + "鐩告満鏈墦寮�");
+ throw new Exception(SN + "鐩告満鏈墦寮�");
}
// 鑾峰彇瑙﹀彂妯″紡
@@ -444,7 +689,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鑾峰彇瑙﹀彂妯″紡澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鑾峰彇瑙﹀彂妯″紡澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"鑾峰彇瑙﹀彂妯″紡澶辫触锛歿ex.Message}");
return false;
}
}
@@ -460,7 +706,8 @@
{
if (_camera == null || !_camera.IMV_IsOpen())
{
- throw new Exception("鐩告満鏈墦寮�");
+ AsyncLogHelper.Error(SN + "鐩告満鏈墦寮�");
+ throw new Exception(SN + "鐩告満鏈墦寮�");
}
// 楠岃瘉鏇濆厜鏃堕棿鑼冨洿
@@ -468,32 +715,37 @@
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;
}
}
@@ -511,7 +763,8 @@
{
if (_camera == null || !_camera.IMV_IsOpen())
{
- throw new Exception("鐩告満鏈墦寮�");
+ AsyncLogHelper.Error(SN + "鐩告満鏈墦寮�");
+ throw new Exception(SN + "鐩告満鏈墦寮�");
}
int result = _camera.IMV_GetDoubleFeatureValue("ExposureTime", ref value);
@@ -519,7 +772,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鑾峰彇鏇濆厜鏃堕棿澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鑾峰彇鏇濆厜鏃堕棿澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"鑾峰彇鏇濆厜鏃堕棿澶辫触锛歿ex.Message}");
return false;
}
}
@@ -535,7 +789,8 @@
{
if (_camera == null || !_camera.IMV_IsOpen())
{
- throw new Exception("鐩告満鏈墦寮�");
+ AsyncLogHelper.Error(SN + "鐩告満鏈墦寮�");
+ throw new Exception(SN + "鐩告満鏈墦寮�");
}
string gainFeature = _camera.IMV_FeatureIsValid("Gain") ? "Gain" : "GainRaw";
@@ -545,13 +800,15 @@
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;
@@ -561,14 +818,16 @@
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;
}
}
@@ -586,7 +845,8 @@
{
if (_camera == null || !_camera.IMV_IsOpen())
{
- throw new Exception("鐩告満鏈墦寮�");
+ AsyncLogHelper.Error(SN + "鐩告満鏈墦寮�");
+ throw new Exception(SN + "鐩告満鏈墦寮�");
}
string gainFeature = _camera.IMV_FeatureIsValid("Gain") ? "Gain" : "GainRaw";
@@ -595,7 +855,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鑾峰彇澧炵泭澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鑾峰彇澧炵泭澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"鑾峰彇澧炵泭澶辫触锛歿ex.Message}");
return false;
}
}
@@ -619,7 +880,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"璁剧疆瑙﹀彂鏋佹�уけ璐ワ細{ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"璁剧疆瑙﹀彂鏋佹�уけ璐ワ細{ex.Message}");
+ AsyncLogHelper.Error(SN + $"璁剧疆瑙﹀彂鏋佹�уけ璐ワ細{ex.Message}");
return false;
}
}
@@ -647,7 +909,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鑾峰彇瑙﹀彂鏋佹�уけ璐ワ細{ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鑾峰彇瑙﹀彂鏋佹�уけ璐ワ細{ex.Message}");
+ AsyncLogHelper.Error(SN + $"鑾峰彇瑙﹀彂鏋佹�уけ璐ワ細{ex.Message}");
return false;
}
}
@@ -671,7 +934,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"璁剧疆瑙﹀彂婊ゆ尝澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"璁剧疆瑙﹀彂婊ゆ尝澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"璁剧疆瑙﹀彂婊ゆ尝澶辫触锛歿ex.Message}");
return false;
}
}
@@ -695,7 +959,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鑾峰彇瑙﹀彂婊ゆ尝澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鑾峰彇瑙﹀彂婊ゆ尝澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"鑾峰彇瑙﹀彂婊ゆ尝澶辫触锛歿ex.Message}");
return false;
}
}
@@ -718,7 +983,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"璁剧疆瑙﹀彂寤舵椂澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"璁剧疆瑙﹀彂寤舵椂澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"璁剧疆瑙﹀彂寤舵椂澶辫触锛歿ex.Message}");
return false;
}
}
@@ -742,7 +1008,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鑾峰彇瑙﹀彂寤舵椂澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鑾峰彇瑙﹀彂寤舵椂澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"鑾峰彇瑙﹀彂寤舵椂澶辫触锛歿ex.Message}");
return false;
}
}
@@ -767,7 +1034,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"璁剧疆淇″彿绾挎ā寮忓け璐ワ細{ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"璁剧疆淇″彿绾挎ā寮忓け璐ワ細{ex.Message}");
+ AsyncLogHelper.Error(SN + $"璁剧疆淇″彿绾挎ā寮忓け璐ワ細{ex.Message}");
return false;
}
}
@@ -791,7 +1059,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"璁剧疆淇″彿绾跨姸鎬佸け璐ワ細{ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"璁剧疆淇″彿绾跨姸鎬佸け璐ワ細{ex.Message}");
+ AsyncLogHelper.Error(SN + $"璁剧疆淇″彿绾跨姸鎬佸け璐ワ細{ex.Message}");
return false;
}
}
@@ -820,7 +1089,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鑾峰彇淇″彿绾跨姸鎬佸け璐ワ細{ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鑾峰彇淇″彿绾跨姸鎬佸け璐ワ細{ex.Message}");
+ AsyncLogHelper.Error(SN + $"鑾峰彇淇″彿绾跨姸鎬佸け璐ワ細{ex.Message}");
return false;
}
}
@@ -843,7 +1113,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鑷姩鐧藉钩琛″け璐ワ細{ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鑷姩鐧藉钩琛″け璐ワ細{ex.Message}");
+ AsyncLogHelper.Error(SN + $"鑷姩鐧藉钩琛″け璐ワ細{ex.Message}");
return false;
}
}
@@ -880,14 +1151,16 @@
if ((uint)result != 0x80000001 && result != -119 && result != -102) // 瓒呮椂閿欒浠g爜
{
// 闈炶秴鏃堕敊璇�
- 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);
}
@@ -918,7 +1191,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"澶勭悊鍥惧儚甯уけ璐ワ細{ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"澶勭悊鍥惧儚甯уけ璐ワ細{ex.Message}");
+ AsyncLogHelper.Error(SN + $"澶勭悊鍥惧儚甯уけ璐ワ細{ex.Message}");
}
finally
{
@@ -957,7 +1231,8 @@
}
catch (Exception ex)
{
- System.Diagnostics.Debug.WriteLine($"鍥惧儚鏍煎紡杞崲澶辫触锛歿ex.Message}");
+ System.Diagnostics.Debug.WriteLine(SN + $"鍥惧儚鏍煎紡杞崲澶辫触锛歿ex.Message}");
+ AsyncLogHelper.Error(SN + $"鍥惧儚鏍煎紡杞崲澶辫触锛歿ex.Message}");
return null;
}
}
@@ -1130,6 +1405,128 @@
GC.SuppressFinalize(this);
}
+ public override bool StartWith_SoftTriggerModel()
+ {
+ SetTriggerMode(TriggerMode.Off, TriggerSource.Software);
+ return StartGrabbing();
+ }
+
+
+ public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0)
+ {
+ if (hardtriggeritem == TriggerSource.Software) hardtriggeritem = TriggerSource.Line0;
+ SetTriggerMode(TriggerMode.On, hardtriggeritem);
+ return StartGrabbing();
+ }
+
+ public override bool GetImage(out Bitmap bitmap, int outtime = 3000)
+ {
+ bitmap = null;
+
+ try
+ {
+ // 璁剧疆瓒呮椂鏃堕棿
+ DateTime lastTime = DateTime.Now.AddMilliseconds(outtime);
+ // 鍒ゆ柇鏄惁瓒呮椂
+ while (lastTime > DateTime.Now)// 璁剧疆瓒呮椂鏃堕棿涓� 3 绉�
+ {
+ if (CallBackImg != null)
+ {
+ lock (CallBackImg)
+ {
+ // 淇濆瓨鏃� Bitmap 骞堕噴鏀�
+ bitmap = CallBackImg.Clone() as Bitmap; // 鍒涘缓鍓湰
+ }
+
+ // 閲婃斁鏃ц祫婧�
+ CallBackImg.Dispose();
+ CallBackImg = null;
+ return true;
+ }
+ }
+
+ return false;
+ }
+ catch { return bitmap == null ? false : true; }
+ }
+
+
+ public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000)
+ {
+ if (!isGrabbing)
+ StartGrabbing();
+
+ GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource);
+
+ if (triggerMode != TriggerMode.On && triggerSource != TriggerSource.Software)
+ SetTriggerMode(TriggerMode.On, TriggerSource.Software);
+
+ bitmap = null;
+ CallBackImg = null;
+
+ if (!SoftTrigger())
+ return false;
+
+ // 寮�濮嬫椂闂�
+ DateTime startTime = DateTime.Now; // 褰撳墠鏃堕棿
+
+ // 鍒ゆ柇鏄惁瓒呮椂
+ while (DateTime.Now < startTime.AddMilliseconds(outtime))// 璁剧疆瓒呮椂鏃堕棿涓� 3 绉�
+ {
+ GetImage(out bitmap, 50);
+ if (bitmap != null)
+ break;
+
+ Thread.Sleep(10);
+ }
+
+ if (triggerMode != TriggerMode.On)
+ SetTriggerMode(TriggerMode.On, triggerSource);
+
+ return (bitmap != null);
+ }
+
+ public override void SetCamConfig(CameraConfig config)
+ {
+ if (Enum.TryParse(config.Params.Inputs["瑙﹀彂妯″紡"].ToString(), out TriggerMode TriggerMode)
+ && Enum.TryParse(config.Params.Inputs["瑙﹀彂鏂瑰紡"].ToString(), out TriggerSource TriggerSource)
+ && Enum.TryParse(config.Params.Inputs["瑙﹀彂鏋佹��"].ToString(), out TriggerPolarity TriggerPolarity)
+ )
+ {
+ SetTriggerMode(TriggerMode, TriggerSource);
+ SetTriggerPolarity(TriggerPolarity);
+ SetTriggerFliter(Convert.ToDouble(config.Params.Inputs["瑙﹀彂娑堟姈"].ToString()));
+ SetTriggerDelay(Convert.ToDouble(config.Params.Inputs["瑙﹀彂寤舵椂"].ToString()));
+ SetExpouseTime(Convert.ToDouble(config.Params.Inputs["鏇濆厜鏃堕棿"].ToString()));
+ SetGain(Convert.ToDouble(config.Params.Inputs["澧炵泭"].ToString()));
+ }
+ }
+
+
+ public override void GetCamConfig(out CameraConfig config)
+ {
+ GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource);
+ GetTriggerPolarity(out TriggerPolarity triggerPolarity);
+ GetTriggerFliter(out double triggerfilter);
+ GetTriggerDelay(out double triggerdelay);
+ GetExpouseTime(out double expouseTime);
+ GetGain(out double gain);
+
+ config = new CameraConfig(null);
+ config.Params.Inputs.Add("瑙﹀彂妯″紡", triggerMode);
+ config.Params.Inputs.Add("瑙﹀彂鏂瑰紡", triggerSource);
+ config.Params.Inputs.Add("瑙﹀彂鏋佹��", triggerPolarity);
+ config.Params.Inputs.Add("瑙﹀彂娑堟姈", triggerfilter);
+ config.Params.Inputs.Add("瑙﹀彂寤舵椂", triggerdelay);
+ config.Params.Inputs.Add("鏇濆厜鏃堕棿", expouseTime);
+ config.Params.Inputs.Add("澧炵泭", gain);
+ }
+
+ public override bool StartContinuousGrab()
+ {
+ return true;
+ }
+
#endregion
}
}
--
Gitblit v1.9.3