From 17db44bdab7772f465969bf778d417e08bf8a5f0 Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期六, 04 七月 2020 17:58:34 +0800
Subject: [PATCH] 1. 大/小复位,机台状态 2. 板卡操作配置复数化 3. 界面日志输出机制修改 4. M071主界面CT,测量结果,测量状态,机台状态输出

---
 src/Bro.UI.Config/MenuForms/FrmStatistic.cs            |    6 
 src/Bro.M071.Process/UI/M071_MainForm.cs               |  183 ++++++++++++++++++++
 src/Bro.Common.Device/DeviceBase/MotionCardBase.cs     |    3 
 src/Bro.Common.Device/Helper/AspectHelper.cs           |    2 
 src/Bro.M071.Process/M071Process_MotionCard.cs         |   37 +++
 src/Bro.M071.Process/UI/M071_MainForm.Designer.cs      |   65 +++++-
 src/Bro.M071.Process/packages.config                   |    1 
 src/Bro.Process/ProcessControl.cs                      |   31 +++
 src/Bro.UI.Config/MainFrm.cs                           |   13 +
 src/Bro.UI.Config/MenuForms/FrmTest.cs                 |    3 
 src/Bro.M071.Process/M071Process.cs                    |  139 +++++++++++---
 src/Bro.UI.Config/MenuForms/FrmCalib.cs                |    3 
 src/Bro.M071.Process/Bro.M071.Process.csproj           |    5 
 src/Bro.UI.Config/Ctrls/CtrlMethodInvoke.cs            |   17 +
 src/Bro.M071.Process/M071Models.cs                     |    4 
 src/Bro.Common.Model/Interface/IMenuNode.cs            |    2 
 src/Bro.UI.Model.Winform/UI/DockContent/MenuFrmBase.cs |    2 
 17 files changed, 440 insertions(+), 76 deletions(-)

diff --git a/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs b/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
index 2091140..1a997ae 100644
--- a/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
+++ b/src/Bro.Common.Device/DeviceBase/MotionCardBase.cs
@@ -138,7 +138,7 @@
         [Category("鏉垮崱鎿嶄綔")]
         [Description("鏉垮崱鎿嶄綔閰嶇疆鍩虹被闆嗗悎锛屼緷娆℃墽琛�")]
         [TypeConverter(typeof(CollectionCountConvert))]
-        [Editor(typeof(ComplexCollectionEditor<MotionCardOperationConfigBase>), typeof(UITypeEditor))]
+        [Editor(typeof(ComplexCollectionEditor<MotionCardOperationSet>), typeof(UITypeEditor))]
         public List<MotionCardOperationSet> OperationCollection { get; set; } = new List<MotionCardOperationSet>();
 
         public string GetDisplayText()
@@ -155,6 +155,7 @@
         [TypeConverter(typeof(CollectionCountConvert))]
         [Editor(typeof(IORefrenceItemCollectionEditor), typeof(UITypeEditor))]
         public List<IORefrenceItem> PreCheckIOCollection { get; set; } = new List<IORefrenceItem>();
+
         [Category("IO鎿嶄綔閰嶇疆")]
         [Description("瓒呮椂璁剧疆锛屽崟浣嶏細ms")]
         [DisplayName("IO棰勬鏌ヨ秴鏃�")]
diff --git a/src/Bro.Common.Device/Helper/AspectHelper.cs b/src/Bro.Common.Device/Helper/AspectHelper.cs
index 6d9cf36..b864177 100644
--- a/src/Bro.Common.Device/Helper/AspectHelper.cs
+++ b/src/Bro.Common.Device/Helper/AspectHelper.cs
@@ -88,7 +88,7 @@
             //    new ProcessException(ex);
             //}
 
-            args.FlowBehavior = FlowBehavior.ThrowException;
+            args.FlowBehavior = FlowBehavior.Return;
         }
     }
     #endregion
diff --git a/src/Bro.Common.Model/Interface/IMenuNode.cs b/src/Bro.Common.Model/Interface/IMenuNode.cs
index bd434b3..88954b2 100644
--- a/src/Bro.Common.Model/Interface/IMenuNode.cs
+++ b/src/Bro.Common.Model/Interface/IMenuNode.cs
@@ -25,7 +25,7 @@
 
     public interface ILogOutput
     {
-        Action<LogMsg> OnLogMsgOutput { get; set; }
+        event Action<LogMsg> OnLogMsgOutput;
         void LogDisplay(LogMsg msg);
     }
 }
diff --git a/src/Bro.M071.Process/Bro.M071.Process.csproj b/src/Bro.M071.Process/Bro.M071.Process.csproj
index e251945..d305bfc 100644
--- a/src/Bro.M071.Process/Bro.M071.Process.csproj
+++ b/src/Bro.M071.Process/Bro.M071.Process.csproj
@@ -12,6 +12,8 @@
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
     <Deterministic>true</Deterministic>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -90,6 +92,9 @@
     <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
     </Reference>
+    <Reference Include="PostSharp, Version=6.2.7.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7, processorArchitecture=MSIL">
+      <HintPath>..\..\packages\PostSharp.Redist.6.2.7\lib\net45\PostSharp.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
diff --git a/src/Bro.M071.Process/M071Models.cs b/src/Bro.M071.Process/M071Models.cs
index a5c4137..43d9a18 100644
--- a/src/Bro.M071.Process/M071Models.cs
+++ b/src/Bro.M071.Process/M071Models.cs
@@ -209,6 +209,10 @@
 
         public List<IShapeElement> ElementList = new List<IShapeElement>();
 
