From 0d10528b430721512e0e93e0d455fcec44207ec9 Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期二, 14 七月 2020 18:27:10 +0800
Subject: [PATCH] 1. 板卡驱动实现运动暂停/继续功能,板卡动作衔接实现暂停/继续 2. 修复部分调试bug 3. 安全光幕/安全门功能调整

---
 src/Bro.M071.Process/UI/M071_MainForm.cs |  198 +++++++++++++++++++++++++++++-------------------
 1 files changed, 119 insertions(+), 79 deletions(-)

diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs
index 7f507bc..6aa59b8 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -53,37 +53,44 @@
             if (string.IsNullOrWhiteSpace(Config.BackgroundImagePath))
                 return;
 
-            this.Invoke(new Action(() =>
+            try
             {
-                try
-                {
-                    Bitmap image = (Bitmap)Image.FromFile(Config.BackgroundImagePath);
-                    cvImage.LoadImage(image);
-                    cvImage.SetScreenSize();
-                }
-                catch (Exception ex)
-                {
-                    LogAsync(new LogMsg(DateTime.Now, "杞藉叆鑳屾櫙鍥惧紓甯�", ex.Message));
-                    return;
-                }
+                this.Invoke(new Action(() =>
+                   {
+                       try
+                       {
+                           Bitmap image = (Bitmap)Image.FromFile(Config.BackgroundImagePath);
+                           cvImage.LoadImage(image);
+                           cvImage.SetScreenSize();
+                       }
+                       catch (Exception ex)
+                       {
+                           LogAsync(new LogMsg(DateTime.Now, "杞藉叆鑳屾櫙鍥惧紓甯�", ex.Message));
+                           return;
+                       }
 
-                cvImage.Elements.Clear();
-                lvMeasures.Items.Clear();
-                txtBarcode.ReadOnly = Config.IsBarcodeManulInputBlocked;
+                       cvImage.Elements.Clear();
+                       lvMeasures.Items.Clear();
 
-                Config.MeasurementUnitCollection.ForEach(u =>
-                {
-                    if (!u.IsEnabled)
-                        return;
+                       txtBarcode.Enabled = !Config.IsBarcodeManualInputBlocked;
 
-                    var ele = new KeyIndicator(u.Id, u.DisplayLocation);
-                    cvImage.Elements.Add(ele);
+                       Config.MeasurementUnitCollection.ForEach(u =>
+                       {
+                           if (!u.IsEnabled)
+                               return;
 
-                    ListViewItem item = new ListViewItem(u.GetDisplayText());
-                    item.Tag = u.Id;
-                    lvMeasures.Items.Add(item);
-                });
-            }));
+                           var ele = new KeyIndicator(u.Id, u.DisplayLocation);
+                           cvImage.Elements.Add(ele);
+
+                           ListViewItem item = new ListViewItem(u.GetDisplayText());
+                           item.Tag = u.Id;
+                           lvMeasures.Items.Add(item);
+                       });
+                   }));
+            }
+            catch (Exception ex)
+            {
+            }
 
             Process_M071.OnClearBarcode -= M071_MainForm_OnClearBarcode;
             Process_M071.OnClearBarcode += M071_MainForm_OnClearBarcode;
@@ -100,6 +107,17 @@
 
             Process_M071.OnFullResetDone -= Process_M071_FullResetDone;
             Process_M071.OnFullResetDone += Process_M071_FullResetDone;
+
+            Config.PropertyChanged -= Config_PropertyChanged;
+            Config.PropertyChanged += Config_PropertyChanged;
+
+            Process_M071.OnElementUpdated -= Process_M071_OnElementUpdated;
+            Process_M071.OnElementUpdated += Process_M071_OnElementUpdated;
+        }
+
+        private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            txtBarcode.Enabled = !Config.IsBarcodeManualInputBlocked;
         }
 
         #region 鍥剧墖鍖哄彸閿彍鍗�
@@ -214,6 +232,26 @@
         }
         #endregion
 
+        #region 鏍囩缁撴灉鏄剧ず
+        private async void Process_M071_OnElementUpdated(Common.Interface.IShapeElement obj)
+        {
+            if (obj is KeyIndicator keyIndicator)
+            {
+                this.Invoke(new Action(() =>
+                {
+                    var ele = cvImage.Elements.FirstOrDefault(u => u.ID == keyIndicator.ID);
+
+                    (ele as KeyIndicator).Text = keyIndicator.Text;
+                    (ele as KeyIndicator).ResultState = keyIndicator.ResultState;
+
+                    this.Invalidate();
+                }));
+            }
+
+            await Task.Delay(100);
+        }
+        #endregion
+
         #region 涓婃柟鐘舵�佸尯
 
         #region 鏉$爜
