C3032
2026-01-08 7279c77f318cd7e38af279dc98a1fecec33f5e30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using LB_SmartVisionCameraSDK.PHM6000;
using LB_VisionProcesses.Cameras;
using LB_SmartVisionCommon;
using LB_SmartVisionCameraDevice.PHM6000;
 
namespace LB_VisionProcesses.Cameras.LBCameras
{
    public class LBCameraEventArgs : CameraEventArgs
    {
        public bool IsComplete { get; set; }
        public LBCameraEventArgs(string sn, Bitmap bitmap, bool isComplete) : base(sn, bitmap)
        {
            IsComplete = isComplete;
        }
    }
 
    /// <summary>
    /// LB3D工业相机实现类
    /// 基于PHM6000系列封装
    /// </summary>
    public class LBCamera : BaseCamera
    {
        private IntPtr _cameraHandle = IntPtr.Zero;
        private PHM6000SensorConfig _sensorConfig;
        private AcquisitionCompletedCallback _acquisitionCompletedCallback;
        private bool _isConnected = false;
        private int _frameCount = 0; // 采集帧计数
 
        // 图像缓冲
        private List<byte[]> _lineDataBuffer = new List<byte[]>();
        private readonly object _bufferLock = new object();
        private int _currentLineCount = 0;
        
        // 实时显示用的Bitmap
        private Bitmap _currentBitmap = null;
        private byte[] _rawPixelBuffer = null; // 用于存储像素数据,避免频繁LockBits
        private int _currentBitmapHeight = 0;
        private int _currentBitmapWidth = 0;
        private object _bitmapLock = new object();
        private DateTime _lastUpdateTime = DateTime.MinValue;
 
        // 显示句柄和函数(与LLSystem示例保持一致)
        private IntPtr _lightPic = IntPtr.Zero;
        private IntPtr _deepPic = IntPtr.Zero;
        private IntPtr _pointPic = IntPtr.Zero;
        private IntPtr _outlinePic = IntPtr.Zero;
 
        // 显示控制函数结构体
        private PILOT2D_FUNC _func2d;
        private VTK3D_FUNC _func3d;
 
        public LBCamera()
        {
            Brand = CameraBrand.LBCamera;
            _sensorConfig = new PHM6000SensorConfig();
 
            // 初始化2D显示函数
            _func2d = new PILOT2D_FUNC
            {
                AddBarycentreDataZA = Pilot2D.AddBarycentreDataZA,
                AddDepthData = Pilot2D.AddDepthData,
                AddIntensityData = Pilot2D.AddIntensityData,
                ClearAllPoints = Pilot2D.ClearAllPoints,
                RefreshPilot2D = Pilot2D.RefreshPilot2D,
                SetImageSize = Pilot2D.SetImageSize,
            };
 
            // 初始化3D显示函数
            _func3d = new VTK3D_FUNC
            {
                AddZAPoints = PHM6000Profiler.AddZAPoints,
                ClearPCLPoints = PHM6000Profiler.ClearPCLPoints,
                GetPointCloudBound = PHM6000Profiler.GetPointCloudBound,
                RenderPCLWindow = PHM6000Profiler.RenderPCLWindow,
                SetLookUpTableRange = PHM6000Profiler.SetLookUpTableRange,
                ShowCubeAxes = PHM6000Profiler.ShowCubeAxes,
                ShowLookUpTable = PHM6000Profiler.ShowLookUpTable,
                UpdatePCLPointColors = PHM6000Profiler.UpdatePCLPointColors,
            };
        }
 
        #region ICamera Implementation
 
