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.M071.Process/M071Process.cs |  139 +++++++++++++++++++++++++++++++++++-----------
 1 files changed, 105 insertions(+), 34 deletions(-)

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

--
Gitblit v1.8.0