@@ -252,46 +290,54 @@
         #region 鏈哄彴鐘舵��
         private async void M071_MainForm_MachineStateChanged(MachineState state)
         {
-            lblMachineState.BeginInvoke(new Action(() =>
+            if (lblMachineState.IsHandleCreated)
             {
-                switch (state)
+                lblMachineState.BeginInvoke(new Action(() =>
                 {
-                    case MachineState.Alarm:
-                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Red;
-                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White;
-                        lblMachineState.Text = "璀︽姤";
+                    switch (state)
+                    {
+                        case MachineState.Alarm:
+                            btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Red;
+                            btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White;
+                            lblMachineState.Text = "璀︽姤";
 
-                        btnStartMeasure.Enabled = false;
-                        break;
-                    case MachineState.Pause:
-                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Yellow;
-                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black;
-                        lblMachineState.Text = "鏆傚仠";
+                            btnStartMeasure.Text = "寮�濮嬫祴閲�";
+                            btnStartMeasure.Enabled = false;
+                            break;
+                        case MachineState.Pause:
+                            btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Yellow;
+                            btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black;
+                            lblMachineState.Text = "鏆傚仠";
 
-                        //btnStartMeasure.Text = "鏆傚仠娴嬮噺";
-                        btnStartMeasure.Enabled = true;
-                        break;
-                    case MachineState.Ready:
-                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
-                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White;
-                        lblMachineState.Text = "灏辩华";
+                            btnStartMeasure.Text = "缁х画娴嬮噺";
+                            btnStartMeasure.Enabled = true;
+                            break;
+                        case MachineState.Ready:
+                            btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
+                            btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black;
+                            lblMachineState.Text = "灏辩华";
+                            
+                            btnStartMeasure.Text = "寮�濮嬫祴閲�";
+                            btnStartMeasure.Enabled = true;
+                            break;
+                        case MachineState.Running:
+                            btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Transparent;
+                            btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.DarkGreen;
+                            lblMachineState.Text = "杩愯";
 
-                        btnStartMeasure.Enabled = true;
-                        break;
-                    case MachineState.Running:
-                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
-                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.DarkGreen;
-                        lblMachineState.Text = "杩愯";
+                            btnStartMeasure.Text = "鏆傚仠娴嬮噺";
+                            btnStartMeasure.Enabled = true;
+                            break;
+                        case MachineState.Unknown:
+                            btnStartMeasure.BackColor = lblMachineState.BackColor = SystemColors.Control;
+                            btnStartMeasure.ForeColor = lblMachineState.ForeColor = SystemColors.ControlText;
+                            lblMachineState.Text = "鏈煡";
 
-                        btnStartMeasure.Enabled = true;
-                        break;
-                    case MachineState.Unknown:
-                        btnStartMeasure.BackColor = lblMachineState.BackColor = SystemColors.Control;
-                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = SystemColors.ControlText;
-                        lblMachineState.Text = "鏈煡";
-                        break;
-                }
-            }));
+                            btnStartMeasure.Enabled = false;
+                            break;
+                    }
+                }));
+            }
 
             await Task.Delay(100);
         }
@@ -324,7 +370,7 @@
                     lblProductionState.Text = "NG";
                 }
 
-                btnStartMeasure.Text = "寮�濮嬫祴閲�";
+                //btnStartMeasure.Text = "寮�濮嬫祴閲�";
             }));
             await Task.Delay(100);
         }
@@ -338,6 +384,15 @@
                 lblProductionState.Text = "娴嬭瘯涓�";
 
                 lblCT.Text = "";
+
+                cvImage.Elements.ToList().ForEach(e =>
+                {
+                    if (e is KeyIndicator indicator)
+                    {
+                        indicator.Text = "";
+                        indicator.ResultState = null;
+                    }
+                });
             }));
             await Task.Delay(100);
         }
@@ -347,9 +402,6 @@
 
         private async void btnStartMeasure_Click(object sender, EventArgs e)
         {
-            btnStartMeasure.Enabled = false;
-            bool isBreak = false;
-
             if (btnStartMeasure.Text == "寮�濮嬫祴閲�")
             {
                 await Task.Run(() =>
@@ -360,31 +412,19 @@
                     }
                     catch (Exception ex)
                     {
-                        isBreak = true;
-
                         LogAsync(DateTime.Now, "娴佺▼寮傚父", ex.Message);
                         Process_M071.ExceptionRaisedInMonitor(ex);
-
-                        btnStartMeasure.Text = "寮�濮嬫祴閲�";
-
                     }
                 });
-
-                if (!isBreak)
-                    btnStartMeasure.Text = "鏆傚仠娴嬮噺";
             }
             else if (btnStartMeasure.Text == "缁х画娴嬮噺")
             {
-                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 0 } }, null, null);
-                btnStartMeasure.Text = "鏆傚仠娴嬮噺";
+                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 10 } }, null, null);
             }
             else
             {
-                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 1 } }, null, null);
-                btnStartMeasure.Text = "缁х画娴嬮噺";
+                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 11 } }, null, null);
             }
-
-            btnStartMeasure.Enabled = true;
         }
 
         #region 澶嶄綅鎿嶄綔
@@ -405,7 +445,7 @@
                 Process_M071.Reset(null, null, null);
             }
 
-            Process_M071.ResetTimer.Change(-1, 1000 * 5);
+            Process_M071.ResetTimer.Change(1000 * 5, -1);
         }
 
         private void btnReset_MouseUp(object sender, MouseEventArgs e)

--
Gitblit v1.8.0