        public override bool InitDevice(string sn, object handle = null)
        {
            // 如果已连接,仅检查是否需要更新显示句柄
            if (_isConnected && _cameraHandle != IntPtr.Zero)
            {
                if (handle != null && handle is IntPtr hPtr && hPtr != IntPtr.Zero)
                {
                    // 销毁旧的显示句柄
                    if (_lightPic != IntPtr.Zero)
                    {
                        Pilot2D.ClearAllPoints(_lightPic);
                        Pilot2D.DestroyPilot2DEntry(_lightPic);
                    }
 
                    // 创建新的显示句柄
                    _lightPic = Pilot2D.CreatePilot2DEntry(hPtr);
                    if (_lightPic != IntPtr.Zero)
                    {
                        var config = GetSensorConfig();
                        Pilot2D.SetImageSize(_lightPic, 4096, config.ScanLineCount > 0 ? config.ScanLineCount : 5000);
                        
                        // 更新相机绑定的显示句柄
                        PHM6000Profiler.SetShowHandles(_cameraHandle, _lightPic, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                        AsyncLogHelper.Info($"LBCamera[{SN}]: Display handle updated");
                    }
                }
                return true;
            }
 
            IntPtr tempHandle = IntPtr.Zero;
            try
            {
                SN = sn;
                // 1. 创建临时句柄用于发现设备
                tempHandle = PHM6000Profiler.CreateCameraEntry();
                if (tempHandle == IntPtr.Zero) return false;
 
                // 2. 发现相机
                int cameraCount = PHM6000Profiler.DiscoverCameras(tempHandle);
                if (cameraCount <= 0)
                {
                    PHM6000Profiler.DestroyCameraEntry(tempHandle);
                    return false;
                }
 
                string targetIp = string.Empty;
                int targetPort = 0;
                bool found = false;
 
                // 3. 遍历相机寻找匹配的SN
                for (int i = 0; i < cameraCount; i++)
                {
                    byte[] moduleTypeBytes = new byte[64];
                    byte[] serialNumberBytes = new byte[64];
                    
                    if (PHM6000Profiler.GetCameraInformation(tempHandle, i, moduleTypeBytes, serialNumberBytes) == 0)
                    {
                        string currentSn = Encoding.UTF8.GetString(serialNumberBytes).TrimEnd('\0');
                        
                        // 如果传入的 sn 是 IP 地址,则直接尝试匹配 IP
                        // 或者匹配序列号
                        if (currentSn == sn || sn.Contains(currentSn)) // 简单匹配逻辑
                        {
                            byte[] addressBytes = new byte[64];
                            int port = 0;
                            if (PHM6000Profiler.GetCameraAddress(tempHandle, i, addressBytes, ref port) == 0)
                            {
                                targetIp = Encoding.UTF8.GetString(addressBytes).TrimEnd('\0');
                                targetPort = port;
                                found = true;
                                break;
                            }
                        }
                    }
                }
 
                // 销毁临时句柄
                PHM6000Profiler.DestroyCameraEntry(tempHandle);
                tempHandle = IntPtr.Zero;
 
                if (!found)
                {
                    // 如果没找到但 sn 本身看起来像 IP,尝试直接连接
                    if (System.Net.IPAddress.TryParse(sn, out _))
                    {
                        targetIp = sn;
                        targetPort = 5577; // 默认端口
                    }
                    else
                    {
                        AsyncLogHelper.Error($"LBCamera: 未找到SN为 {sn} 的相机");
                        return false;
                    }
                }
 
                // 4. 创建正式相机句柄并连接
                _cameraHandle = PHM6000Profiler.CreateCameraEntry();
                if (_cameraHandle == IntPtr.Zero) return false;
 
                var addr = Encoding.ASCII.GetBytes(targetIp);
                int result = PHM6000Profiler.ConnectToCamera(_cameraHandle, addr, targetPort);
                
                if (result == 0)
                {
                    _isConnected = true;
                    // 加载相机当前参数到 _sensorConfig
                    SyncConfigFromCamera();
 
                    // 创建亮度图显示句柄(类似LLSystem示例)
                    IntPtr hPtr = IntPtr.Zero;
                    if (handle is IntPtr p) hPtr = p;
                    
                    if (hPtr != IntPtr.Zero)
                    {
                        _lightPic = Pilot2D.CreatePilot2DEntry(hPtr);
                        if (_lightPic != IntPtr.Zero)
                        {
                            // 设置图像尺寸,宽度4096,高度根据配置
                            var config = GetSensorConfig();
                            Pilot2D.SetImageSize(_lightPic, 4096, config.ScanLineCount > 0 ? config.ScanLineCount : 5000);
                        }
                    }
 
                    // 初始化回调
                    _acquisitionCompletedCallback = new AcquisitionCompletedCallback(OnAcquisitionCompleted);
                    
                    // 注册采集完成回调(类似LLSystem示例)
                    PHM6000Profiler.RegisterAcquisitionCompletedCallback(_cameraHandle, _acquisitionCompletedCallback, IntPtr.Zero);
 
                    // 设置2D和3D显示函数(类似LLSystem示例)
                    PHM6000Profiler.SetPilot2dFunc(_cameraHandle, _func2d);
                    PHM6000Profiler.SetVTK3dFunc(_cameraHandle, _func3d);
 
                    // 设置显示句柄(类似LLSystem示例的SetShowHandles)
                    PHM6000Profiler.SetShowHandles(_cameraHandle, _lightPic, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
 
                    AsyncLogHelper.Info($"LBCamera[{SN}]: Connected and initialized successfully with SDK auto-display mode");
 
                    return true;
                }
                else
                {
                    AsyncLogHelper.Error($"LBCamera[{SN}]: ConnectToCamera failed, result={result}");
                }
            }
            catch (Exception ex) 
            { 
                AsyncLogHelper.Error($"LBCamera: InitDevice异常 - {ex.Message}");
                if (tempHandle != IntPtr.Zero) PHM6000Profiler.DestroyCameraEntry(tempHandle);
            }
            return false;
        }
 
        public override bool CloseDevice()
        {
            if (_isConnected && _cameraHandle != IntPtr.Zero)
            {
                StopGrabbing();
 
                // 销毁显示句柄
                if (_lightPic != IntPtr.Zero)
                {
                    Pilot2D.ClearAllPoints(_lightPic);
                    Pilot2D.DestroyPilot2DEntry(_lightPic);
                    _lightPic = IntPtr.Zero;
                }
 
                PHM6000Profiler.DestroyCameraEntry(_cameraHandle);
                _cameraHandle = IntPtr.Zero;
                _isConnected = false;
 
                AsyncLogHelper.Info($"LBCamera[{SN}]: Closed and cleaned up");
            }
            return true;
        }
 
        public override List<string> GetListEnum()
        {
            List<string> cameraList = new List<string>();
            IntPtr tempHandle = IntPtr.Zero;
            try
            {
                tempHandle = PHM6000Profiler.CreateCameraEntry();
                if (tempHandle != IntPtr.Zero)
                {
                    int count = PHM6000Profiler.DiscoverCameras(tempHandle);
                    for (int i = 0; i < count; i++)
                    {
                        byte[] moduleTypeBytes = new byte[64];
                        byte[] serialNumberBytes = new byte[64];
                        if (PHM6000Profiler.GetCameraInformation(tempHandle, i, moduleTypeBytes, serialNumberBytes) == 0)
                        {
                            string sn = Encoding.UTF8.GetString(serialNumberBytes).TrimEnd('\0');
                            string type = Encoding.UTF8.GetString(moduleTypeBytes).TrimEnd('\0');
                            // 格式参考:PHM6000[SN123456]
                            if (!string.IsNullOrEmpty(sn))
                            {
                                cameraList.Add(sn);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AsyncLogHelper.Error($"LBCamera: GetListEnum异常 - {ex.Message}");
            }
            finally
            {
                if (tempHandle != IntPtr.Zero)
                    PHM6000Profiler.DestroyCameraEntry(tempHandle);
            }
            return cameraList;
        }
 
        private void InitBuffer()
        {
            lock (_bitmapLock)
            {
                _currentBitmapHeight = _sensorConfig.ScanLineCount > 0 ? _sensorConfig.ScanLineCount : 5000;
                // 宽度暂时未知,将在第一行数据到达时初始化
                _currentBitmapWidth = 0;
                if (_currentBitmap != null)
                {
                    _currentBitmap.Dispose();
                    _currentBitmap = null;
                }
                _rawPixelBuffer = null;
                _currentLineCount = 0;
            }
        }
 
        public override bool StartGrabbing()
        {
            // 线扫相机默认使用连续采集模式
            // 参考LLSystem示例的ContinuousScan方法:SetAcquisitionMode(1, 1)
            return StartSingleGrab();
        }
 
        /// <summary>
        /// 单次采集模式(适用于线扫相机)
        /// 参考LLSystem示例的StartScan方法:SetAcquisitionMode(1, 0)
        /// 使用SDK自动显示模式,不手动处理数据
        /// </summary>
        public bool StartSingleGrab()
        {
            if (!_isConnected) return false;
 
            AsyncLogHelper.Info($"LBCamera[{SN}]: Starting single grab mode");
 
            // 使用SDK自动显示模式,类似LLSystem示例
            // 不设置AcquisitionCallbackZA,让SDK自动处理图像显示
            PHM6000Profiler.SetAcquisitionCallbackZA(_cameraHandle, IntPtr.Zero, IntPtr.Zero);
 
            // 设置采集模式:1=扫描模式,0=单次模式(与LLSystem示例保持一致)
            PHM6000Profiler.SetAcquisitionMode(_cameraHandle, 1, 0);
            int result = PHM6000Profiler.StartAcquisition(_cameraHandle, 0, 0, 0.0);
 
            if (result == 0)
            {
                isGrabbing = true;
                AsyncLogHelper.Info($"LBCamera[{SN}]: Single grab started successfully");
                return true;
            }
            else
            {
                AsyncLogHelper.Error($"LBCamera[{SN}]: Failed to start single grab, result={result}");
            }
            return false;
        }
 
        /// <summary>
        /// 连续采集模式(适用于线扫相机)
        /// 参考LLSystem示例的ContinuousScan方法:SetAcquisitionMode(1, 1)
        /// 使用SDK自动显示模式,不手动处理数据
        /// </summary>
        public override bool StartContinuousGrab()
        {
            if (!_isConnected) return false;
 
            AsyncLogHelper.Info($"LBCamera[{SN}]: Starting continuous grab mode");
 
            // 使用SDK自动显示模式,类似LLSystem示例
            // 不设置AcquisitionCallbackZA,让SDK自动处理图像显示
            PHM6000Profiler.SetAcquisitionCallbackZA(_cameraHandle, IntPtr.Zero, IntPtr.Zero);
 
            // 设置采集模式:1=扫描模式,1=连续模式(与LLSystem示例保持一致)
            PHM6000Profiler.SetAcquisitionMode(_cameraHandle, 1, 1);
            int result = PHM6000Profiler.StartAcquisition(_cameraHandle, 0, 0, 0.0);
 
            if (result == 0)
            {
                isGrabbing = true;
                AsyncLogHelper.Info($"LBCamera[{SN}]: Continuous grab started successfully");
                return true;
            }
            else
            {
                AsyncLogHelper.Error($"LBCamera[{SN}]: Failed to start continuous grab, result={result}");
            }
            return false;
        }
 
        public override bool StopGrabbing()
        {
            if (!_isConnected) return true;
            PHM6000Profiler.StopAcquisition(_cameraHandle);
            isGrabbing = false;
            return true;
        }
 
 
        public override bool StartWith_SoftTriggerModel()
        {
            // 对于LBCamera(线扫相机),软件触发连续采集
            // 参考LLSystem示例的ContinuousScan方法:SetAcquisitionMode(1, 1)
            return StartContinuousGrab();
        }
 
        public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0)
        {
            // 对于LBCamera(线扫相机),硬件触发也使用连续采集模式
            // 参考LLSystem示例的ContinuousScan方法:SetAcquisitionMode(1, 1)
            // 外部硬件信号会触发相机开始采集
            return StartSingleGrab();
        }
 
        public override bool SoftTrigger()
        {
            // 线扫相机通常不需要传统软触发,但在某些模式下可模拟
            return true;
        }
 
        #region 参数设置映射
 
        public override bool SetExpouseTime(double value) => SetParam(EnumNameId.ExposureTime, (float)value);
        public override bool GetExpouseTime(out double value) { float v; bool r = GetParam(EnumNameId.ExposureTime, out v); value = v; return r; }
        public override bool SetGain(double gain) => SetParam(EnumNameId.AnalogGain, (float)gain);
        public override bool GetGain(out double gain) { float v; bool r = GetParam(EnumNameId.AnalogGain, out v); gain = v; return r; }
 
        // 其他接口占位实现
        public override bool SetTriggerMode(TriggerMode mode, TriggerSource triggerEnum = TriggerSource.Line0) => true;
        public override bool GetTriggerMode(out TriggerMode mode, out TriggerSource source) { mode = TriggerMode.Off; source = TriggerSource.Software; return true; }
        public override bool SetTriggerPolarity(TriggerPolarity polarity) => true;
        public override bool GetTriggerPolarity(out TriggerPolarity polarity) { polarity = TriggerPolarity.RisingEdge; return true; }
        public override bool SetTriggerFliter(double flitertime) => true;
        public override bool GetTriggerFliter(out double flitertime) { flitertime = 0; return true; }
        public override bool SetTriggerDelay(double delay) => true;
        public override bool GetTriggerDelay(out double delay) { delay = 0; return true; }
        public override bool SetLineMode(IOLines line, LineMode mode) => true;
        public override bool SetLineStatus(IOLines line, LineStatus linestatus) => true;
        public override bool GetLineStatus(IOLines line, out LineStatus lineStatus) { lineStatus = LineStatus.Low; return true; }
        public override bool AutoBalanceWhite() => true;
        
        // 不实现的方法
        public override void SetCamConfig(CameraConfig config) { }
        public override void GetCamConfig(out CameraConfig config) { config = new CameraConfig(null); }
        public override bool GetImage(out Bitmap bitmap, int outtime = 3000) { bitmap = null; return false; }
        public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000)
        {
            bitmap = null;
            if (!_isConnected) return false;
 
            // 对于线扫相机,使用SDK自动显示模式
            // 注意:SDK自动显示模式下,我们无法直接获取Bitmap
            // 但SDK会自动将图像显示到_lightPic句柄对应的控件上
            // 我们只需要启动单次采集,等待采集完成即可
 
            using (AutoResetEvent waitHandle = new AutoResetEvent(false))
            {
                bool captured = false;
                EventHandler<CameraEventArgs> handler = (s, e) =>
                {
                    // 对于线扫相机,仅当IsComplete为true时才表示采集完成
                    if (e is LBCameraEventArgs args && args.IsComplete)
                    {
                        captured = true;
                        waitHandle.Set();
                    }
                };
 
                this.ImageGrabbed += handler;
 
                try
                {
                    // 使用单次采集模式(与LLSystem示例保持一致)
                    if (StartSingleGrab())
                    {
                        // 等待采集完成
                        if (waitHandle.WaitOne(outtime))
                        {
                            // 由于SDK自动显示,我们无法返回Bitmap
                            // 但采集已完成,图像已显示到界面上
                            bitmap = null;  // SDK自动显示模式下不返回Bitmap
                            return captured;
                        }
                    }
                }
                finally
                {
                    this.ImageGrabbed -= handler;
                    StopGrabbing();
                }
            }
            return false;
        }
 
        public PHM6000SensorConfig GetSensorConfig()
        {
            SyncConfigFromCamera();
            return _sensorConfig;
        }
 
        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.固定频率)
            {
                PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)EnumNameId.SoftwareTriggerRate, 0, config.SoftwareTriggerRate, 0);
            }
            
            // 确保参数生效
            PHM6000Profiler.SaveAllParametersToDevice(_cameraHandle);
        }
 
