From 2f5b39f83b584869e0a323f69ba5541db3fcaa75 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期四, 08 一月 2026 09:25:59 +0800
Subject: [PATCH] 重构BaseCamera基类相关相机的所有操作为abstract,2D/3D分别继承重载实现相应的操作即可。
---
LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 117 insertions(+), 0 deletions(-)
diff --git a/LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs b/LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
index 6aab716..48d15c7 100644
--- a/LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
+++ b/LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs
@@ -1130,6 +1130,123 @@
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);
+ }
+
#endregion
}
}
--
Gitblit v1.9.3