+        public DateTime? StartTime = null;
+
+        public DateTime? EndTime = null;
+
         public event PropertyChangedEventHandler PropertyChanged;
 
         public void Dispose()
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 65f74a9..2358e3e 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -13,6 +13,7 @@
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
+using static Bro.Common.Helper.EnumHelper;
 
 namespace Bro.M071.Process
 {
@@ -35,6 +36,8 @@
         public event Action OnMeasureStart;
         public event Action OnClearBarcode;
         public event Action<IShapeElement> OnElementUpdated;
+        public event Action<MachineState> OnMachineStateChanged;
+        public event Action OnFullResetDone;
         #endregion
 
         public override void Open()
@@ -43,15 +46,8 @@
 
             base.Open();
 
-            CheckMachineState();
-        }
-
-        /// <summary>
-        /// 妫�鏌ヨ澶囩姸鎬�
-        /// </summary>
-        private void CheckMachineState()
-        {
-            //throw new NotImplementedException();
+            Reset(null, null, null);
+            FullReset(null);
         }
 
         private void InitialSetting()
@@ -125,29 +121,23 @@
             });
         }
 
-        #region InitialHalconTool
-        //protected override void InitialHalconTool()
-        //{
-        //    base.InitialHalconTool();
-
-        //    Config.SnapshotPointCollection.ForEach(u =>
-        //    {
-        //        u.GetHalconToolPathList().ForEach(path =>
-        //        {
-        //            if (!string.IsNullOrWhiteSpace(path))
-        //            {
-        //                string directoryPath = Path.GetDirectoryName(path);
-        //                string fileName = Path.GetFileNameWithoutExtension(path);
-
-        //                HDevEngineTool tool = new HDevEngineTool(directoryPath);
-        //                tool.LoadProcedure(fileName);
-
-        //                //浣跨敤鈥渱鈥濅綔涓洪棿闅旂
-        //                _halconToolDict[u.Id + "|" + path] = tool;
-        //            }
-        //        });
-        //    });
-        //}
+        #region 娴佺▼涓姏鍑哄紓甯�
+        public override void ExceptionRaisedInMonitor(Exception ex)
+        {
+            if (ex is ProcessException pEx)
+            {
+                if (pEx.Level >= ExceptionLevel.Fatal)
+                {
+                    RaisedAlarm(pEx.Message);
+                    MachineState = MachineState.Alarm;
+                }
+            }
+            else
+            {
+                RaisedAlarm(ex.Message);
+                MachineState = MachineState.Alarm;
+            }
+        }
         #endregion
 
         public string BarCode { get; set; }
@@ -157,12 +147,16 @@
         [ProcessMethod("", "StartJob", "寮�濮嬫壂鎻�", InvokeType.TestInvoke)]
         public ProcessResponse StartJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
         {
+            if (MachineState != MachineState.Ready)
+                throw new ProcessException("鏈哄彴鏈氨缁紝璇峰嬁寮�濮嬫祴閲�", null, ExceptionLevel.Fatal);
+
             if (string.IsNullOrWhiteSpace(BarCode))
             {
                 OnClearBarcode?.Invoke();
                 throw new ProcessException("鏈緭鍏ヤ骇鍝佹潯鐮侊紝璇峰嬁寮�濮嬫祴閲�");
             }
 
+            MachineState = MachineState.Running;
             OnMeasureStart?.BeginInvoke(null, null);
 
             var measurements = Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().DeepSerializeClone();
@@ -175,6 +169,7 @@
             {
                 Barcode = BarCode,
                 Measurements = measurements,
+                StartTime = DateTime.Now,
             };
 
             var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
@@ -206,14 +201,25 @@
                       var response = motionDevice.Run(s.MotionOp.OpConfig);
                       if (!response.Result)
                       {
-                          throw new ProcessException($"{device.Name}寮傚父锛寋response.Message}", null, ExceptionLevel.Info);
+                          throw new ProcessException($"{device.Name}寮傚父锛寋response.Message}", null, ExceptionLevel.Fatal);
                       }
 
                       CameraBase camera = DeviceCollection.FirstOrDefault(u => u.Id == s.CameraOp.Device) as CameraBase;
                       if (camera == null)
                           return;
 
-                      HImage hImage = CollectHImage(camera, s.CameraOp.OpConfig, out string imgSetId);
+                      string imgSetId = "";
+                      HImage hImage = null;
+                      try
+                      {
+                          hImage = CollectHImage(camera, s.CameraOp.OpConfig, out imgSetId);
+                      }
+                      catch (ProcessException pEx)
+                      {
+                          pEx.Level = ExceptionLevel.Fatal;
+                          throw pEx;
+                      }
+
                       if (string.IsNullOrWhiteSpace(imgSetId))
                       {
                           return;
@@ -223,9 +229,64 @@
                   });
 
             BarCode = "";
+            LogAsync(DateTime.Now, $"{pMeasure.Barcode}娴嬮噺鍔ㄤ綔瀹屾垚", "");
 
             return new ProcessResponse(true);
         }
