From 78584911d0457ad9fc26d9dfc6f374b7ef531c0f Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期日, 22 十一月 2020 13:45:09 +0800
Subject: [PATCH] 1. 添加操作员输入和界面显示 2. 添加通过输入窗体 3. 添加webservice调用帮助类 4. M071添加MES数据检查和数据上传功能,添加相关界面显示和流程控制

---
 src/Bro.M071.Process/M071Process.cs |  103 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 74 insertions(+), 29 deletions(-)

diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 155f253..1de633a 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -50,7 +50,6 @@
 
         string _precision = "f3";
 
-
         public override void Open()
         {
             InitialSetting();
@@ -71,6 +70,9 @@
             {
                 _precision = "f" + Config.Precision;
             }
+
+            IncomingCheckMethod = InitialMESWebServiceMethod(IncomingCheckMethodName, out IncomingCheckObj);
+            DataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj);
         }
 
         private void InitialMotionCardBaseAxisAlarm()
@@ -183,8 +185,6 @@
         }
         #endregion
 
-        public string BarCode { get; set; }
-
         List<ProductionMeasurement> productionList = new List<ProductionMeasurement>();
 
         [ProcessMethod("", "StartJob", "寮�濮嬫壂鎻�", InvokeType.TestInvoke)]
@@ -195,22 +195,39 @@
                 throw new ProcessException(SafetyMsg, null, ExceptionLevel.Fatal);
             }
 
+            string hint = "";
             if (MachineState != MachineState.Ready)
-                throw new ProcessException("鏈哄彴鏈氨缁紝璇峰嬁寮�濮嬫祴閲�", null, ExceptionLevel.Fatal);
+            {
+                hint = "鏈哄彴鏈氨缁紝璇峰嬁寮�濮嬫祴閲�";
+                OnCheckHintUpload?.Invoke(hint, true);
+                throw new ProcessException(hint, null, ExceptionLevel.Fatal);
+            }
 
             if (string.IsNullOrWhiteSpace(BarCode))
             {
+                hint = "鏈緭鍏ヤ骇鍝佹潯鐮侊紝璇峰嬁寮�濮嬫祴閲�";
                 OnClearBarcode?.Invoke();
-                throw new ProcessException("鏈緭鍏ヤ骇鍝佹潯鐮侊紝璇峰嬁寮�濮嬫祴閲�");
+                OnCheckHintUpload?.Invoke(hint, true);
+                throw new ProcessException(hint);
             }
 
             MachineState = MachineState.Running;
+
+            OnCheckHintUpload?.Invoke(hint, true);
             OnMeasureStart?.Invoke();
 
-            var measurements = Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().DeepSerializeClone();
-            measurements.ForEach(m =>
+            //var measurements = Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().DeepSerializeClone();
+            //measurements.ForEach(m =>
+            //{
+            //    m.InitialKeyUnitMeasureChanged();
+            //});
+
+            List<MeasurementUnit> measurements = new List<MeasurementUnit>();
+            Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().ForEach(u =>
             {
+                var m = u.Copy();
                 m.InitialKeyUnitMeasureChanged();
+                measurements.Add(m);
             });
 
             var pMeasure = new ProductionMeasurement()
@@ -219,6 +236,8 @@
                 Measurements = measurements,
                 StartTime = DateTime.Now,
             };
+
+            BarCode = "";
 
             var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
             if (existedProduction != null)
@@ -283,8 +302,9 @@
                       RunImageHandle(s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements);
                   });
 
-            BarCode = "";
             LogAsync(DateTime.Now, $"{pMeasure.Barcode}娴嬮噺鍔ㄤ綔瀹屾垚", "");
+
+            GC.Collect(0, GCCollectionMode.Optimized);
 
             return new ProcessResponse(true);
         }
