领胜LDS 键盘AOI检测项目
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
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
using A036.Process;
using Autofac;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.Common.PubSub;
using Bro.Common.UI;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Bro.Common.Helper.EnumHelper;
 
namespace A034.Config
{
    public partial class ConfigFrm : Form
    {
        private IStationProcess Process { get; set; } = null;
 
        IStationConfig _config = null;
        IStationConfig Config
        {
            get => _config;
            set
            {
                _config = value;
 
                if (Process != null)
                {
                    InitialCalibrationMethod();
                    InitialAllTestMethod();
 
                    InitialDevices();
                }
            }
        }
 
        ProcessConfig ProcessConfig
        {
            get => Config as ProcessConfig;
        }
 
        Canvas canvasImage = new Canvas();
 
        #region 用户登录
        private bool isLogin = false;
        public bool IsLogin
        {
            get => isLogin;
            set
            {
                isLogin = value;
                tsslLoginStatus.Text = isLogin ? "已登录" : "未登录";
            }
        }
 
        private void tsslLoginStatus_Click(object sender, EventArgs e)
        {
            if (!IsLogin)
            {
                IsLogin = UserLogin();
            }
        }
 
        private bool UserLogin()
        {
            AdvancedPwdFrm pwdFrm = new AdvancedPwdFrm();
            return pwdFrm.ShowDialog() == DialogResult.OK;
        }
        #endregion
 
        public ConfigFrm()
        {
            InitializeComponent();
 
            canvasImage = new Canvas();
            canvasImage.IsShowElementList = false;
            canvasImage.Dock = DockStyle.Fill;
            plCanvas.Controls.Add(canvasImage);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            FillProductionCodes();
 
            //_servicePanel.Dock = DockStyle.Fill;
            //_servicePanel.OnServiceStateChanged = OnServiceStateChanged;
            //_servicePanel.GetServiceStatus();
            //tabControl1.TabPages["tbService"].Controls.Add(_servicePanel);
 
            if (cboProductionCode.Text == "Default")
            {
                LoadProcess("Default");
            }
        }
 
        private void FillProductionCodes()
        {
            List<string> codes = new List<string>();
 
            string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Setting.json");
            if (File.Exists(configPath))
            {
                using (StreamReader reader = new StreamReader(configPath, System.Text.Encoding.UTF8))
                {
                    string dataStr = reader.ReadToEnd();
                    JObject data = JsonConvert.DeserializeObject<JObject>(dataStr);
 
                    if (data.ContainsKey("ProductionCodes"))
                    {
                        codes = JsonConvert.DeserializeObject<List<string>>(data.Value<string>("ProductionCodes"));
                    }
                }
            }
 
            if (codes == null || codes.Count == 0)
            {
                codes = new List<string>() { "Default" };
            }
 
            UIHelper.SetCombo(cboProductionCode, codes, "", "");
        }
 
        //private object OnExceptionUpdate(ISubscriber arg1, object arg2, object arg3)
        //{
        //    Exception ex = arg3 as Exception;
        //    RecordException(arg2.ToString() + "\r\n" + ex?.GetExceptionMessage());
 
        //    return null;
        //}
 
        private void btnSaveProcess_Click(object sender, EventArgs e)
        {
            //if (!OpBeforeSaveConfig())
            //{
            //    return;
            //}
 
            //string msg = "";
 
            //if (Process == null || Process.StationConfig.StationCode != cboStationCode.Text.Trim())
            //    Process = StationFactory.CreateStationProcess(cboStationCode.Text.Trim(), "xcd", out msg);
 
 
            if (Process == null)
                Process = new ProcessControl();
 
            if (!IsLogin)
            {
                IsLogin = UserLogin();
            }
 
            if (IsLogin)
            {
                Process.SaveStationConfig(propConfig.SelectedObject as IStationConfig);
                MessageBox.Show(@"Save done");
            }
            else
            {
                MessageBox.Show("未通过用户验证,无法保存配置");
            }
        }
 
        private void btnLoadProcess_Click(object sender, EventArgs e)
        {
            LoadProcess(cboProductionCode.Text);
 
            MessageBox.Show(@"Load done");
        }
 
        private void LoadProcess(string productionCode)
        {
            Process = new ProcessControl(productionCode);
 
            propConfig.SelectedObject = Config = Process.StationConfig;
 
            //InitialService((Process.StationConfig as ProcessConfig).ServicePort);
 
            LoadCameras();
 
            (Process as ProcessControl).OnLog = OnProcessLog;
        }
 
        private void btnStartProcess_Click(object sender, EventArgs e)
        {
            Process.Open();
 
            MessageBox.Show(@"Start!");
 
            btnStartProcess.Visible = false;
            btnStopProcess.Visible = true;
        }
 
