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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
using Bro.Common.Factory;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model.Interface;
using HalconDotNet;
using Newtonsoft.Json;
//using MvCamCtrl.NET;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using static Bro.Common.Helper.EnumHelper;
 
namespace Bro.Common.Base
{
    public delegate void OnUpdateCameraImageDelegate(CameraBase camera, Bitmap image, string imagePath);
    public abstract class CameraBase : DeviceBase
    {
        #region DeviceBase
        protected override void Start()
        {
            if (clearImageTimer == null)
            {
                clearImageTimer = new System.Threading.Timer((o) => { ClearImage(); }, null, 0, 1000 * 60 * 120);
            }
        }
 
        protected override void Stop()
        {
            if (clearImageTimer != null)
            {
                clearImageTimer.Change(-1, -1);
                clearImageTimer.Dispose();
                clearImageTimer = null;
            }
        }
        #endregion
 
        //public Action<string, string> OnLog;
 
        /// <summary>
        /// 运行模式 扫描or拍照
        /// </summary>
        public EnumHelper.CameraOpMode OpMode { get; set; } = EnumHelper.CameraOpMode.Snapshot;
 
        /// <summary>
        /// 扫描到的图片
        /// </summary>
        public virtual object ImageObj { get; set; } = null;
 
        public AutoResetEvent ImageGetHandle = new AutoResetEvent(false);
        public AutoResetEvent ImageSaveDoneHandle = new AutoResetEvent(false);
 
        private Bitmap showImage;
        /// <summary>
        /// 输出显示的图片
        /// </summary>
        public virtual Bitmap ShowImage
        {
            get
            {
                return showImage;
            }
            set
            {
                try
                {
                    showImage = value;
 
                    if (showImage != null)
                    {
                        UpdateShowImage?.Invoke(this, new Bitmap(showImage), null);
                    }
 
                    if (OpMode == EnumHelper.CameraOpMode.Snapshot)
                    {
                        ImageGetHandle.Set();
                    }
                }
                catch (Exception ex)
                {
                    OnLog?.Invoke(DateTime.Now, this, $"相机异常信息:{ex.GetExceptionMessage()}");
                }
            }
        }
 
        #region 使用指针操作图像的必须信息
        ///// <summary>
        ///// 图片内容的指针
        ///// </summary>
        //public IntPtr ImagePtr { get; set; } = IntPtr.Zero;
 
        //public int ImagePtrSize { get; set; } = 0;
 
        //public int? ImageWidth
        //{
        //    get
        //    {
        //        return ShowImage?.Width;
        //    }
        //}
 
        //public int? ImageHeight
        //{
        //    get
        //    {
        //        return ShowImage?.Height;
        //    }
        //}
 
        #endregion
 
        private string imageFilePath;
        /// <summary>
        /// 扫描图片保存文件路径
        /// </summary>
        public string ImageFilePath
        {
            get
            {
                return imageFilePath;
            }
            set
            {
 
                if (imageFilePath != value)
                {
                    imageFilePath = value;
                }
            }
        }
 
 
        /// <summary>
        /// 一次性抓拍
        /// </summary>
        /// <returns></returns>
        public abstract void Snapshot();
 
        public abstract void Snapshot(out HObject hImage);
 
        public abstract void Snapshot(IOperationConfig config, out HObject hImage);
 
        /// <summary>
        /// 开始扫描
        /// </summary>
        /// <returns></returns>
        public abstract void StartScan();
 
        /// <summary>
        /// 结束扫描
        /// </summary>
        public abstract void StopScan();
 
 
        /// <summary>
        /// 释放图片数据
        /// </summary>
        protected virtual void FreeImage()
        {
            if (ShowImage != null)
            {
                ShowImage.Dispose();
            }
        }
 
        /// <summary>
        /// 从设备硬件信息获取设备设置参数
        /// </summary>
        /// <returns></returns>
        public abstract IDeviceConfig GetDeviceConfigFromDevice();
 
        public abstract IOperationConfig GetOperationConfigFromDevice();
 
        public abstract void UploadOperationConfig(IOperationConfig config);
 