+
+        #region 鍙屾墜鍚姩
+        bool isLeftStart = false;
+        bool IsLeftStart
+        {
+            get => isLeftStart;
+            set
+            {
+                isLeftStart = value;
+                StartCheck();
+            }
+        }
+
+        bool isRightStart = false;
+        bool IsRightStart
+        {
+            get => isRightStart;
+            set
+            {
+                isRightStart = value;
+                StartCheck();
+            }
+        }
+
+        private void StartCheck()
+        {
+            if (isRightStart && isLeftStart)
+            {
+                StartJob(null, null, null);
+            }
+        }
+
+        [ProcessMethod("", "Start_Left", "宸︽墜鍚姩", InvokeType.TestInvoke)]
+        public ProcessResponse Start_Left(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+        {
+            if (opConfig.InputPara != null && opConfig.InputPara.Count > 0)
+            {
+                IsLeftStart = opConfig.InputPara[0] == 1;
+            }
+
+            return new ProcessResponse();
+        }
+
+        [ProcessMethod("", "Start_Right", "鍙虫墜鍚姩", InvokeType.TestInvoke)]
+        public ProcessResponse Start_Right(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+        {
+            if (opConfig.InputPara != null && opConfig.InputPara.Count > 0)
+            {
+                IsRightStart = opConfig.InputPara[0] == 1;
+            }
+
+            return new ProcessResponse();
+        }
+        #endregion
 
         #region 绉佹湁鏂规硶
         private void MeasureProduction_PropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -289,6 +350,16 @@
                         return;
                     }
 
+                    pMeasure.EndTime = DateTime.Now;
+                    bool pResult = pMeasure.Measurements.All(u => u.Spec.MeasureResult == true);
+                    OnUpdateResult?.Invoke(DateTime.Now, pResult ? 1 : 0);
+                    OnUpdateCT?.Invoke((float)(pMeasure.EndTime.Value - pMeasure.StartTime.Value).TotalSeconds);
+
+                    LogAsync(DateTime.Now, $"{pMeasure.Barcode} 妫�娴嬪畬鎴愶紝缁撴灉 {(pResult ? "OK" : "NG")}", "");
+
+                    if (MachineState == MachineState.Running)
+                        MachineState = MachineState.Ready;
+
                     //MES杈撳嚭 todo
 
                     //Excel鎶ヨ〃杈撳嚭 todo
diff --git a/src/Bro.M071.Process/M071Process_MotionCard.cs b/src/Bro.M071.Process/M071Process_MotionCard.cs
index 514b46d..98ce638 100644
--- a/src/Bro.M071.Process/M071Process_MotionCard.cs
+++ b/src/Bro.M071.Process/M071Process_MotionCard.cs
@@ -16,11 +16,11 @@
 {
     public partial class M071Process
     {
-        Timer _resetTimer = null;
+        public Timer ResetTimer = null;
         const int FULLRESETTIME = 5;
 
         MachineState machineState = MachineState.Unknown;
-        MachineState MachineState
+        public MachineState MachineState
         {
             get => machineState;
             set
@@ -40,6 +40,8 @@
                     default:
                         break;
                 }
+
+                OnMachineStateChanged?.Invoke(machineState);
             }
         }
 
@@ -66,21 +68,26 @@
 
             MotionCardDefaultRun("Reset", ref opConfig, ref invokeDevice);
 
-            if (_resetTimer == null)
+            RaisedAlarm("");
+            MachineState = MachineState.Ready;
+
+            if (ResetTimer == null)
             {
-                _resetTimer = new Timer(FullReset, null, -1, -1);
+                ResetTimer = new Timer(FullReset, null, -1, -1);
             }
 
             if (opConfig.InputPara.Count > 0)
             {
                 //澶у浣嶄俊鍙�
-                _resetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1);
+                ResetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1);
             }
 
             //if (invokeDevice is MotionCardBase motionCard)
             //{
             //    motionCard.Run(opConfig);
             //}
+
+            LogAsync(DateTime.Now, "鏅�氬浣嶅姩浣滃畬鎴�", "");
 
             return new ProcessResponse(true);
         }
@@ -116,8 +123,14 @@
             //    motionCard.Run(opConfig);
             //}
 
-            //MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice);
+            MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice);
 
+            productionList.ForEach(u => u.Dispose());
+            productionList.Clear();
+
+            OnFullResetDone?.Invoke();
+
+            LogAsync(DateTime.Now, "澶у浣嶅姩浣滃畬鎴�", "");
             return new ProcessResponse(true);
         }
 