        private async void OnProcessLog(DateTime dt, string prefix, string msg)
        {
            await Task.Run(() =>
             {
                 RecordMsg(dt, prefix, msg);
             });
        }
 
        private void btnStopProcess_Click(object sender, EventArgs e)
        {
            chkContinueMode.Checked = false;
 
            Process.Close();
            MessageBox.Show(@"Stop!");
 
            btnStartProcess.Visible = true;
            btnStopProcess.Visible = false;
        }
 
        #region 标定
        Dictionary<ProcessMethodAttribute, MethodInfo> _calibrationMethodDict = new Dictionary<ProcessMethodAttribute, MethodInfo>();
        MethodInfo _calibrationMethod = null;
 
        private void InitialCalibrationMethod()
        {
            _calibrationMethodDict.Clear();
 
            Process.GetType().GetMethods().ToList().ForEach(m =>
            {
                var attr = m.GetCustomAttribute<ProcessMethodAttribute>();
 
                if (attr != null && attr.InvokeType == InvokeType.CalibInvoke)
                {
                    _calibrationMethodDict[attr] = m;
                }
            });
 
            UIHelper.SetCombo(cboCalibrationMethod, _calibrationMethodDict.Keys.ToList(), "MethodDesc", "MethodCode");
 
            cboCalibrationMethod.SelectedIndexChanged -= cboCalibrationMethod_SelectedIndexChanged;
            cboCalibrationMethod.SelectedIndexChanged += cboCalibrationMethod_SelectedIndexChanged;
        }
 
