From a0c982ba8abdbd7569a6cae07812127a757fd410 Mon Sep 17 00:00:00 2001
From: C3032 <C3032@BC3032>
Date: 星期三, 07 一月 2026 16:02:34 +0800
Subject: [PATCH] 更新相机实例化和UI线程处理逻辑

---
 LB_SmartVision/VisionForm.cs                     |    2 +-
 LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs |   30 +++++++++++++++---------------
 LB_VisionProcesses/Cameras/2DCameraForm.cs       |   21 ++++++++++-----------
 3 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/LB_SmartVision/VisionForm.cs b/LB_SmartVision/VisionForm.cs
index 6bf83db..58c8f0e 100644
--- a/LB_SmartVision/VisionForm.cs
+++ b/LB_SmartVision/VisionForm.cs
@@ -688,7 +688,7 @@
                         }
                     case CameraBrand.LBCamera:
                         {
-                            //camera = new LBCamera();
+                            camera = new LBCamera();
                             break;
                         }
                     default:
diff --git a/LB_VisionProcesses/Cameras/2DCameraForm.cs b/LB_VisionProcesses/Cameras/2DCameraForm.cs
index 3d9057a..9558b6e 100644
--- a/LB_VisionProcesses/Cameras/2DCameraForm.cs
+++ b/LB_VisionProcesses/Cameras/2DCameraForm.cs
@@ -390,21 +390,20 @@
             if (e.Bitmap == null)
                 return;
 
-            lock (e.Bitmap)
-            {
-                if (this.InvokeRequired) // 妫�鏌ユ槸鍚﹂渶瑕佸湪UI绾跨▼涓婅皟鐢�
+                lock (e.Bitmap)
                 {
-                    this.Invoke(new Action(() =>
+                    if (this.InvokeRequired) // 妫�鏌ユ槸鍚﹂渶瑕佸湪UI绾跨▼涓婅皟鐢�
+                    {
+                        this.Invoke(new Action(() =>
+                        {
+                            onlinePictureBox.Image = e.Bitmap;
+                        })); // 閫掑綊璋冪敤鑷韩锛屼絾杩欐鍦║I绾跨▼涓�
+                    }
+                    else
                     {
                         onlinePictureBox.Image = e.Bitmap;
-                    })); // 閫掑綊璋冪敤鑷韩锛屼絾杩欐鍦║I绾跨▼涓�
+                    }
                 }
-                else
-                {
-                    onlinePictureBox.Image = e.Bitmap;
-                }
-            }
-
             total.iImageCount++;
             try
             {
diff --git a/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs b/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
index a7c409b..a856458 100644
--- a/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
+++ b/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
@@ -266,27 +266,27 @@
 
         private void OnLineReceived(IntPtr pInstance, IntPtr buffer, int points)
         {
-            // 瀹炴椂鍥炶皟澶勭悊锛氱疮绉鏁版嵁
-            if (!isGrabbing) return;
+                // 瀹炴椂鍥炶皟澶勭悊锛氱疮绉鏁版嵁
+                if (!isGrabbing) return;
 
-            int lineSize = points * Marshal.SizeOf(typeof(LBPointZA));
-            byte[] lineData = new byte[lineSize];
-            Marshal.Copy(buffer, lineData, 0, lineSize);
+                int lineSize = points * Marshal.SizeOf(typeof(LBPointZA));
+                byte[] lineData = new byte[lineSize];
+                Marshal.Copy(buffer, lineData, 0, lineSize);
 
-            lock (_bufferLock)
-            {
-                _lineDataBuffer.Add(lineData);
-                _currentLineCount++;
-            }
+                lock (_bufferLock)
+                {
+                    _lineDataBuffer.Add(lineData);
+                    _currentLineCount++;
+                }
         }
 
         private void OnAcquisitionCompleted(IntPtr pInstance, int nOption)
         {
-            // nOption: 0=涓�鎵规暟鎹粨鏉�, 1=鍏ㄩ儴瀹屾垚, 2=鐐逛簯灏辩华
-            if (nOption == 1 || nOption == 0)
-            {
-                GenerateIntensityMap();
-            }
+                // nOption: 0=涓�鎵规暟鎹粨鏉�, 1=鍏ㄩ儴瀹屾垚, 2=鐐逛簯灏辩华
+                if (nOption == 1 || nOption == 0)
+                {
+                    GenerateIntensityMap();
+                }
         }
 
         private void GenerateIntensityMap()

--
Gitblit v1.9.3