@@ -135,14 +148,22 @@
         [ProcessMethod("", "PauseJob", "鏆傚仠娴佺▼", InvokeType.TestInvoke)]
         public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
         {
-            if (_pauseHandle.WaitResult)
+            if (!_pauseHandle.WaitResult)
             {
                 #region 鏉垮崱鏆傚仠鍔ㄤ綔
                 #endregion
 
                 _pauseHandle.WaitHandle.Reset();
             }
-            else
+
+            _pauseHandle.WaitResult = !_pauseHandle.WaitResult;
+            return new ProcessResponse(_pauseHandle.WaitResult);
+        }
+
+        [ProcessMethod("", "ResumeJob", "缁х画娴佺▼", InvokeType.TestInvoke)]
+        public ProcessResponse ResumeJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+        {
+            if (_pauseHandle.WaitResult)
             {
                 #region 鏉垮崱鎭㈠鍔ㄤ綔
                 #endregion
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
index b83b97d..25f0b07 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
@@ -45,7 +45,10 @@
             this.splitContainer1 = new System.Windows.Forms.SplitContainer();
             this.lvMeasures = new System.Windows.Forms.ListView();
             this.propGridKeyIndicator = new System.Windows.Forms.PropertyGrid();
+            this.btnStartMeasure = new System.Windows.Forms.Button();
+            this.btnReset = new System.Windows.Forms.Button();
             this.contextMenuStrip1.SuspendLayout();
+            this.plImage.SuspendLayout();
             this.tscEditLocation.ContentPanel.SuspendLayout();
             this.tscEditLocation.SuspendLayout();
             this.tableLayoutPanel1.SuspendLayout();
@@ -113,7 +116,7 @@
             this.lblProductionState.AutoSize = true;
             this.lblProductionState.BackColor = System.Drawing.Color.Lime;
             this.lblProductionState.Font = new System.Drawing.Font("Tahoma", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.World, ((byte)(134)));
-            this.lblProductionState.ForeColor = System.Drawing.Color.White;
+            this.lblProductionState.ForeColor = System.Drawing.Color.DarkGreen;
             this.lblProductionState.Location = new System.Drawing.Point(405, 13);
             this.lblProductionState.Name = "lblProductionState";
             this.lblProductionState.Size = new System.Drawing.Size(39, 24);
@@ -125,7 +128,7 @@
             this.lblMachineState.AutoSize = true;
             this.lblMachineState.BackColor = System.Drawing.Color.Lime;
             this.lblMachineState.Font = new System.Drawing.Font("Tahoma", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.World, ((byte)(134)));
-            this.lblMachineState.ForeColor = System.Drawing.Color.White;
+            this.lblMachineState.ForeColor = System.Drawing.Color.DarkGreen;
             this.lblMachineState.Location = new System.Drawing.Point(22, 12);
             this.lblMachineState.Name = "lblMachineState";
             this.lblMachineState.Size = new System.Drawing.Size(79, 24);
@@ -138,6 +141,7 @@
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
             this.plImage.ContextMenuStrip = this.contextMenuStrip1;
+            this.plImage.Controls.Add(this.tscEditLocation);
             this.plImage.Location = new System.Drawing.Point(1, 47);
             this.plImage.Name = "plImage";
             this.plImage.Size = new System.Drawing.Size(796, 304);
@@ -149,11 +153,11 @@
             // tscEditLocation.ContentPanel
             // 
             this.tscEditLocation.ContentPanel.Controls.Add(this.tableLayoutPanel1);
-            this.tscEditLocation.ContentPanel.Size = new System.Drawing.Size(209, 326);
+            this.tscEditLocation.ContentPanel.Size = new System.Drawing.Size(209, 279);
             this.tscEditLocation.Dock = System.Windows.Forms.DockStyle.Right;
-            this.tscEditLocation.Location = new System.Drawing.Point(591, 0);
+            this.tscEditLocation.Location = new System.Drawing.Point(587, 0);
             this.tscEditLocation.Name = "tscEditLocation";
-            this.tscEditLocation.Size = new System.Drawing.Size(209, 351);
+            this.tscEditLocation.Size = new System.Drawing.Size(209, 304);
             this.tscEditLocation.TabIndex = 0;
             this.tscEditLocation.Text = "toolStripContainer1";
             this.tscEditLocation.Visible = false;
@@ -172,7 +176,7 @@
             this.tableLayoutPanel1.RowCount = 2;
             this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
             this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
-            this.tableLayoutPanel1.Size = new System.Drawing.Size(209, 326);
+            this.tableLayoutPanel1.Size = new System.Drawing.Size(209, 279);
             this.tableLayoutPanel1.TabIndex = 0;
             // 
             // btnConfirmEdit
@@ -181,7 +185,7 @@
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
             this.btnConfirmEdit.Font = new System.Drawing.Font("瀹嬩綋", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnConfirmEdit.Location = new System.Drawing.Point(3, 293);
+            this.btnConfirmEdit.Location = new System.Drawing.Point(3, 246);
             this.btnConfirmEdit.Name = "btnConfirmEdit";
             this.btnConfirmEdit.Size = new System.Drawing.Size(98, 30);
             this.btnConfirmEdit.TabIndex = 0;
@@ -195,7 +199,7 @@
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
             this.btnCancelEdit.Font = new System.Drawing.Font("瀹嬩綋", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnCancelEdit.Location = new System.Drawing.Point(107, 293);
+            this.btnCancelEdit.Location = new System.Drawing.Point(107, 246);
             this.btnCancelEdit.Name = "btnCancelEdit";
             this.btnCancelEdit.Size = new System.Drawing.Size(99, 30);
             this.btnCancelEdit.TabIndex = 0;
@@ -218,8 +222,8 @@
             // splitContainer1.Panel2
             // 
             this.splitContainer1.Panel2.Controls.Add(this.propGridKeyIndicator);
-            this.splitContainer1.Size = new System.Drawing.Size(203, 284);
-            this.splitContainer1.SplitterDistance = 163;
+            this.splitContainer1.Size = new System.Drawing.Size(203, 237);
+            this.splitContainer1.SplitterDistance = 136;
             this.splitContainer1.TabIndex = 1;
             // 
             // lvMeasures
@@ -231,7 +235,7 @@
             this.lvMeasures.Location = new System.Drawing.Point(0, 0);
             this.lvMeasures.MultiSelect = false;
             this.lvMeasures.Name = "lvMeasures";
-            this.lvMeasures.Size = new System.Drawing.Size(203, 163);
+            this.lvMeasures.Size = new System.Drawing.Size(203, 136);
             this.lvMeasures.TabIndex = 0;
             this.lvMeasures.UseCompatibleStateImageBehavior = false;
             this.lvMeasures.View = System.Windows.Forms.View.List;
@@ -242,26 +246,59 @@
             this.propGridKeyIndicator.Dock = System.Windows.Forms.DockStyle.Fill;
             this.propGridKeyIndicator.Location = new System.Drawing.Point(0, 0);
             this.propGridKeyIndicator.Name = "propGridKeyIndicator";
-            this.propGridKeyIndicator.Size = new System.Drawing.Size(203, 117);
+            this.propGridKeyIndicator.Size = new System.Drawing.Size(203, 97);
             this.propGridKeyIndicator.TabIndex = 0;
             this.propGridKeyIndicator.ToolbarVisible = false;
+            // 
+            // btnStartMeasure
+            // 
+            this.btnStartMeasure.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+            this.btnStartMeasure.BackColor = System.Drawing.Color.Lime;
+            this.btnStartMeasure.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.btnStartMeasure.Font = new System.Drawing.Font("瀹嬩綋", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.World, ((byte)(134)));
+            this.btnStartMeasure.ForeColor = System.Drawing.Color.DarkGreen;
+            this.btnStartMeasure.Location = new System.Drawing.Point(678, 8);
+            this.btnStartMeasure.Name = "btnStartMeasure";
+            this.btnStartMeasure.Size = new System.Drawing.Size(110, 35);
+            this.btnStartMeasure.TabIndex = 5;
+            this.btnStartMeasure.Text = "寮�濮嬫祴閲�";
+            this.btnStartMeasure.UseVisualStyleBackColor = false;
+            this.btnStartMeasure.Click += new System.EventHandler(this.btnStartMeasure_Click);
+            // 
+            // btnReset
+            // 
+            this.btnReset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+            this.btnReset.BackColor = System.Drawing.Color.Orange;
+            this.btnReset.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.btnReset.Font = new System.Drawing.Font("瀹嬩綋", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.World, ((byte)(134)));
+            this.btnReset.ForeColor = System.Drawing.Color.DarkGreen;
+            this.btnReset.Location = new System.Drawing.Point(531, 8);
+            this.btnReset.Name = "btnReset";
+            this.btnReset.Size = new System.Drawing.Size(141, 35);
+            this.btnReset.TabIndex = 5;
+            this.btnReset.Text = "澶嶄綅锛堥暱鎸�5s澶у浣嶏級";
+            this.btnReset.UseVisualStyleBackColor = false;
+            this.btnReset.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnReset_MouseDown);
+            this.btnReset.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnReset_MouseUp);
             // 
             // M071_MainForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(800, 351);
+            this.Controls.Add(this.btnReset);
+            this.Controls.Add(this.btnStartMeasure);
             this.Controls.Add(this.lblCT);
             this.Controls.Add(this.txtBarcode);
             this.Controls.Add(this.lblProductionState);
             this.Controls.Add(this.lblMachineState);
             this.Controls.Add(this.plImage);
-            this.Controls.Add(this.tscEditLocation);
             this.KeyPreview = true;
             this.Name = "M071_MainForm";
             this.Text = "M071_MainForm";
             this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.M071_MainForm_KeyUp);
             this.contextMenuStrip1.ResumeLayout(false);
+            this.plImage.ResumeLayout(false);
             this.tscEditLocation.ContentPanel.ResumeLayout(false);
             this.tscEditLocation.ResumeLayout(false);
             this.tscEditLocation.PerformLayout();
@@ -293,5 +330,7 @@
         private System.Windows.Forms.Label lblProductionState;
         private System.Windows.Forms.TextBox txtBarcode;
         private System.Windows.Forms.Label lblCT;
+        private System.Windows.Forms.Button btnStartMeasure;
+        private System.Windows.Forms.Button btnReset;
     }
 }
