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/BaseCamera.cs         |  126 +++----------------------
 LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs |   30 ++++++
 LB_VisionProcesses/Cameras/HRCameras/HRCamera.cs |  117 +++++++++++++++++++++++
 LB_VisionProcesses/Cameras/ICamera.cs            |    2 
 4 files changed, 163 insertions(+), 112 deletions(-)

diff --git a/LB_VisionProcesses/Cameras/BaseCamera.cs b/LB_VisionProcesses/Cameras/BaseCamera.cs
index 5f6db1d..4f9d877 100644
--- a/LB_VisionProcesses/Cameras/BaseCamera.cs
+++ b/LB_VisionProcesses/Cameras/BaseCamera.cs
@@ -14,7 +14,15 @@
         protected BaseCamera() { }
 
         #region Parm
+        /// <summary>
+        /// 鐩告満SN鍙�
+        /// </summary>
         public string SN { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 鐩告満鍚嶇О
+        /// </summary>
+        public string CameraName { get; set; } = string.Empty;
         public CameraBrand Brand { get; set; } = CameraBrand.UNSUPPORTED;
 
         public bool isGrabbing = false;
@@ -64,96 +72,24 @@
 
         public abstract bool InitDevice(string SN, object Handle = null);
 
-        public bool StartWith_SoftTriggerModel()
-        {
-            SetTriggerMode(TriggerMode.Off, TriggerSource.Software);
-            return StartGrabbing();
-        }
+        public abstract bool StartWith_SoftTriggerModel();
 
-        public bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0)
-        {
-            if (hardtriggeritem == TriggerSource.Software) hardtriggeritem = TriggerSource.Line0;
-            SetTriggerMode(TriggerMode.On, hardtriggeritem);
-            return StartGrabbing();
-        }
+        public abstract bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0);
 
         /// <summary>
-        /// 绛夊緟纭Е鍙戣幏鍙栧浘鍍�
+        /// 绛夊緟杞�/纭Е鍙戣幏鍙栧浘鍍�
         /// </summary>
         /// <param name="bitmap"></param>
         /// <param name="outtime"></param>
         /// <returns></returns>
-        public 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 abstract bool GetImage(out Bitmap bitmap, int outtime = 3000);
         /// <summary>
         /// 杞Е鍙戣幏鍙栧浘鍍�
         /// </summary>
         /// <param name="bitmap"></param>
         /// <param name="outtime"></param>
         /// <returns></returns>
-        public 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 abstract bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000);
 
         /// <summary>
         /// 杞Е鍙�
@@ -195,40 +131,8 @@
         #endregion
 
         #region SettingConfig
-        public 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 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 abstract void SetCamConfig(CameraConfig config);
+        public abstract void GetCamConfig(out CameraConfig config);
 
         /// <summary>
         /// 璁剧疆瑙﹀彂妯″紡鍙婅Е鍙戞簮
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
     }
 }
diff --git a/LB_VisionProcesses/Cameras/ICamera.cs b/LB_VisionProcesses/Cameras/ICamera.cs
index 055a5e5..e173d9c 100644
--- a/LB_VisionProcesses/Cameras/ICamera.cs
+++ b/LB_VisionProcesses/Cameras/ICamera.cs
@@ -63,7 +63,7 @@
         bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0);
 
         /// <summary>
-        /// 绛夊緟纭Е鍙戣幏鍙栧浘鍍�
+        /// 绛夊緟杞�/纭Е鍙戣幏鍙栧浘鍍�
         /// </summary>
         /// <param name="bitmap"></param>
         /// <param name="outtime"></param>
diff --git a/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs b/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
index 2bdc26b..b5ca44d 100644
--- a/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
+++ b/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
@@ -23,6 +23,11 @@
             return true;
         }
 
+        public override void GetCamConfig(out CameraConfig config)
+        {
+            throw new NotImplementedException();
+        }
+
         public override bool GetExpouseTime(out double value)
         {
             value = 0;
@@ -33,6 +38,16 @@
         {
             gain = 0;
             return true;
+        }
+
+        public override bool GetImage(out Bitmap bitmap, int outtime = 3000)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000)
+        {
+            throw new NotImplementedException();
         }
 
         public override bool GetLineStatus(IOLines line, out LineStatus lineStatus)
@@ -74,6 +89,11 @@
         public override bool InitDevice(string SN, object Handle = null)
         {
             return true;
+        }
+
+        public override void SetCamConfig(CameraConfig config)
+        {
+            throw new NotImplementedException();
         }
 
         public override bool SetExpouseTime(double value)
@@ -126,6 +146,16 @@
             return true;
         }
 
+        public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override bool StartWith_SoftTriggerModel()
+        {
+            throw new NotImplementedException();
+        }
+
         public override bool StopGrabbing()
         {
             return true;

--
Gitblit v1.9.3