        public event OnUpdateCameraImageDelegate UpdateShowImage;
 
        public abstract HalconRelatedCameraInitialConfigBase IConfig { get; }
 
        protected virtual async void SaveImage(Bitmap map, HalconRelatedCameraOprerationConfigBase opConfig = null)
        {
            await Task.Run(() =>
            {
                if ((opConfig?.IsSaveImage) ?? false)
                {
                    string subDir = (opConfig ?? new HalconRelatedCameraOprerationConfigBase()).ImageSaveSubDirectory;
                    if (string.IsNullOrWhiteSpace(subDir))
                    {
                        subDir = DateTime.Now.ToString("yyyyMMdd");
                    }
                    else
                    {
                        subDir = Path.Combine(DateTime.Now.ToString("yyyyMMdd"), subDir);
                    }
 
                    string imgDir = Path.Combine(IConfig.ImgDirectory, subDir);
 
                    DirectoryInfo dir = new DirectoryInfo(imgDir);
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
 
                    try
                    {
                        //if ((opConfig?.IsSaveImage) ?? false)
                        {
                            //ImageSaveDoneHandle.Reset();
 
                            string fileName = DateTime.Now.ToString("HHmmssfff");
 
                            if (opConfig.ImageType == ImageType.Bmp)
                            {
                                ImageFilePath = Path.Combine(imgDir, $"{fileName}.bmp");
                                map.Save(ImageFilePath, ImageFormat.Bmp);
                            }
                            else
                            {
                                ImageFilePath = Path.Combine(imgDir, $"{fileName}.jpg");
                                map.Save(ImageFilePath, ImageFormat.Jpeg);
                            }
 
                            ImageSaveDoneHandle.Set();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            });
        }
 
        #region 定时清理图片
        static object _clearImageLock = new object();
 
        protected void ClearImage()
        {
            if (IConfig.SaveImageDayLimit > 0)
            {
                lock (_clearImageLock)
                {
                    OnLog?.Invoke(DateTime.Now, this, $"ClearImage Start。 {this.IConfig.CameraIP}");
 
                    try
                    {
                        DirectoryInfo dirImage = new DirectoryInfo(IConfig.ImgDirectory);
                        if (dirImage.Exists)
                        {
                            DateTime dtNow = DateTime.Now;
 
                            var folderList = dirImage.GetDirectories().ToList();
 
                            folderList = folderList.Where(f =>
                               {
                                   if (f.Name.Length < 8)
                                       return false;
 
                                   DateTime dt = DateTime.Now;
                                   string name = f.Name.Substring(0, 4) + "/" + f.Name.Substring(4, 2) + "/" + f.Name.Substring(6);
                                   return DateTime.TryParse(name, out dt);
                               }).OrderBy(u => u.Name).ToList();
 
                            if (folderList.Count > IConfig.SaveImageDayLimit)
                            {
                                folderList.Take(folderList.Count - IConfig.SaveImageDayLimit).ToList().ForEach(f =>
                                    {
                                        f.Delete(true);
                                    });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        OnLog?.Invoke(DateTime.Now, this, $"ClearImage Exception\r\n{ex.GetExceptionMessage()}");
                    }
 
                    OnLog?.Invoke(DateTime.Now, this, $"ClearImage Done\r\n {this.IConfig.CameraIP}");
                }
            }
        }
 
        private System.Threading.Timer clearImageTimer = null;
        #endregion
    }
 
    public class CameraOperationConfigBase : OperationConfigBase, IComparer<CameraOperationConfigBase>, IComparable<CameraOperationConfigBase>
    {
        /// <summary>
        /// 运行模式
        /// </summary>
        public EnumHelper.CameraOpMode OpMode { get; set; } = EnumHelper.CameraOpMode.Snapshot;
 
        #region 运行参数
        /// <summary>
        /// 该参数表示哪些值参与设置
        /// </summary>
        public string ConfigItems { get; set; } = "[]"; //= "['BalanceRed','BalanceGreen','BalanceBlue','Exposure','Saturation','Gain','WhiteBalance']";
 
        [CameraPara("红平衡", "BalanceRed", 2, 1, 1000)]
        public double BalanceRed { get; set; } = 1;
 
        [CameraPara("绿平衡", "BalanceGreen", 2, 1, 1000)]
        public double BalanceGreen { get; set; } = 1;
 
        [CameraPara("蓝平衡", "BalanceBlue", 2, 1, 1000)]
        public double BalanceBlue { get; set; } = 1;
 
        [CameraPara("白平衡", "WhiteBalance", 2, 0, 1000)]
        public double WhiteBalance { get; set; } = 1;
 
        [CameraPara("曝光时间", "Exposure", 60000, 1, 1)]
        public double Exposure { get; set; } = 10;
 
        [CameraPara("饱和度", "Saturation", 2, 1, 1000)]
        public double Saturation { get; set; } = 1;
 
        [CameraPara("增益补偿", "Gain", 200, 0, 1)]
        public double Gain { get; set; } = 1;
 
        [CameraPara("采像宽度", "Width", 10000, 0, 1)]
        public int Width { get; set; } = 0;
 
        [CameraPara("采像高度", "Height", 10000, 0, 1)]
        public int Height { get; set; } = 0;
 
        [ConfigOutputResource("OutputResultCommon")]
        public override int ResultOutput { get; set; }
 
        public int Compare(CameraOperationConfigBase x, CameraOperationConfigBase y)
        {
            //List<string> yItems = JsonConvert.DeserializeObject<List<string>>(y.ConfigItems);
            string yItems = y.ConfigItems.Trim(new char[] { '[', ']' });
 
            if (string.IsNullOrWhiteSpace(yItems))
            {
                return 0;
            }
            else
            {
                if (yItems.Contains("BalanceBlue"))
                {
                    if (x.BalanceBlue != y.BalanceBlue)
                    {
                        return 1;
                    }
                }
 
                if (yItems.Contains("BalanceGreen"))
                {
                    if (x.BalanceGreen != y.BalanceGreen)
                    {
                        return 1;
                    }
                }
 
                if (yItems.Contains("BalanceRed"))
                {
                    if (x.BalanceRed != y.BalanceRed)
                    {
                        return 1;
                    }
                }
 
                if (yItems.Contains("WhiteBalance"))
                {
                    if (x.WhiteBalance != y.WhiteBalance)
                    {
                        return 1;
                    }
                }
 
                if (yItems.Contains("Exposure"))
                {
                    if (x.Exposure != y.Exposure)
                    {
                        return 1;
                    }
                }
 
                if (yItems.Contains("Saturation"))
                {
                    if (x.Saturation != y.Saturation)
                    {
                        return 1;
                    }
                }
 
                if (yItems.Contains("Gain"))
                {
                    if (x.Gain != y.Gain)
                    {
                        return 1;
                    }
                }
 
                if (yItems.Contains("Width"))
                {
                    if (x.Width != y.Width)
                    {
                        return 1;
                    }
                }
 
                if (yItems.Contains("Height"))
                {
                    if (x.Height != y.Height)
                    {
                        return 1;
                    }
                }
 
                return 0;
            }
        }
 
        /// <summary>
        /// y作为原始数据 当前数据如果ConfigItem为空时,默认无变化
        /// </summary>
        /// <param name="y">原始数据</param>
        /// <returns></returns>
        public int CompareTo(CameraOperationConfigBase y)
        {
            string xItems = ConfigItems.Trim(new char[] { '[', ']' });
 
            if (string.IsNullOrWhiteSpace(xItems))
            {
                return 0;
            }
            else
            {
                if (xItems.Contains("BalanceBlue"))
                {
                    if (BalanceBlue != y.BalanceBlue)
                    {
                        return 1;
                    }
                }
 
                if (xItems.Contains("BalanceGreen"))
                {
                    if (BalanceGreen != y.BalanceGreen)
                    {
                        return 1;
                    }
                }
 
                if (xItems.Contains("BalanceRed"))
                {
                    if (BalanceRed != y.BalanceRed)
                    {
                        return 1;
                    }
                }
 
                if (xItems.Contains("WhiteBalance"))
                {
                    if (WhiteBalance != y.WhiteBalance)
                    {
                        return 1;
                    }
                }
 
                if (xItems.Contains("Exposure"))
                {
                    if (Exposure != y.Exposure)
                    {
                        return 1;
                    }
                }
 
                if (xItems.Contains("Saturation"))
                {
                    if (Saturation != y.Saturation)
                    {
                        return 1;
                    }
                }
 
                if (xItems.Contains("Gain"))
                {
                    if (Gain != y.Gain)
                    {
                        return 1;
                    }
                }
 
                if (xItems.Contains("Width"))
                {
                    if (Width != y.Width)
                    {
                        return 1;
                    }
                }
 
                if (xItems.Contains("Height"))
                {
                    if (Height != y.Height)
                    {
                        return 1;
                    }
                }
 
                return 0;
            }
        }
 
        public override bool Equals(object obj)
        {
            CameraOperationConfigBase cocb = obj as CameraOperationConfigBase;
            if (cocb == null)
            {
                return false;
            }
 
            return CompareTo(cocb) == 0;
        }
 
        #endregion
    }
 
    public class CameraDeviceConfigBase : DeviceConfigBase
    {
        [DefaultValue("['MaxNumBuffer','GammaValue','ReverseX','ReverseY']")]
        public string ConfigItems { get; set; } = "['MaxNumBuffer','GammaValue','ReverseX','ReverseY']";
 
        public long MaxNumBuffer { get; set; }
 
        public double GammaValue { get; set; } = double.MinValue;
 
        public bool ReverseX { get; set; }
 
        public bool ReverseY { get; set; }
    }
 
    public class CameraInitialConfigBase : InitialConfigBase
    {
        /// <summary>
        /// 该参数表示哪些参数值对本相机有效
        /// </summary>
        public string EnableItems { get; set; }
    }
 
    public class CameraInputConfigBase : InputConfigBase
    {
    }
 
    #region HalconRelatedCameara
 
    public class HalconRelatedCameraOprerationConfigBase : OperationConfigBase, INotifyPropertyChanged, IComplexDisplay, IHalconToolPath
    {
        private float exposure = 0;
        /// <summary>
        /// 曝光
        /// </summary>
        [Category("取像配置")]
        [Description("曝光")]
        public float Exposure
        {
            get => exposure;
            set
            {
                if (exposure != value)
                {
                    exposure = value;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Exposure"));
                }
            }
        }
 
        /// <summary>
        /// 增益
        /// </summary>
        [Category("取像配置")]
        [Description("增益")]
        public float Gain { get; set; }
 
        [Category("取像配置")]
        [Description("曝光修改后等待时间,单位ms。针对部分场景确保曝光修改及时生效。")]
        public int ExposureWaitTime { get; set; }
 
        [Category("取像配置")]
        [Description("拍摄后曝光值。可在一次拍摄后将曝光修改为下次拍摄的曝光值,节约曝光生效时间。")]
        public float ExposureAfterSnap { get; set; }
 
        [Browsable(false)]
        public override int ResultOutput { get; set; }
 
        [Category("算法配置")]
        [Description("算法路径")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string AlgorithemPath { get; set; }
 
        [Category("延时配置")]
        [Description("拍照前延时")]
        public int DelayBefore { get; set; } = 0;
 
        [Category("延时配置")]
        [Description("拍照后延时")]
        public int DelayAfter { get; set; } = 0;
 
        [Category("图片保存")]
        [Description("图片保存文件夹分路径")]
        public string ImageSaveSubDirectory { get; set; }
 
        [Category("图片保存")]
        [Description("是否保存图片")]
        public bool IsSaveImage { get; set; } = true;
 
        [Category("图片保存")]
        [Description("图片保存格式")]
        public ImageType ImageType { get; set; } = ImageType.Jpeg;
 
        [Category("图片保存")]
        [Description("是否保存拟合/结果图片")]
        public bool IsSaveFitImage { get; set; } = false;
 
        [Category("图片保存")]
        [Description("是否保存NG图片")]
        public bool IsSaveNGImage { get; set; } = false;
 
        [Category("图片保存")]
        [Description("拟合/结果图片保存路径")]
        [Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
        public string FitImagePath { get; set; }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        public string GetDisplayText()
        {
            return $"{(IsEnabled ? "" : "停用 ")}曝光:{Exposure.ToString("f2")}";
        }
 
        public List<string> GetHalconToolPathList()
        {
            return new List<string>() { AlgorithemPath };
        }
    }
 
    public class HalconRelatedCameraInitialConfigBase : InitialConfigBase
    {
        [Category("相机设置")]
        [Description("驱动类型")]
        [TypeConverter(typeof(CameraTypeConverter))]
        public string DriverType { get; set; } = "HikCamera";
 
        [Category("相机设置")]
        [Description("相机序列号")]
        [TypeConverter(typeof(HalconSerialNumConverter))]
        public virtual string SerialNum { get; set; }
 
        [Category("相机设置")]
        [Description("相机IP地址")]
        public string CameraIP { get; set; }
 
        [Category("相机设置")]
        [Description("上位机IP地址")]
        public string ComputerIP { get; set; }
 
        [Category("相机设置")]
        [Description("视频模式扫描间隔 单位毫秒")]
        public int ScanInterval { get; set; } = 100;
 
        [Category("保存设置")]
        [Description("采图保存目录")]
        [Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
        public string ImgDirectory { get; set; } = @"../Images";
 
        [Category("保存设置")]
        [Description("图片保存天数")]
        [Browsable(false)]
        public int SaveImageDayLimit { get; set; } = 0;
 
        [Category("拍摄设置")]
        [Description("默认曝光值。相机开启后就设置该曝光值。")]
        public float DefaultExposure { get; set; }
    }
 
    public class HalconSerialNumConverter : ComboBoxItemTypeConvert
    {
        public override void GetConvertHash()
        {
            HTuple deviceList = null;
 
            AutoResetEvent handle = new AutoResetEvent(false);
 
            Task.Run(() =>
            {
                HOperatorSet.InfoFramegrabber("GigEVision", "info_boards", out HTuple deviceInfo, out deviceList);
                handle.Set();
            });
 
            handle.WaitOne(5000);
            if (deviceList != null)
            {
                for (int i = 0; i < deviceList.Length; i++)
                {
                    var list = deviceList[i].S.Split(new char[] { ':', '|' }, StringSplitOptions.RemoveEmptyEntries);
 
                    _hash[list[1].Trim()] = list[3].Trim() + "--" + list[1].Trim();
                }
            }
        }
    }
    #endregion
 
    public class CameraTypeConverter : StringConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
 
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }
 
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            List<string> devices = DeviceFactory.GetAllSupportDeviceTypeNames();
 
            devices = devices.Where(u => u.EndsWith("Camera")).ToList();
 
            return new StandardValuesCollection(devices);
        }
    }
 
    public class CameraInitialConfigEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }
 
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
 
            if (edSvc != null)
            {
                Form form = new Form();
                form.FormBorderStyle = FormBorderStyle.SizableToolWindow;
                form.StartPosition = FormStartPosition.CenterParent;
                form.Text = context.PropertyDescriptor.DisplayName + "--" + context.PropertyDescriptor.Description;
 
                PropertyGrid pg = new PropertyGrid();
                pg.Dock = DockStyle.Fill;
                pg.ToolbarVisible = false;
 
                string driverType = (value as HalconRelatedCameraInitialConfigBase).DriverType;
 
                if (!string.IsNullOrWhiteSpace(driverType))
                {
                    IInitialConfig initial = ConfigFactory.GetInitialConfig(driverType);
                    initial.DataFrom(value);
                    value = initial;
                }
 
                pg.SelectedObject = value;
 
                form.Controls.Add(pg);
 
                form.ShowDialog();
 
                value = pg.SelectedObject;
                return value;
            }
 
            return base.EditValue(context, provider, value);
        }
    }
 
    public static class CameraHelper
    {
        public static CameraBase GetCameraInstance(string driverType)
        {
            return DeviceFactory.GetDeviceInstanceByTypeName(driverType) as CameraBase;
        }
    }
}