\ No newline at end of file
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs
index 97904b6..63f429e 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -9,6 +9,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using static Bro.Common.Helper.EnumHelper;
 
 namespace Bro.M071.Process.UI
 {
@@ -17,6 +18,7 @@
     {
         Canvas cvImage = new Canvas();
         M071Config Config => Process?.IConfig as M071Config;
+        M071Process Process_M071 => Process as M071Process;
 
         public M071_MainForm()
         {
@@ -69,8 +71,21 @@
 
             txtBarcode.ReadOnly = Config.IsBarcodeManulInputBlocked;
 
-            (Process as M071Process).OnClearBarcode -= M071_MainForm_OnClearBarcode;
-            (Process as M071Process).OnClearBarcode += M071_MainForm_OnClearBarcode;
+            Process_M071.OnClearBarcode -= M071_MainForm_OnClearBarcode;
+            Process_M071.OnClearBarcode += M071_MainForm_OnClearBarcode;
+            Process_M071.OnUpdateResult -= M071_MainForm_UpdateResult;
+            Process_M071.OnUpdateResult += M071_MainForm_UpdateResult;
+            Process_M071.OnUpdateCT -= M071_MainForm_UpdateCT;
+            Process_M071.OnUpdateCT += M071_MainForm_UpdateCT;
+
+            Process_M071.OnMeasureStart -= M071_MainForm_MeasureStart;
+            Process_M071.OnMeasureStart += M071_MainForm_MeasureStart;
+
+            Process_M071.OnMachineStateChanged -= M071_MainForm_MachineStateChanged;
+            Process_M071.OnMachineStateChanged += M071_MainForm_MachineStateChanged;
+
+            Process_M071.OnFullResetDone -= Process_M071_FullResetDone;
+            Process_M071.OnFullResetDone += Process_M071_FullResetDone;
         }
 
         #region 鍥剧墖鍖哄彸閿彍鍗�
@@ -157,7 +172,7 @@
 
         private void txtBarcode_TextChanged(object sender, EventArgs e)
         {
-            (Process as M071Process).BarCode = txtBarcode.Text.Trim();
+            Process_M071.BarCode = txtBarcode.Text.Trim();
         }
 
         private void M071_MainForm_OnClearBarcode()
@@ -166,7 +181,169 @@
         }
         #endregion
 
+        #region 鏈哄彴鐘舵��
+        private async void M071_MainForm_MachineStateChanged(MachineState state)
+        {
+            lblMachineState.BeginInvoke(new Action(() =>
+            {
+                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 = true;
+                        break;
+                    case MachineState.Ready:
+                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
+                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White;
+                        lblMachineState.Text = "灏辩华";
+
+                        btnStartMeasure.Enabled = true;
+                        break;
+                    case MachineState.Running:
+                        btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
+                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.DarkGreen;
+                        lblMachineState.Text = "杩愯";
+
+                        btnStartMeasure.Enabled = true;
+                        break;
+                    case MachineState.Unknown:
+                        btnStartMeasure.BackColor = lblMachineState.BackColor = SystemColors.Control;
+                        btnStartMeasure.ForeColor = lblMachineState.ForeColor = SystemColors.ControlText;
+                        lblMachineState.Text = "鏈煡";
+                        break;
+                }
+            }));
+
+            await Task.Delay(100);
+        }
         #endregion
 