        #endregion
        
        #endregion
 
        #region Private Callback & Helpers
 
        private void OnAcquisitionCompleted(IntPtr pInstance, int nOption)
        {
            // nOption含义:
            // 0 = 一批数据结束
            // 1 = 全部采集完成(仅单次模式)
            // 2 = 对应数据处理完成(每次采集完成都会触发)
 
            // 记录回调信息
            AsyncLogHelper.Info($"LBCamera[{SN}]: OnAcquisitionCompleted called, nOption={nOption}");
 
            if (nOption == 2)
            {
                // 连续采集模式下,每完成一帧SDK都会自动继续采集下一帧
                // SDK会自动处理图像显示到_lightPic句柄
                // 我们只需要统计采集次数
                _frameCount++;
 
                AsyncLogHelper.Info($"LBCamera[{SN}]: Frame {_frameCount} completed (continuous mode, SDK auto-display)");
 
                // 触发事件通知UI更新(但不传递Bitmap,因为SDK自动显示)
                ImageGrabbed?.Invoke(this, new LBCameraEventArgs(SN, null, true));
            }
        }
 
        private void SyncConfigFromCamera()
        {
            // 从相机读取所有参数并填充到 _sensorConfig
            foreach (EnumNameId id in Enum.GetValues(typeof(EnumNameId)))
            {
                int iVal = 0; double dVal = 0; int eVal = 0;
                if (PHM6000Profiler.GetProfilerParameter(_cameraHandle, (int)id, ref iVal, ref dVal, ref eVal) == 0)
                {
                    // 实际项目中应使用反射将值写回 _sensorConfig
                }
            }
        }
 
        private bool SetParam(EnumNameId id, float value)
        {
            if (!_isConnected) return false;
            return PHM6000Profiler.SetProfilerParameter(_cameraHandle, (int)id, 0, value, 0) == 0;
        }
 
        private bool GetParam(EnumNameId id, out float value)
        {
            value = 0;
            if (!_isConnected) return false;
            int iVal = 0; double dVal = 0; int eVal = 0;
            if (PHM6000Profiler.GetProfilerParameter(_cameraHandle, (int)id, ref iVal, ref dVal, ref eVal) == 0)
            {
                value = (float)dVal;
                return true;
            }
            return false;
        }
        #endregion
    }
}