@@ -363,7 +383,8 @@
                             {
                                 if (m.KeyUnitCollection.Any(k => k.IsDone == false))
                                 {
-                                    m.Spec.ActualValue = -999;
+                                    //m.Spec.ActualValue = -999;
+                                    m.Spec.ActualValue = null;
                                 }
                                 else
                                 {
@@ -371,7 +392,8 @@
                                     if (!_halconToolDict.ContainsKey(toolKey))
                                     {
                                         LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}绠楁硶鏈垵濮嬪寲", "");
-                                        m.Spec.ActualValue = -999;
+                                        //m.Spec.ActualValue = -999;
+                                        m.Spec.ActualValue = null;
                                     }
                                     else
                                     {
@@ -381,7 +403,8 @@
                                         if (array == null || array.Length == 0)
                                         {
                                             LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}鏈兘鑾峰彇瀵瑰簲妫�娴嬪��", "");
-                                            m.Spec.ActualValue = -999;
+                                            //m.Spec.ActualValue = -999;
+                                            m.Spec.ActualValue = null;
                                         }
                                         else
                                         {
@@ -390,7 +413,8 @@
                                             if (!_halconToolDict[toolKey].RunProcedure(out string error))
                                             {
                                                 LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}绠楁硶寮傚父,{error}", "");
-                                                m.Spec.ActualValue = -999;
+                                                //m.Spec.ActualValue = -999;
+                                                m.Spec.ActualValue = null;
                                             }
                                             else
                                             {
@@ -404,7 +428,8 @@
                                 //LogAsync(DateTime.Now, $"{m.GetDisplayText()}妫�娴嬬粨鏋�", $"{((m.Spec.MeasureResult ?? false) ? "OK" : "NG")}");
 
                                 KeyIndicator indicator = new KeyIndicator(m.Id, m.DisplayLocation);
-                                indicator.Text = (m.Spec.ActualValue == null || m.Spec.ActualValue == -999) ? "NA" : m.Spec.ActualValue.Value.ToString(_precision);
+                                //indicator.Text = (m.Spec.ActualValue == null || m.Spec.ActualValue == -999) ? "NA" : m.Spec.ActualValue.Value.ToString(_precision);
+                                indicator.Text = m.Spec.ActualValue == null ? "NA" : m.Spec.ActualValue.Value.ToString(_precision);
                                 indicator.ResultState = m.Spec.MeasureResult;
                                 pMeasure.ElementList.Add(indicator);
                                 //杈撳嚭鍥惧舰鍩哄厓鍒扮晫闈� 
@@ -424,9 +449,27 @@
                 }
 
                 pMeasure.EndTime = DateTime.Now;
-                bool pResult = pMeasure.Measurements.All(u => u.Spec.MeasureResult == true);
-                pMeasure.PResult = pResult ? "OK" : "NG";
-                OnUpdateResult?.Invoke(DateTime.Now, pResult ? 1 : 0);
+                //bool pResult = pMeasure.Measurements.All(u => u.Spec.MeasureResult == true);
+                //pMeasure.PResult = pResult ? "OK" : "NG";
+                //OnUpdateResult?.Invoke(DateTime.Now, pResult ? 1 : 0);
+                //OnUpdateCT?.Invoke((float)(pMeasure.EndTime.Value - pMeasure.StartTime.Value).TotalSeconds);
+
+                int result = -1;
+                if (pMeasure.Measurements.Any(u => u.Spec.MeasureResult == null))
+                {
+                    pMeasure.PResult = "NA";
+                }
+                else if (pMeasure.Measurements.Any(u => u.Spec.MeasureResult == false))
+                {
+                    pMeasure.PResult = "NG";
+                    result = 0;
+                }
+                else
+                {
+                    pMeasure.PResult = "OK";
+                    result = 1;
+                }
+                OnUpdateResult?.Invoke(DateTime.Now, result);
                 OnUpdateCT?.Invoke((float)(pMeasure.EndTime.Value - pMeasure.StartTime.Value).TotalSeconds);
 
                 LogAsync(DateTime.Now, $"{pMeasure.Barcode} 妫�娴嬪畬鎴愶紝缁撴灉 {pMeasure.PResult}", "");
@@ -436,9 +479,10 @@
 
                 var measurementUnitResultAndKeyUnitDataSet = GetMeasurementUnitResultAndKeyUnitData(pMeasure);
 
-                //MES杈撳嚭 todo
-                if (Config.IsEnableMESUpload)
+                if (pMeasure.PResult != "NA")
                 {
+                    //MES杈撳嚭
+                    MESCheckDataUpload(pMeasure);
                 }
 
                 //Excel鎶ヨ〃杈撳嚭 锛堝崟涓骇鍝佺殑excel瀵煎嚭锛�
@@ -452,6 +496,7 @@
 
                 productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode);
                 pMeasure.Dispose();
+                //LogAsync(DateTime.Now, $"{pMeasure.Barcode}浜у搧淇℃伅閲婃斁瀹屾垚", JsonConvert.SerializeObject(pMeasure));
             }
         }
 
@@ -729,8 +774,6 @@
 
                         #region RawData
                         {
-                            //rawDataSheet = package.Workbook.Worksheets["RawData"];
-
                             int rowDataStartCol = rawDataSheet.Dimension.Columns;
                             var barcodeCell = rawDataSheet.Cells[1, rowDataStartCol + 1, 1, rowDataStartCol + 4];
                             barcodeCell.Merge = true;
@@ -777,11 +820,6 @@
                         {
                             int slantStartCol = slantSheet.Dimension.Columns;
 
-                            //var barcodeCell = slantSheet.Cells[1, slantStartCol + 1, 1, slantStartCol + 2];
-                            //barcodeCell.Merge = true;
-                            //barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode;
-                            //SetTitleCell(barcodeCell);
-
                             var barcodeCell = slantSheet.Cells[1, slantStartCol + 1];
                             barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode;
                             SetTitleCell(barcodeCell);
@@ -789,10 +827,6 @@
                             var valueCell = slantSheet.Cells[2, slantStartCol + 1];
                             valueCell.Value = "Value";
                             SetTitleCell(valueCell);
-
-                            //var resultCell = slantSheet.Cells[2, slantStartCol + 2];
-                            //resultCell.Value = "Result";
-                            //SetTitleCell(resultCell);
 
                             slantMeasures.ForEach(m =>
                             {
@@ -937,6 +971,11 @@
                         #endregion
 
                         package.Save();
+
+                        rawDataSheet.Dispose();
+                        slantSheet.Dispose();
+                        alignmentSheet.Dispose();
+                        rowAlignmentSheet.Dispose();
                     };
                 }
             });
@@ -1191,11 +1230,17 @@
                     });
 
                     image.Dispose();
+                    image = null;
                 }
                 //);
 
                 imgSet.HImage.Dispose();
+                imgSet.HImage = null;
+                imgSet.Dispose();
+
                 images.Dispose();
+                images = null;
+
                 //if (count.I != 1)
                 //{
                 //    hImage?.Dispose();

--
Gitblit v1.8.0