+        #region 浜у搧缁撴灉
+        private async void M071_MainForm_UpdateCT(float ct)
+        {
+            lblCT.BeginInvoke(new Action(() =>
+            {
+                lblCT.Text = ct.ToString("f2") + " 绉�";
+            }));
+            await Task.Delay(100);
+        }
+
+        private async void M071_MainForm_UpdateResult(DateTime arg1, int result)
+        {
+            this.BeginInvoke(new Action(() =>
+            {
+                if (result == 1)
+                {
+                    lblProductionState.BackColor = Color.Green;
+                    lblProductionState.ForeColor = Color.White;
+                    lblProductionState.Text = "OK";
+                }
+                else
+                {
+                    lblProductionState.BackColor = Color.Red;
+                    lblProductionState.ForeColor = Color.White;
+                    lblProductionState.Text = "NG";
+                }
+
+                btnStartMeasure.Text = "寮�濮嬫祴閲�";
+            }));
+            await Task.Delay(100);
+        }
+
+        private async void M071_MainForm_MeasureStart()
+        {
+            this.BeginInvoke(new Action(() =>
+            {
+                lblProductionState.BackColor = SystemColors.Control;
+                lblProductionState.ForeColor = SystemColors.ControlText;
+                lblProductionState.Text = "娴嬭瘯涓�";
+
+                lblCT.Text = "";
+            }));
+            await Task.Delay(100);
+        }
+        #endregion
+
+        #endregion
+
+        private async void btnStartMeasure_Click(object sender, EventArgs e)
+        {
+            btnStartMeasure.Enabled = false;
+            bool isBreak = false;
+
+            if (btnStartMeasure.Text == "寮�濮嬫祴閲�")
+            {
+                await Task.Run(() =>
+                {
+                    try
+                    {
+                        Process_M071.StartJob(null, null, null);
+                    }
+                    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.ResumeJob(null, null, null);
+                btnStartMeasure.Text = "鏆傚仠娴嬮噺";
+            }
+            else
+            {
+                Process_M071.PauseJob(null, null, null);
+                btnStartMeasure.Text = "缁х画娴嬮噺";
+            }
+
+            btnStartMeasure.Enabled = true;
+        }
+
+        #region 澶嶄綅鎿嶄綔
+        private async void Process_M071_FullResetDone()
+        {
+            btnStartMeasure.BeginInvoke(new Action(() =>
+            {
+                btnStartMeasure.Enabled = true;
+                btnStartMeasure.Text = "寮�濮嬫祴閲�";
+            }));
+            await Task.Delay(100);
+        }
+
+        private void btnReset_MouseDown(object sender, MouseEventArgs e)
+        {
+            if (Process_M071.MachineState != MachineState.Running)
+            {
+                Process_M071.Reset(null, null, null);
+            }
+
+            Process_M071.ResetTimer.Change(-1, 1000 * 5);
+        }
+
+        private void btnReset_MouseUp(object sender, MouseEventArgs e)
+        {
+            Process_M071.ResetTimer.Change(-1, -1);
+        }
+        #endregion
     }
 }
