From 9b2ad9bafb0739f8ba1e76107011fada5e5883c3 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期五, 10 四月 2026 16:23:08 +0800
Subject: [PATCH] 修复LB3D相机参数设置问题以及新增兰宝3D相机参数存储在本地以及初始化给相机参数。

---
 LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs |   81 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 71 insertions(+), 10 deletions(-)

diff --git a/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs b/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
index dba81f6..123fa04 100644
--- a/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
+++ b/LB_VisionProcesses/Cameras/LBCameras/LBCamera.cs
@@ -2,10 +2,13 @@
 using LB_SmartVisionCameraSDK.PHM6000;
 using LB_SmartVisionCommon;
 using LB_VisionProcesses.Cameras;
+using OpenVinoSharp.Extensions.model;
+using SharpCompress.Common;
 using Sunny.UI.Win32;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Drawing;
 using System.Drawing.Imaging;
 using System.Reflection;
@@ -33,7 +36,6 @@
     {
         private IntPtr _cameraHandle = IntPtr.Zero;
         private PHM6000SensorConfig _sensorConfig;
-        
         // 閲囬泦鍥炶皟
         private AcquisitionCallbackZA _acquisitionCallback;
         private AcquisitionCompletedCallback _acquisitionCompletedCallback;
@@ -419,16 +421,75 @@
 
         public void UpdateSensorConfig(PHM6000SensorConfig config)
         {
-            _sensorConfig = config;
-            if (!_isConnected) return;
-            SetParam(EnumNameId.ExposureTime, (float)config.ExposureTime);
-            SetParam(EnumNameId.AnalogGain, (float)config.AnalogGain);
-            PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.ScanLineCount, config.ScanLineCount, 0, 0);
-            PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.LineScanTriggerSource, 0, 0, (int)config.LineScanTriggerSource);
-            PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.DataAcquisitionTriggerSource, 0, 0, (int)config.DataAcquisitionTriggerSource);
-            if (config.LineScanTriggerSource == EnumLineScanTriggerSource.鍥哄畾棰戠巼)
+            //_sensorConfig = config;
+            //if (!_isConnected) return;
+            //SetParam(EnumNameId.ExposureTime, (float)config.ExposureTime);
+            //SetParam(EnumNameId.AnalogGain, (float)config.AnalogGain);
+            //PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.ScanLineCount, config.ScanLineCount, 0, 0);
+            //PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.LineScanTriggerSource, 0, 0, (int)config.LineScanTriggerSource);
+            //PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.DataAcquisitionTriggerSource, 0, 0, (int)config.DataAcquisitionTriggerSource);
+            //if (config.LineScanTriggerSource == EnumLineScanTriggerSource.鍥哄畾棰戠巼)
+            //{
+            //    PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.SoftwareTriggerRate, 0, config.SoftwareTriggerRate, 0);
+            //}
+
+            int result = 0;
+            var type = config.GetType();
+            var propLineScan = type.GetProperty(nameof(config.LineScanTriggerSource));
+            var val = (EnumLineScanTriggerSource)propLineScan.GetValue(config);
+            var props = config.GetType().GetProperties();
+
+            //鎺掗櫎Y杞�
+            props = props.Where(d => d.Name != nameof(PHM6000SensorConfig.YResolution)).ToArray();
+            //鎺掗櫎涓嶉渶瑕佺殑椤�
+            if (val == EnumLineScanTriggerSource.鍥哄畾棰戠巼)
             {
-                PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.SoftwareTriggerRate, 0, config.SoftwareTriggerRate, 0);
+                props = props.Where(d => d.Name != nameof(PHM6000SensorConfig.EncoderTriggerDirection) && d.Name != nameof(PHM6000SensorConfig.EncoderTriggerInterval) && d.Name != nameof(PHM6000SensorConfig.EncoderTriggerSignalCountingMode)).ToArray();
+            }
+            else
+            {
+                props = props.Where(d => d.Name != nameof(PHM6000SensorConfig.SoftwareTriggerRate)).ToArray();
+            }
+            foreach (var p in props)
+            {
+                //璺宠繃鑷畾涔夊弬鏁�
+                var iscustomAttr = p.GetCustomAttribute<IsCustomAttribute>();
+                if (iscustomAttr != null) continue;
+                //鍒ゆ柇鏄�6030浼犳劅鍣ㄨ繕鏄櫘閫氫紶鎰熷櫒
+                if (SN.StartsWith("LX030") && p.Name == nameof(config.AnalogGain))
+                {
+                    continue;
+                }
+                if (!SN.StartsWith("LX030") && p.Name == nameof(config.AnalogGainFor6030))
+                {
+                    continue;
+                }
+                var id = Convert.ToInt32(Enum.Parse(typeof(EnumNameId), p.Name));
+                if (p.PropertyType == typeof(int))
+                {
+                    var value = Convert.ToInt32(p.GetValue(config));
+                    result = PHM6000Profiler.SetProfilerParameter(_cameraHandle, id, value, 0, 0);
+                }
+                else if (p.PropertyType == typeof(float))
+                {
+                    var value = Convert.ToDouble(p.GetValue(config));
+                    result = PHM6000Profiler.SetProfilerParameter(_cameraHandle, id, 0, value, 0);
+                }
+                else
+                {
+                    var value = Convert.ToInt32(p.GetValue(config));
+                    result = PHM6000Profiler.SetProfilerParameter(_cameraHandle, id, 0, 0, value);
+                }
+                if (result == -1)
+                {
+                    var disattr = p.GetCustomAttribute<DisplayNameAttribute>();
+                    var name = disattr?.DisplayName ?? p.Name;
+                    throw new Exception($"璁剧疆鍙傛暟{name}鏃朵笉鎴愬姛锛�");
+                }
+            }
+            var finalResult = PHM6000Profiler.SaveAllParametersToDevice(_cameraHandle);
+            if (finalResult != 0)
+            {
             }
             PHM6000Profiler.SaveAllParametersToDevice(_cameraHandle);
         }

--
Gitblit v1.9.3