        private void cboCalibrationMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboCalibrationMethod.SelectedIndex >= 0)
            {
                string methodCode = cboCalibrationMethod.SelectedValue.ToString();
 
                _calibrationMethod = _calibrationMethodDict[_calibrationMethodDict.Keys.FirstOrDefault(u => u.MethodCode == methodCode)];
 
                if (Process.StationConfig.ProcessOpConfigDict.Keys.Contains(methodCode))
                {
                    propCalibrationConfig.SelectedObject = Process.StationConfig.ProcessOpConfigDict[methodCode];
                }
                else
                {
                    MessageBox.Show(@"Config of " + methodCode + @" is not found");
                }
            }
        }
 
        private void btnStartCalibration_Click(object sender, EventArgs e)
        {
            btnStartCalibration.Enabled = false;
            IDevice sourceDevice = cboCalibSourceDevices.SelectedItem as IDevice;
            IDevice executeDevice = cboCalibExecuteDevice.SelectedItem as IDevice;
            IOperationConfig config = propCalibrationConfig.SelectedObject as IOperationConfig;
 
            Task.Run(() =>
            {
                try
                {
                    if (config != null)
                    {
                        config.InputPara = null;
                    }
 
                    _calibrationMethod.Invoke(Process, new object[] { config, executeDevice, sourceDevice });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(@"Calibration cancel\r\n" + ex.GetExceptionMessage());
                    return;
                }
                finally
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke(new Action(() => btnStartCalibration.Enabled = true));
                    }
                    else
                    {
                        btnStartCalibration.Enabled = true;
                    }
                }
 
                MessageBox.Show(@"Operation Done");
            });
        }
 
        #endregion
 
        #region Test
        Dictionary<ProcessMethodAttribute, MethodInfo> _allTestMethod = new Dictionary<ProcessMethodAttribute, MethodInfo>();
        MethodInfo _testMethod = null;
 
        private void InitialDevices()
        {
            List<IDevice> deviceList = new List<IDevice>();
            using (var scope = GlobalVar.Container.BeginLifetimeScope())
            {
                deviceList = scope.Resolve<List<IDevice>>();
            }
 
            List<ISimpleDevice> list = deviceList.Select(u => u as ISimpleDevice).ToList();
            UIHelper.SetCombo(cboCalibSourceDevices, new List<ISimpleDevice>(list), "Name", "Id");
            UIHelper.SetCombo(cboTestSourceDevices, new List<ISimpleDevice>(list), "Name", "Id");
 
            UIHelper.SetCombo(cboCalibExecuteDevice, new List<ISimpleDevice>(list), "Name", "Id");
            UIHelper.SetCombo(cboTestExecuteDevice, new List<ISimpleDevice>(list), "Name", "Id");
        }
 
        private void InitialAllTestMethod()
        {
            _allTestMethod.Clear();
 
            Process.GetType().GetMethods().ToList().ForEach(m =>
            {
                var attr = m.GetCustomAttribute<ProcessMethodAttribute>();
 
                if (attr != null && attr.InvokeType == InvokeType.TestInvoke)
                {
                    _allTestMethod[attr] = m;
                }
            });
 
            UIHelper.SetCombo(cboTestMethod, _allTestMethod.Keys.ToList(), "MethodDesc", "MethodCode");
 
            cboTestMethod.SelectedIndexChanged -= cboTestMethod_SelectedIndexChanged;
            cboTestMethod.SelectedIndexChanged += cboTestMethod_SelectedIndexChanged;
        }
 
        private void cboTestMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboTestMethod.SelectedIndex >= 0)
            {
                string methodCode = cboTestMethod.SelectedValue.ToString();
                var attr = _allTestMethod.Keys.FirstOrDefault(u => u.MethodCode == methodCode);
                if (attr == null)
                    return;
 
                _testMethod = _allTestMethod[attr];
 
                if (Process.StationConfig.ProcessOpConfigDict.Keys.Contains(methodCode))
                {
                    propGridTestMethod.SelectedObject = Process.StationConfig.ProcessOpConfigDict[methodCode];
                }
                else
                {
                    MessageBox.Show(@"Config of " + methodCode + @" is not found");
                }
            }
        }
 
        private void btnManualTrigger_Click(object sender, EventArgs e)
        {
            IDevice sourceDevice = cboTestSourceDevices.SelectedItem as IDevice;
            IDevice executeDevice = cboTestExecuteDevice.SelectedItem as IDevice;
            new Task((m) =>
            {
                MethodInfo method = m as MethodInfo;
 
                int invokeTimes = 1;
 
                if (!int.TryParse(txtInvokeTimes.Text.Trim(), out invokeTimes))
                {
                    invokeTimes = 1;
                }
                ProcessResponse response = null;
                if (invokeTimes == 1)
                {
                    try
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        response = method.Invoke(Process, new object[] { propGridTestMethod.SelectedObject as IOperationConfig, executeDevice, sourceDevice }) as ProcessResponse;
                        sw.Stop();
 
                        //RecordMsg($"{method.Name}调用耗时:{sw.ElapsedMilliseconds}ms");
                        (Process as ProcessControl).LogAsync(DateTime.Now, $"{method.Name}调用耗时:{sw.ElapsedMilliseconds}ms", "");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Method cancel\r\n\r\n" + ex.InnerException.GetExceptionMessage());
                        return;
                    }
 
                    MessageBox.Show("Method done\r\n" + JsonConvert.SerializeObject(response, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.None }));
                }
                else
                {
                    for (int i = 0; i < invokeTimes; i++)
                    {
                        try
                        {
                            response = method.Invoke(Process, new object[] { propGridTestMethod.SelectedObject as IOperationConfig }) as ProcessResponse;
                        }
                        catch (Exception ex)
                        {
                            RecordMsg(DateTime.Now, $"Method Cancel,Time:{i + 1}", ex.InnerException.GetExceptionMessage());
                        }
 
                        RecordMsg(DateTime.Now, $"Method Done", JsonConvert.SerializeObject(response, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.None }));
 
                        Thread.Sleep(250);
                    }
                }
            }, _testMethod).Start();
        }
        #endregion
 
        private void ConfigFrm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                Process.Close();
                (Process as ProcessControl).OnLog = null;
                Thread.Sleep(500);
            }
            catch (Exception) { }
        }
 
        #region 日志和显示
 
        public void RecordMsg(DateTime dt, string prefix, string msg, bool isLog = false)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action<DateTime, string, string, bool>(RecordMsg), dt, prefix, msg, isLog);
            }
            else
            {
                if (isLog)
                {
                    LogAsync(dt, prefix, msg);
                }
 
                txtError.AppendText($"{dt.ToString("HH:mm:ss.fff")}\t{prefix}\t{msg}\r\n");
 
                while (txtError.Lines.Length > 1000)
                {
                    txtError.Lines = txtError.Lines.Skip(500).ToArray();
                }
            }
        }
 
        private void btnClearError_Click(object sender, EventArgs e)
        {
            txtError.Clear();
        }
 
        static object lockObj = new object();
        public async void LogAsync(DateTime dt, string prefix, string msg)
        {
            await Task.Run(() =>
            {
                string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExLog_" + DateTime.Today.ToString("yyyyMMdd") + ".txt");
 
                lock (lockObj)
                {
                    using (StreamWriter writer = new StreamWriter(logPath, true))
                    {
                        writer.WriteLine($"{dt.ToString("HH:mm:ss")}\t{prefix}\t{msg}");
                        writer.WriteLine();
 
                        writer.Flush();
                        writer.Close();
                    }
                }
            });
        }
 
        private void LoadCameras()
        {
            cboCameras.DataSource = null;
 
            List<dynamic> cameras = new List<dynamic>() { new { Desc = "All", Id = "" } };
 
            (Config as ProcessConfig).CameraConfigCollection.ForEach(c =>
            {
                cameras.Add(new { Desc = c.Name, Id = c.Id });
            });
 
            UIHelper.SetCombo(cboCameras, cameras, "Desc", "Id");
            cboCameras.SelectedIndex = 0;
 
            (Process as ProcessControl).OnBitmapOutput -= UpdateImage;
            (Process as ProcessControl).OnBitmapOutput += UpdateImage;
        }
 
        private static object _imgLock = new object();
        private void UpdateImage(string cameraId, Bitmap image)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action(() => UpdateImage(cameraId, image)));
            }
            else
            {
                //lock (_imgLock)
                {
                    try
                    {
                        if (string.IsNullOrWhiteSpace(cboCameras.SelectedValue?.ToString()))
                        {
                            canvasImage.LoadImage(image);
                        }
                        else
                        {
                            if (cboCameras.SelectedValue.ToString() == cameraId)
                            {
                                canvasImage.LoadImage(image);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
 
                    _imgShowedHandle.Set();
                }
            }
        }
        #endregion
 
        #region advanced使用        
        private void btnNewConfig_Click(object sender, EventArgs e)
        {
            Config = new ProcessConfig();
            propConfig.SelectedObject = Config;
        }
 
        private void btnLoadLocal_Click(object sender, EventArgs e)
        {
            if (Process == null)
            {
                MessageBox.Show("流程不能为空,请先载入流程");
                return;
            }
 
            if ((Process as ProcessControl).ProcessState == DeviceState.DSOpen)
            {
                MessageBox.Show("流程执行中,请先停止流程");
                return;
            }
 
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = false;
            ofd.Filter = "JSON配置文件|*.json";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Process = new ProcessControl(cboProductionCode.Text, ofd.FileName);
                MessageBox.Show("流程载入配置文件成功");
            }
        }
 
        #region 配置修改备份
        string _oldConfigStr = "";
 
        /// <summary>
        /// 保存配置前检查
        /// </summary>
        /// <returns>true: 可以继续保存配置  false:不再保存配置 </returns>
        private bool OpBeforeSaveConfig()
        {
            //if (string.IsNullOrWhiteSpace(_oldConfigStr))
            //    return true;
 
            string newConfigStr = JsonConvert.SerializeObject(propConfig.SelectedObject);
 
            if (newConfigStr == _oldConfigStr)
            {
                return true;
            }
            else
            {
                Process.SaveStationConfig(propConfig.SelectedObject as ProcessConfig);
                return true;
            }
        }
        #endregion
 
        private void btnAdvanced_Click(object sender, EventArgs e)
        {
            AdvancedPwdFrm pFrm = new AdvancedPwdFrm();
 
            if (pFrm.ShowDialog() == DialogResult.OK)
            {
                plBasic.Visible = false;
                plAdvanced.Visible = true;
            }
            else
            {
                plBasic.Visible = true;
                plAdvanced.Visible = false;
            }
        }
 
        private void btnExitAdvanced_Click(object sender, EventArgs e)
        {
            plAdvanced.Visible = false;
            plBasic.Visible = true;
        }
 
        private void propConfig_SelectedObjectsChanged(object sender, EventArgs e)
        {
            if (propConfig.SelectedObject != null)
            {
                _oldConfigStr = JsonConvert.SerializeObject(propConfig.SelectedObject);
            }
        }
        #endregion
 
        #region 取像操作
        float FrameRate
        {
            set
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new Action(() => lblFrameRate.Text = value.ToString() + " ms"));
                }
                else
                {
                    lblFrameRate.Text = value.ToString() + " ms";
                }
            }
        }
 
        AutoResetEvent _imgShowedHandle = new AutoResetEvent(false);
 
        private void btnSnap_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(cboCameras.SelectedValue.ToString()))
            {
                MessageBox.Show("请先选择操作相机");
                return;
            }
 
            PubSubCenter.GetInstance().Publish(PubTag.DeviceOperation.ToString(), cboCameras.SelectedValue.ToString(), "Snap");
 
            //string folderPath = "";
            //FolderBrowserDialog fbd = new FolderBrowserDialog();
            //if (fbd.ShowDialog() == DialogResult.OK)
            //{
            //    folderPath = fbd.SelectedPath;
            //}
            //else
            //{
            //    return;
            //}
 
            //Task.Run(() =>
            //{
            //    DirectoryInfo dir = new DirectoryInfo(folderPath);
            //    dir.GetFiles("*.jpg").Select(u => u.FullName).ToList().ForEach(f =>
            //    {
            //        //Task.Run(() =>
            //        //{
            //        UpdateImage("", (Bitmap)Image.FromFile(f));
            //        //});
 
            //        //Task.Run(() =>
            //        //{
            //        List<ElementBase> list = new List<ElementBase>();
            //        Random r = new Random((int)DateTime.Now.Ticks);
 
            //        for (int i = 0; i < 10; i++)
            //        {
            //            list.Add(new PointIndicator(r.Next(2448), r.Next(2048)));
            //        }
            //        UpdateVisionResult("", list);
            //        //});
            //        //Thread.Sleep(10);
            //    });
            //});
        }
 
        private void chkContinueMode_CheckedChanged(object sender, EventArgs e)
        {
            if (!chkContinueMode.Checked)
            {
                cboCameras.Enabled = true;
                lblFrameRate.Text = "";
                return;
            }
 
            if (string.IsNullOrWhiteSpace(cboCameras.SelectedValue.ToString()))
            {
                MessageBox.Show("请先选择操作相机");
                return;
            }
 
            cboCameras.Enabled = false;
            string cameraId = cboCameras.SelectedValue.ToString();
            Task.Run(() =>
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                while (chkContinueMode.Checked)
                {
                    try
                    {
                        sw.Stop();
                        FrameRate = sw.ElapsedMilliseconds;
                        sw.Restart();
                        PubSubCenter.GetInstance().Publish(PubTag.DeviceOperation.ToString(), cameraId, "Snap", false);
                        _imgShowedHandle.WaitOne(3000);
                    }
                    catch (Exception)
                    {
                    }
                }
            });
        }
 
        private void chkHardwareTrigger_CheckedChanged(object sender, EventArgs e)
        {
            //if (cboCameras.SelectedIndex > 0)
            //{
            //    var cameraConfig = ProcessConfig.CameraConfigs.FirstOrDefault(u => u.ID == cboCameras.SelectedValue.ToString());
 
            //    if (cameraConfig != null)
            //    {
            //        cameraConfig.IsHardwareTrigger = chkHardwareTrigger.Checked;
            //    }
            //}
        }
 
        private void cboCameras_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboCameras.SelectedIndex > 0)
            {
                var cameraConfig = ProcessConfig.CameraConfigCollection.FirstOrDefault(u => u.Id == cboCameras.SelectedValue.ToString());
 
                if (cameraConfig == null)
                {
                    MessageBox.Show("未能获取正确的相机配置");
                    return;
                }
                //else
                //{
                //    chkHardwareTrigger.Checked = cameraConfig.IsHardwareTrigger;
                //}
            }
        }
        #endregion
 
        #region 服务
        //CtrlServicePanel _servicePanel = new CtrlServicePanel();
        //private void InitialService(int port)
        //{
        //    _servicePanel.Port = port;
        //    _servicePanel.OnLogBroadcast = OnServiceLogBroadcast;
        //    _servicePanel.OnBitmapBroadcast = OnServiceImageBroadcast;
        //}
 
        //private void OnServiceImageBroadcast(string cameraId, string imagePath)
        //{
        //    UpdateImage(cameraId, new Bitmap(imagePath));
        //}
 
        //private void OnServiceLogBroadcast(DateTime dt, string prefix, string msg)
        //{
        //    RecordMsg(dt, prefix, msg);
        //}
 
        //private void OnServiceStateChanged(bool isServiceRunning)
        //{
        //    if (this.InvokeRequired)
        //    {
        //        this.Invoke(new Action(() =>
        //        {
        //            btnStartProcess.Enabled = btnStopProcess.Enabled = !isServiceRunning;
        //        }));
        //    }
        //    else
        //    {
        //        btnStartProcess.Enabled = btnStopProcess.Enabled = !isServiceRunning;
        //    }
        //}
        #endregion
 
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Name != "tbLog")
            {
                chkContinueMode.Checked = false;
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            //(Process as ProcessControl).Robot_Monitor_FullTrayFull(new OperationConfigBase() { InputPara = new List<int>() { 1 } }, new HikCameraDriver { Id = "3680EBF8-D9F8-4E14-8B0D-6E53BE3BB96D" });
 
            //var list = (Process.StationConfig as ProcessConfig).StorageCells;
            //list.Clear();
            //for (int i = 0; i < 20000; i++)
            //{
            //    list.Add(new Bro.Common.RMQBus.CellInfo() { CellCode = Guid.NewGuid().ToString() });
            //}
 
            MessageBox.Show("Done");
        }
    }
}