diff --git a/src/Bro.M071.Process/packages.config b/src/Bro.M071.Process/packages.config
index a5ede62..2ebb67c 100644
--- a/src/Bro.M071.Process/packages.config
+++ b/src/Bro.M071.Process/packages.config
@@ -3,5 +3,6 @@
   <package id="Autofac" version="4.9.4" targetFramework="net452" />
   <package id="DockPanelSuite" version="3.0.6" targetFramework="net452" />
   <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
+  <package id="PostSharp.Redist" version="6.2.7" targetFramework="net452" />
   <package id="WeifenLuo.WinFormsUI.Docking" version="2.1.0" targetFramework="net452" />
 </packages>
\ No newline at end of file
diff --git a/src/Bro.Process/ProcessControl.cs b/src/Bro.Process/ProcessControl.cs
index 29d3170..948b3c0 100644
--- a/src/Bro.Process/ProcessControl.cs
+++ b/src/Bro.Process/ProcessControl.cs
@@ -32,8 +32,8 @@
             #region AutoFac娉ㄥ唽
             GlobalVar.Builder.RegisterInstance(this).As<IProcess>().ExternallyOwned();
             GlobalVar.Builder.RegisterInstance(IConfig).As<IProcessConfig>().ExternallyOwned();
-            GlobalVar.Builder.RegisterInstance(DeviceCollection).ExternallyOwned();
-            GlobalVar.Builder.RegisterInstance(ProcessMethodCollection).ExternallyOwned();
+            GlobalVar.Builder.RegisterInstance(DeviceCollection);
+            GlobalVar.Builder.RegisterInstance(ProcessMethodCollection);
 
             //if (isBuild)
             //{
@@ -520,6 +520,9 @@
                 return;
             }
 
+            if (!ProcessInvokePreCheck())
+                return;
+
             IOperationConfig config = monitorSet.OpConfig;
             object res = null;
             int reTryTimes = config.ReTryTimes;
@@ -578,6 +581,8 @@
                         }
 
                         LogAsync(DateTime.Now, methodCode + "寮傚父淇℃伅", ex.GetExceptionMessage());
+
+                        ExceptionRaisedInMonitor(ex);
                     }
                 }
 
@@ -600,6 +605,23 @@
             sw.Stop();
             LogAsync(DateTime.Now, $"{device.Name}璋冪敤{methodCode}瀹屾垚锛岃�楁椂{sw.ElapsedMilliseconds}ms", "");
             TimeRecordCSV(DateTime.Now, device.Name, $"{methodCode}璋冪敤瀹屾垚", (int)sw.ElapsedMilliseconds);
+        }
+
+        /// <summary>
+        /// 娴佺▼鎵ц鐨勯妫�鏌�
+        /// </summary>
+        /// <returns></returns>
+        public virtual bool ProcessInvokePreCheck()
+        {
+            return true;
+        }
+
+        /// <summary>
+        /// 鐩戝惉娴佺▼涓紓甯告姏鍑� 鍦ㄥ叿浣撲笟鍔′腑鍏蜂綋澶勭悊
+        /// </summary>
+        /// <param name="ex">鐩戝惉娴佺▼涓紓甯稿璞�</param>
+        public virtual void ExceptionRaisedInMonitor(Exception ex)
+        {
         }
         #endregion
 
@@ -698,6 +720,11 @@
 
             OnAlarmUpdate?.BeginInvoke(alarmMsg, null, null);
         }
+
+        public virtual void RaisedAlarm(string alarmMsg)
+        {
+            OnAlarmUpdate?.Invoke(alarmMsg);
+        }
         #endregion
 
         #region ILogger
diff --git a/src/Bro.UI.Config/Ctrls/CtrlMethodInvoke.cs b/src/Bro.UI.Config/Ctrls/CtrlMethodInvoke.cs
index 84b159e..382ce1b 100644
--- a/src/Bro.UI.Config/Ctrls/CtrlMethodInvoke.cs
+++ b/src/Bro.UI.Config/Ctrls/CtrlMethodInvoke.cs
@@ -38,7 +38,7 @@
         }
 
         #region ILogoutput
-        public Action<LogMsg> OnLogMsgOutput { get; set; }
+        public event Action<LogMsg> OnLogMsgOutput;
 
         public void LogDisplay(LogMsg msg)
         {
@@ -157,11 +157,18 @@
             {
                 OnLogMsgOutput?.Invoke(new LogMsg(DateTime.Now, $"{_methodCode}璋冪敤寮�濮�", ""));
 
-                ProcessResponse response = _method.Invoke(Process, new object[] { opConfig, _invokeDevice, _sourceDevice }) as ProcessResponse;
-
-                if (response != null)
+                try
                 {
-                    OnLogMsgOutput?.Invoke(new LogMsg(DateTime.Now, $"{_methodCode}璋冪敤瀹屾垚", $"鍙嶉锛歿JsonConvert.SerializeObject(response)}"));
+                    ProcessResponse response = _method.Invoke(Process, new object[] { opConfig, _invokeDevice, _sourceDevice }) as ProcessResponse;
+
+                    if (response != null)
+                    {
+                        OnLogMsgOutput?.Invoke(new LogMsg(DateTime.Now, $"{_methodCode}璋冪敤瀹屾垚", $"鍙嶉锛歿JsonConvert.SerializeObject(response)}"));
+                    }
+                }
+                catch (Exception ex)
+                {
+                    OnLogMsgOutput?.Invoke(new LogMsg(DateTime.Now, $"{_methodCode}璋冪敤寮傚父", ex.GetExceptionMessage()));
                 }
             });
         }
diff --git a/src/Bro.UI.Config/MainFrm.cs b/src/Bro.UI.Config/MainFrm.cs
index e7940f5..f35297d 100644
--- a/src/Bro.UI.Config/MainFrm.cs
+++ b/src/Bro.UI.Config/MainFrm.cs
@@ -90,7 +90,9 @@
         private void RegisterEvent(MenuFrmBase dockFrm)
         {
             dockFrm.OnUploadProcess = DockFrm_OnUploadProcess;
-            dockFrm.OnLogMsgOutput = DockFrm_OnLogMsgOutput;
+
+            dockFrm.OnLogMsgOutput -= DockFrm_OnLogMsgOutput;
+            dockFrm.OnLogMsgOutput += DockFrm_OnLogMsgOutput;
 
             //if (dockFrm is FrmDevices)
             //{
@@ -167,9 +169,14 @@
             });
         }
 
-        private void Process_OnAlarmUpdate(string alarmMsg)
+        private async void Process_OnAlarmUpdate(string alarmMsg)
         {
-            tsslWarning.Text = alarmMsg;
+            this.BeginInvoke(new Action(() =>
+            {
+                tsslWarning.Text = alarmMsg;
+            }));
+
+            await Task.Delay(100);
         }
 
         private ToolStripMenuItem GetMatchNode(ToolStripItemCollection items, string parentMenuCode)
diff --git a/src/Bro.UI.Config/MenuForms/FrmCalib.cs b/src/Bro.UI.Config/MenuForms/FrmCalib.cs
index 4241926..6256b4a 100644
--- a/src/Bro.UI.Config/MenuForms/FrmCalib.cs
+++ b/src/Bro.UI.Config/MenuForms/FrmCalib.cs
@@ -16,7 +16,8 @@
             ctrlMethodInvoker.Dock = DockStyle.Fill;
             plMain.Controls.Add(ctrlMethodInvoker);
 
-            ctrlMethodInvoker.OnLogMsgOutput = OnLogMsgOutput;
+            ctrlMethodInvoker.OnLogMsgOutput -= LogAsync;
+            ctrlMethodInvoker.OnLogMsgOutput += LogAsync;
         }
 
         public override void OnProcessUpdated()
diff --git a/src/Bro.UI.Config/MenuForms/FrmStatistic.cs b/src/Bro.UI.Config/MenuForms/FrmStatistic.cs
index ae8680e..080514a 100644
--- a/src/Bro.UI.Config/MenuForms/FrmStatistic.cs
+++ b/src/Bro.UI.Config/MenuForms/FrmStatistic.cs
@@ -359,8 +359,10 @@
             Process.OnAlarmUpdate -= Process_OnAlarmUpdate;
             Process.OnAlarmUpdate += Process_OnAlarmUpdate;
 
-            Process.OnUpdateResult = UpdateResultOK;
-            Process.OnUpdateCT = UpdateCT;
+            Process.OnUpdateResult -= UpdateResultOK;
+            Process.OnUpdateCT -= UpdateCT;
+            Process.OnUpdateResult += UpdateResultOK;
+            Process.OnUpdateCT += UpdateCT;
 
             _availableTimer = new System.Threading.Timer(AvailableTimerCallBack, null, -1, -1);
             _idleTimer = new System.Threading.Timer(IdleTimerCallBack, null, -1, -1);
diff --git a/src/Bro.UI.Config/MenuForms/FrmTest.cs b/src/Bro.UI.Config/MenuForms/FrmTest.cs
index 3ae4291..fa2733e 100644
--- a/src/Bro.UI.Config/MenuForms/FrmTest.cs
+++ b/src/Bro.UI.Config/MenuForms/FrmTest.cs
@@ -16,7 +16,8 @@
             ctrlMethodInvoker.Dock = DockStyle.Fill;
             plMain.Controls.Add(ctrlMethodInvoker);
 
-            ctrlMethodInvoker.OnLogMsgOutput = OnLogMsgOutput;
+            ctrlMethodInvoker.OnLogMsgOutput -= LogAsync;
+            ctrlMethodInvoker.OnLogMsgOutput += LogAsync;
         }
 
         public override void OnProcessUpdated()
diff --git a/src/Bro.UI.Model.Winform/UI/DockContent/MenuFrmBase.cs b/src/Bro.UI.Model.Winform/UI/DockContent/MenuFrmBase.cs
index d5fde03..c472541 100644
--- a/src/Bro.UI.Model.Winform/UI/DockContent/MenuFrmBase.cs
+++ b/src/Bro.UI.Model.Winform/UI/DockContent/MenuFrmBase.cs
@@ -10,7 +10,7 @@
     public partial class MenuFrmBase : DockContent, IMenuNode, IProcessObserver, ILogOutput
     {
         public Action<string, IProcess> OnUploadProcess { get; set; }
-        public Action<LogMsg> OnLogMsgOutput { get; set; }
+        public event Action<LogMsg> OnLogMsgOutput;
         public string Id { get; set; } = Guid.NewGuid().ToString();
 
         private IProcess process = null;

--
Gitblit v1.8.0