From ab94f070d797edbe927d7d58a460cc4eddf48b03 Mon Sep 17 00:00:00 2001
From: jace.tang <1536884497@qq.com>
Date: 星期一, 13 六月 2022 10:58:40 +0800
Subject: [PATCH] 1.添加检测异常抛出时图片保存动作

---
 MainForm.cs |  640 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 587 insertions(+), 53 deletions(-)

diff --git a/MainForm.cs b/MainForm.cs
index 3c791e3..81c164a 100644
--- a/MainForm.cs
+++ b/MainForm.cs
@@ -19,6 +19,8 @@
 using System.Threading.Tasks;
 using System.Configuration;
 using System.Globalization;
+using Newtonsoft.Json;
+using System.Reflection;
 
 namespace M423project
 {
@@ -85,6 +87,7 @@
 
         private void MainForm_Load(object sender, EventArgs e)
         {
+            InitialStandardBlockReportDir();
             rm.ReduceMemory();
             SetControls();
             DisplayMeasureTTL();
@@ -94,6 +97,8 @@
             #region add by Patrick 2018-07-13
             SetCarrierBarcodeCtrl();
             #endregion
+
+
 
             _downTimeNoAction = Convert.ToInt32(ConfigurationManager.AppSettings["DownTimeNoAction"]);
             Task.Factory.StartNew(() =>
@@ -190,7 +195,8 @@
             if (!opc.CreateGroup())
                 return;
             UpdateOpc();
-            opc.listenEventCreater.ListenEvent += OPCEventHandler;
+            //opc.listenEventCreater.ListenEvent += OPCEventHandler;
+            opc.OnReadItemValueChanged += Opc_OnReadItemValueChanged;
             InitParams();
             imageProcess = new ImageProcess();
             if (!imageProcess.OpenCameras())
@@ -351,6 +357,34 @@
             }
         }
 
+        string _blockDataReportDir = @"D:\Baisreport";
+        string _blockDataForCustomerDir = @"E:\Baisreport";
+        private void InitialStandardBlockReportDir()
+        {
+            _blockDataReportDir = ConfigurationManager.AppSettings["StandardBlockDataDir"];
+            if (string.IsNullOrWhiteSpace(_blockDataReportDir) || !Path.IsPathRooted(_blockDataReportDir))
+            {
+                _blockDataReportDir = @"D:\Baisreport";
+            }
+
+            if (!Directory.Exists(_blockDataReportDir))
+            {
+                Directory.CreateDirectory(_blockDataReportDir);
+            }
+
+            _blockDataForCustomerDir = ConfigurationManager.AppSettings["StandardBlockDataForCustomer"];
+            if (string.IsNullOrWhiteSpace(_blockDataForCustomerDir) || !Path.IsPathRooted(_blockDataForCustomerDir))
+            {
+                _blockDataForCustomerDir = @"E:\Baisreport";
+            }
+
+            if (!Directory.Exists(_blockDataForCustomerDir))
+            {
+                Directory.CreateDirectory(_blockDataForCustomerDir);
+            }
+        }
+
+
         //public void SetDetectionSize(double length, double width, double cellWidth,
         //    MeasureState lengthMeasureState, MeasureState widthMeasureState, int _plateID, string _imageFile, bool isSpotCheck)
         //{
@@ -442,8 +476,71 @@
         //    }
         //}
 
+
+        //public void SetDetectionSize(double length, double width, double cellWidth,
+        //MeasureState lengthMeasureState, MeasureState widthMeasureState, int _plateID, string _imageFile, bool isSpotCheck)
+        //{
+        //    try
+        //    {
+        //        int detectID = CommonUtil.StepControl.GetDetectSizeStepID();
+        //        if (detectID < 0)
+        //        {
+        //            CommonUtil.WriteLog(LogType.Inf, string.Format("no detectid WHEN set size, stepcontrol:{0}", CommonUtil.StepControl.ToString()));
+        //            return;
+        //        }
+        //        var p = (from x in ProductBindingList
+        //                 where x.DetectID == detectID
+        //                 select x
+        //                 ).FirstOrDefault();
+        //        if (p == null)
+        //        {
+        //            CommonUtil.WriteLog(LogType.Inf, string.Format("no detectid when setsize in ProductBindingList:{0}", detectID));
+        //            return;
+        //        }
+
+        //        p.Length = length;
+        //        p.Width = width;
+        //        p.PlateID = _plateID;
+        //        p.LengthResult = lengthMeasureState.ToString();
+        //        p.WidthResult = widthMeasureState.ToString();
+        //        p.IsSpotCheck = isSpotCheck;
+
+        //        measureResultTTL.ProductQuntity++;
+
+        //        if (p.HeightResult == MeasureState.OK.ToString())
+        //            measureResultTTL.HeightPassQuntity++;
+
+        //        if (p.HeightResult == MeasureState.NG.ToString() && p.LengthResult != MeasureState.NA.ToString())
+        //            measureResultTTL.HeightFailQuntity++;
+
+        //        if (p.ProductNoResult == MeasureState.NG.ToString() && p.LengthResult != MeasureState.NA.ToString())
+        //        {
+        //            measureResultTTL.ProductNoFailQuantity++;
+        //        }
+
+        //        if (lengthMeasureState == MeasureState.OK && widthMeasureState == MeasureState.OK)
+        //            measureResultTTL.SizePassQuantity++;
+
+        //        if (lengthMeasureState == MeasureState.NG || widthMeasureState == MeasureState.NG)
+        //            measureResultTTL.SizeFailQuantity++;
+
+        //        //Task.Factory.StartNew(() =>
+        //        //{
+        //        DisplayResult(length, width, cellWidth, _imageFile, p);
+        //        //});
+        //    }
+        //    catch (Exception)
+        //    {
+        //    }
+        //    finally
+        //    {
+        //        //opc.Write(OPCOutputTag.DetectionOK4, true);
+        //    }
+        //}
+
+        List<ProductMeasureResult> _standardResultList = new List<ProductMeasureResult>();
         public void SetDetectionSize(double length, double width, double cellWidth,
-MeasureState lengthMeasureState, MeasureState widthMeasureState, int _plateID, string _imageFile, bool isSpotCheck)
+        MeasureState lengthMeasureState, MeasureState widthMeasureState, int _plateID, string _imageFile, bool isSpotCheck)
         {
             try
             {
@@ -470,32 +567,95 @@
                 p.WidthResult = widthMeasureState.ToString();
                 p.IsSpotCheck = isSpotCheck;
 
-                measureResultTTL.ProductQuntity++;
-
-                if (p.HeightResult == MeasureState.OK.ToString())
-                    measureResultTTL.HeightPassQuntity++;
-
-                if (p.HeightResult == MeasureState.NG.ToString() && p.LengthResult != MeasureState.NA.ToString())
-                    measureResultTTL.HeightFailQuntity++;
-
-                if (p.ProductNoResult == MeasureState.NG.ToString() && p.LengthResult != MeasureState.NA.ToString())
+                string filePath = Path.Combine(_blockDataForCustomerDir, "Standarddata" + DateTime.Now.ToString("yyyyMMdd") + ".csv");
+                string standardCSVFileName = Path.Combine(_blockDataReportDir, "Standarddata" + DateTime.Now.ToString("yyyyMMdd") + ".csv");
+                if (CommonUtil.DetectionOption == DetectionOption.doStandardBlock)
                 {
-                    measureResultTTL.ProductNoFailQuantity++;
+                    if (p.measureHeight.HeightResult != MeasureState.NA)
+                    {
+                        _standardResultList.Add(p);
+
+                        //鍏嬮殕鏂扮殑浜у搧缁撴灉瀵硅薄 閬垮厤瀵瑰師鏈変骇鍝佺粨鏋滃璞″仛淇敼鍚庡奖鍝�
+                        ProductMeasureResult clone = JsonConvert.DeserializeObject<ProductMeasureResult>(JsonConvert.SerializeObject(p));
+
+                        //鍏嬮殕瀵硅薄鐨凜SV鏁版嵁璁板綍                        
+                        detectionData.CSVDataRecord(clone, filePath);
+
+                        detectionData.CSVDataRecord(clone, standardCSVFileName);
+
+                    }
+
+                    if (_standardResultList.Count() == _standardToDoNum)
+                    {
+                        int plateId = _standardResultList[0].PlateID;
+
+                        var stationField = typeof(CompensationZ).GetFields().FirstOrDefault(u => u.Name == "station" + plateId);
+
+                        var avgHeight = _standardResultList.Average(u => u.Height);
+                        var standardHeightValue = (opcConfig.standardHeightLimit.Min + opcConfig.standardHeightLimit.Max) / 2.0;
+                        var curCompensationHeight = stationField.GetValue(opcConfig.compensationZ);
+                        var newHeightComp = standardHeightValue - avgHeight + (double)curCompensationHeight;
+                        //stationField.SetValue(opcConfig.compensationZ, newHeightComp);
+
+                        var avgLenght = _standardResultList.Average(u => u.Length);
+                        var standardLenghtValue = (opcConfig.standardLengthLimit.Min + opcConfig.standardLengthLimit.Max) / 2.0;
+                        var curCompensationLenght = stationField.GetValue(opcConfig.compensationL);
+                        var newLenghtComp = standardLenghtValue - avgLenght + (double)curCompensationLenght;
+
+                        var avgWidth = _standardResultList.Average(u => u.Width);
+                        var standardWidthValue = (opcConfig.standardWidthLimit.Min + opcConfig.standardWidthLimit.Max) / 2.0;
+                        var curCompensationWidth = stationField.GetValue(opcConfig.compensationW);
+                        var newWidthComp = standardWidthValue - avgWidth + (double)curCompensationWidth;
+
+                        string nameH = "Height";
+                        string nameL = "Length";
+                        string nameW = "Width";
+                        string resultStrH = $"宸ヤ綅 {plateId},妫�娴嬮」 {nameH},鍘熷厛琛ュ伩鍊硷細{curCompensationHeight}锛岃绠楄ˉ鍋垮�硷細{newHeightComp}锛屾爣鍑嗗�硷細{standardHeightValue}锛屽钩鍧囧�硷細{avgHeight}";
+                        string resultStrL = $"宸ヤ綅 {plateId},妫�娴嬮」 {nameL},鍘熷厛琛ュ伩鍊硷細{curCompensationLenght}锛岃绠楄ˉ鍋垮�硷細{newLenghtComp}锛屾爣鍑嗗�硷細{standardLenghtValue}锛屽钩鍧囧�硷細{avgLenght}";
+                        string resultStrW = $"宸ヤ綅 {plateId},妫�娴嬮」 {nameW},鍘熷厛琛ュ伩鍊硷細{curCompensationWidth}锛岃绠楄ˉ鍋垮�硷細{newWidthComp}锛屾爣鍑嗗�硷細{standardWidthValue}锛屽钩鍧囧�硷細{avgWidth}";
+
+                        Trace.TraceWarning(resultStrH);
+                        Trace.TraceWarning(resultStrL);
+                        Trace.TraceWarning(resultStrW);
+                        File.AppendAllText(standardCSVFileName, $"\r\n{resultStrH}\r\n");
+                        File.AppendAllText(standardCSVFileName, $"\r\n{resultStrL}\r\n");
+                        File.AppendAllText(standardCSVFileName, $"\r\n{resultStrW}\r\n");
+                        _standardResultList.Clear();
+
+
+                        //鍙嶅皠
+                        //List<string> propList = new List<string>() { "Height", "Length", "Width" };
+                        //typeof(ProductMeasureResult).GetProperties().Where(u => propList.Contains(u.Name)).ToList().ForEach(u =>
+                        //{
+
+
+                        //    double preValue = 0.0;
+                        //    double uAvg = 0.0;
+
+                        //    Type t = opcConfig.standardCompensationZ.GetType();
+                        //    FieldInfo fi = t.GetField(string.Format("station{0}", (CommonUtil.mainForm.PlateID + 1) % 5 + 1));
+                        //    preValue = (double)fi.GetValue(opcConfig.standardCompensationZ);
+                        //    double curCompensation = standardHeightValue - uAvg + preValue;
+
+                        //    string resultStr = $"宸ヤ綅 {plateId}锛屾娴嬮」 {u.Name}锛屽師鍏堣ˉ鍋垮�硷細{preValue}锛岃绠楄ˉ鍋垮�硷細{curCompensation}锛屾爣鍑嗗�硷細{standardHeightValue}锛屽钩鍧囧�硷細{uAvg}";
+                        //Trace.TraceWarning(resultStr);
+
+                        //File.AppendAllText(standardCSVFileName, $"\r\n{resultStr}\r\n");
+                        //});
+                        //_standardResultList.Clear();
+                    }
+
                 }
 
-                if (lengthMeasureState == MeasureState.OK && widthMeasureState == MeasureState.OK)
-                    measureResultTTL.SizePassQuantity++;
-
-                if (lengthMeasureState == MeasureState.NG || widthMeasureState == MeasureState.NG)
-                    measureResultTTL.SizeFailQuantity++;
-
+                UpdateOEE(p);
                 //Task.Factory.StartNew(() =>
                 //{
                 DisplayResult(length, width, cellWidth, _imageFile, p);
                 //});
             }
-            catch (Exception)
+            catch (Exception ex)
             {
+                Trace.TraceError($"SetDetectionSize error,ex:{ex}");
             }
             finally
             {
@@ -503,6 +663,28 @@
             }
         }
 
+        public void UpdateOEE(ProductMeasureResult result)
+        {
+            measureResultTTL.ProductQuntity++;
+            if (result.HeightResult == MeasureState.OK.ToString())
+                measureResultTTL.HeightPassQuntity++;
+
+            if (result.HeightResult == MeasureState.NG.ToString() && result.LengthResult != MeasureState.NA.ToString())
+                measureResultTTL.HeightFailQuntity++;
+
+            if (result.ProductNoResult == MeasureState.NG.ToString() && result.LengthResult != MeasureState.NA.ToString())
+            {
+                measureResultTTL.ProductNoFailQuantity++;
+            }
+
+            if (result.LengthResult == MeasureState.OK.ToString() && result.WidthResult == MeasureState.OK.ToString())
+                measureResultTTL.SizePassQuantity++;
+
+            if (result.LengthResult == MeasureState.NG.ToString() || result.WidthResult == MeasureState.NG.ToString())
+                measureResultTTL.SizeFailQuantity++;
+
+
+        }
         private void DisplayResult(double length, double width, double cellWidth, string _imageFile, ProductMeasureResult p)
         {
             if (this.InvokeRequired)
@@ -628,16 +810,20 @@
         int _continuousNG = 0;
 
         #region PLC 鐩戝惉
-        void OPCEventHandler(object sender, EventTool.ListenEventArgs e)
+
+
+
+        void Opc_OnReadItemValueChanged(OPC.Item item, int itemValue)
         {
             string timeStr = DateTime.Now.ToString("hh:mm:ss fff");
-            OPC.Item item = (OPC.Item)e.IData.Data;
+            //OPC.Item item = (OPC.Item)e.IData.Data;
+
             //CommonUtil.WriteLog(LogType.Inf, string.Format("鎺ユ敹鍒癙LC淇″彿锛歿0}锛屾椂闂达細{1}", item.name, timeStr));
             switch (item.name)
             {
                 case OPCInputTag.TurnDiskReady:
                     TurnDiskReadyTime = DateTime.Now;
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         opc.Write(OPCOutputTag.SpotCheck, false);
                         CommonUtil.StepControl.IncStep();
@@ -741,14 +927,14 @@
                     }
                     break;
                 case OPCInputTag.DetectionStart2:
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         DetectionProcesser hp = heightDetection.Execute;
                         IAsyncResult ar = hp.BeginInvoke(null, null);
                     }
                     break;
                 case OPCInputTag.DetectionStart4:
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         //if (FormCheck._totalQty - FormCheck._finishedQty > 0 && FormCheck._pickCount > 0)
                         //{
@@ -780,7 +966,7 @@
                     break;
                 case OPCInputTag.PLCInitialized:
                     tbPLCMsg.Text = DateTime.Now.ToString("HH:mm:ss") + ":" + OPCInputTag.PLCInitialized + "," + item.value.ToString() + "\r\n" + tbPLCMsg.Text;
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         opc.Write(OPCOutputTag.PCInitialized, true);
                         lbDisplayState.Text = "鍒濆鍖栧畬鎴�";
@@ -805,25 +991,26 @@
                 //    }
                 //    break;
                 case OPCInputTag.EmergencyStop:
+                    if (itemValue == 1)
+                    {
+                        ProductBindingList.Clear();
+                        productTestCollection.Clear();
+                        CommonUtil.StepControl.Clear();
+                        DisplayMeasureTTL();
 
-                    ProductBindingList.Clear();
-                    productTestCollection.Clear();
-                    CommonUtil.StepControl.Clear();
-                    DisplayMeasureTTL();
+                        imageProcess.ClearBarcodeImage();
+                        //Thread.Sleep(1000);
+                        //imageProcess.CloseCameras();
+                        //Thread.Sleep(1000);
+                        //imageProcess.OpenCameras();
+                        CommonUtil.WriteLog(LogType.Inf, "绯荤粺鎬ュ仠");
 
-                    imageProcess.ClearBarcodeImage();
-                    //Thread.Sleep(1000);
-                    //imageProcess.CloseCameras();
-                    //Thread.Sleep(1000);
-                    //imageProcess.OpenCameras();
-                    CommonUtil.WriteLog(LogType.Inf, "绯荤粺鎬ュ仠");
-
-                    //鎶芥鍙傛暟鐨勫埛鏂�
-                    SetCheckInfo();
-
+                        //鎶芥鍙傛暟鐨勫埛鏂�
+                        SetCheckInfo();
+                    }
                     break;
                 case OPCInputTag.Alarm:
-                    int val = int.Parse(item.value.ToString());
+                    int val = itemValue;
                     Task.Factory.StartNew(() =>
                     {
                         UpdateAlarm(val);
@@ -851,27 +1038,27 @@
                 //UpdateAlarm(int.Parse(item.value.ToString()));
                 //break;
                 case OPCInputTag.UploadSignalRequire:
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         UpdateAlarm(101);
                     }
                     break;
                 case OPCInputTag.X1axisLocalPos:
-                    tbX1axisLoPos.Text = item.value.ToString();
+                    tbX1axisLoPos.Text = itemValue.ToString();
                     break;
                 case OPCInputTag.Y1axisLocalPos:
-                    tbY1axisLoPos.Text = item.value.ToString();
+                    tbY1axisLoPos.Text = itemValue.ToString();
                     break;
                 case OPCInputTag.X2axisLocalPos:
-                    tbX2axisLoPos.Text = item.value.ToString();
+                    tbX2axisLoPos.Text = itemValue.ToString();
                     break;
                 case OPCInputTag.Y2axisLocalPos:
-                    tbY2axisLoPos.Text = item.value.ToString();
+                    tbY2axisLoPos.Text = itemValue.ToString();
                     break;
 
                 case OPCInputTag.TestResult:
                     tbPLCMsg.Text = DateTime.Now.ToString("HH:mm:ss") + ":" + OPCInputTag.TestResult + "," + item.value.ToString() + "\r\n" + tbPLCMsg.Text;
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         //鍒ゆ柇OKNG
                         opc.Write(OPCOutputTag.TestResult, false);
@@ -912,7 +1099,7 @@
                     });
                     break;
                 case OPCInputTag.UploadFinished:
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         TimeSpan tsUpload = DateTime.Now - TurnDiskReadyTime;
                         tbUploadTime.Text = string.Format("{0:0.00}", tsUpload.TotalMilliseconds / 1000);
@@ -920,7 +1107,7 @@
                     }
                     break;
                 case OPCInputTag.UnloadFinished:
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         TimeSpan tsUnload = DateTime.Now - TurnDiskReadyTime;
                         tbUnloadTime.Text = string.Format("{0:0.00}", tsUnload.TotalMilliseconds / 1000);
@@ -930,7 +1117,7 @@
 
                 #region add by Patrick 2018-07-12
                 case OPCInputTag.UnloadBatteryDone: //鐢垫睜涓嬫枡鍒颁綅鏃讹紝缁戝畾杞藉叿鏉$爜
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         //opc.Write(OPCInputTag.UnloadBatteryDone, false);
                         int batteryId = CommonUtil.StepControl.GetUnloadBatteryID();
@@ -942,7 +1129,7 @@
                     }
                     break;
                 case OPCInputTag.UnloadTrayMoveToOP: //褰撲笅鏂欒浇鍏峰洖鍒癘P绔紝娓呯┖杞藉叿鏉$爜
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         //opc.Write(OPCInputTag.UnloadTrayMoveToOP, false);
 
@@ -957,7 +1144,7 @@
                     }
                     break;
                 case OPCInputTag.UnloadTrayReady://褰撲笅鏂欒浇鍏峰氨缁紝涓嶅厑璁歌緭鍏ユ潯鐮�
-                    if ((bool)item.value)
+                    if (itemValue == 1)
                     {
                         //opc.Write(OPCInputTag.UnloadTrayReady, false);
                         allowBarcodeFlag = false;
@@ -967,6 +1154,346 @@
 
             }
         }
+
+        //void OPCEventHandler(object sender, EventTool.ListenEventArgs e)
+        //{
+        //    string timeStr = DateTime.Now.ToString("hh:mm:ss fff");
+        //    OPC.Item item = (OPC.Item)e.IData.Data;
+        //    //CommonUtil.WriteLog(LogType.Inf, string.Format("鎺ユ敹鍒癙LC淇″彿锛歿0}锛屾椂闂达細{1}", item.name, timeStr));
+        //    switch (item.name)
+        //    {
+        //        case OPCInputTag.TurnDiskReady:
+        //            TurnDiskReadyTime = DateTime.Now;
+        //            if ((bool)item.value)
+        //            {
+        //                opc.Write(OPCOutputTag.SpotCheck, false);
+        //                CommonUtil.StepControl.IncStep();
+        //                //bool isOk = false;
+
+        //                MeasureState pState = MeasureState.NA;
+
+        //                int detectID = CommonUtil.StepControl.GetUnloadStepID();
+        //                ProductMeasureResult x = null;
+        //                if (detectID > 0)
+        //                {
+        //                    x = (from t in productTestCollection
+        //                         where t.DetectID == detectID
+        //                         select t
+        //                            ).FirstOrDefault();
+        //                    if (x != default(ProductMeasureResult))
+        //                    {
+        //                        pState = (MeasureState)Enum.Parse(typeof(MeasureState), x.ProductResult);
+        //                        if (pState == MeasureState.OK)
+        //                        //if (x.ProductResult == MeasureState.OK.ToString())
+        //                        {
+        //                            if (x.IsSpotCheck)
+        //                            {
+        //                                //鍙栨秷鎶芥鏃舵斁鍏G鏂欑洏锛屾洿鏂版暟鎹簱鎶芥鏍囧織
+        //                                //isOk = false;
+        //                                //isOk = true;
+        //                                detectionData.SaveSpotCheck(detectID);
+        //                                detectionData.SaveTrayBarcode(detectID);
+        //                                //opc.Write(OPCOutputTag.SpotCheck, true);
+        //                            }
+        //                            else
+        //                            {
+        //                                //isOk = true;
+        //                                //opc.Write(OPCOutputTag.SpotCheck, false);
+        //                            }
+        //                        }
+        //                    }
+        //                }
+
+        //                #region add by Patrick 2019-12-20
+        //                switch (pState)
+        //                {
+        //                    case MeasureState.OK:
+        //                        opc.Write(OPCOutputTag.DetectResult_OK, true);
+        //                        opc.Write(OPCOutputTag.DetectResult_NG, false);
+
+        //                        CommonUtil.WriteLog(LogType.Inf, $"{x?.DetectID}|{x?.ProductNo}浜у搧搴旀斁鍏K Tray");
+
+        //                        _continuousNG = 0;
+        //                        break;
+        //                    case MeasureState.NG:
+        //                        opc.Write(OPCOutputTag.DetectResult_OK, false);
+        //                        opc.Write(OPCOutputTag.DetectResult_NG, true);
+
+        //                        CommonUtil.WriteLog(LogType.Inf, $"{x?.DetectID}|{x?.ProductNo}浜у搧搴旀斁鍏G Tray");
+        //                        CommonUtil.StepControl.RemoveById(detectID);
+
+        //                        _continuousNG++;
+        //                        break;
+        //                    default:
+        //                        opc.Write(OPCOutputTag.DetectResult_OK, false);
+        //                        opc.Write(OPCOutputTag.DetectResult_NG, false);
+
+        //                        CommonUtil.WriteLog(LogType.Inf, $"{x?.DetectID}|{x?.ProductNo}浜у搧搴旀斁鍏A Tray");
+        //                        CommonUtil.StepControl.RemoveById(detectID);
+
+        //                        _continuousNG = 0;
+        //                        break;
+        //                }
+        //                #endregion
+
+        //                //杞洏淇″彿璋冩暣鍒扮粨鏋滀箣鍚庣粰鍑�
+        //                opc.Write(OPCOutputTag.TurnDiskReadyConfirm, true);
+
+        //                //opc.Write(OPCOutputTag.DetectResult, isOk);
+
+        //                //if (!isOk)
+        //                //{
+        //                //    CommonUtil.StepControl.RemoveById(detectID);
+        //                //}
+
+        //                RemoveDetectedItem(detectID);
+        //                CommonUtil.WriteLog(LogType.Inf, string.Format("{0}, {1}", detectID, pState.ToString()));
+
+        //                if (unloadTime != DateTime.MaxValue)
+        //                {
+        //                    TimeSpan ts = DateTime.Now - unloadTime;
+        //                    DisplayCycleTime((int)Math.Round(ts.TotalMilliseconds));
+        //                }
+        //                unloadTime = DateTime.Now;
+
+        //                if (_continuousNG >= _continuousNGThreshold)
+        //                {
+        //                    //鑴氭湰涓缃姤璀︾爜2000琛ㄧず杩炵画NG娆℃暟鍒拌揪璁惧畾鎶ヨ涓婇檺
+        //                    opc.Write(OPCOutputTag.Alarm, 2000);
+
+        //                    CommonUtil.WriteLog(LogType.Inf, $"浜у搧杩炵画NG{_continuousNG}娆★紝鎶ヨ鎻愮ず");
+        //                    _continuousNG = 0;
+        //                }
+        //                //
+        //            }
+        //            break;
+        //        case OPCInputTag.DetectionStart2:
+        //            if ((bool)item.value)
+        //            {
+        //                DetectionProcesser hp = heightDetection.Execute;
+        //                IAsyncResult ar = hp.BeginInvoke(null, null);
+        //            }
+        //            break;
+        //        case OPCInputTag.DetectionStart4:
+        //            if ((bool)item.value)
+        //            {
+        //                //if (FormCheck._totalQty - FormCheck._finishedQty > 0 && FormCheck._pickCount > 0)
+        //                //{
+        //                //    if (FormCheck._lastProductQty + FormCheck._pickCount < measureResultTTL.ProductQuntity + FormCheck._lastBreakProductQty)
+        //                //    {
+        //                //        FormCheck._lastProductQty = measureResultTTL.ProductQuntity + FormCheck._lastBreakProductQty;
+        //                //    }
+        //                //    if (measureResultTTL.ProductQuntity + FormCheck._lastBreakProductQty == FormCheck._lastProductQty + FormCheck._pickCount)
+        //                //    {
+        //                //        string productNo = sizeDetection.GetProductNo(CommonUtil.StepControl.GetDetectSizeStepID());
+        //                //        if (productNo!="NA" && WeekCompare(productNo))
+        //                //        {
+        //                //            sizeDetection.isPick = true;
+        //                //            FormCheck._lastProductQty = measureResultTTL.ProductQuntity + FormCheck._lastBreakProductQty;
+        //                //        }
+        //                //    }
+        //                //}
+        //                Task.Factory.StartNew(() =>
+        //                {
+        //                    sizeDetection.Execute(measureResultTTL.ProductQuntity);
+        //                });
+        //            }
+        //            break;
+        //        case OPCInputTag.Auto:
+        //            tbPLCMsg.Text = DateTime.Now.ToString("HH:mm:ss") + ":" + OPCInputTag.Auto + "," + item.value.ToString() + "\r\n" + tbPLCMsg.Text;
+        //            ckAuto.Text = (bool)item.value ? "鎵嬪嫊" : "鑷嫊";
+        //            ckAuto.Checked = (bool)item.value;
+        //            gbHandTest.Enabled = ckAuto.Checked;
+        //            break;
+        //        case OPCInputTag.PLCInitialized:
+        //            tbPLCMsg.Text = DateTime.Now.ToString("HH:mm:ss") + ":" + OPCInputTag.PLCInitialized + "," + item.value.ToString() + "\r\n" + tbPLCMsg.Text;
+        //            if ((bool)item.value)
+        //            {
+        //                opc.Write(OPCOutputTag.PCInitialized, true);
+        //                lbDisplayState.Text = "鍒濆鍖栧畬鎴�";
+        //                Thread.Sleep(10);
+        //            }
+        //            break;
+        //        //case OPCInputTag.RunStatus:
+        //        //    switch (item.value.ToString())
+        //        //    {
+        //        //        case "1":
+        //        //            lbDisplayState.Text = "鎬ュ仠";
+        //        //            break;
+        //        //        case "2":
+        //        //            lbDisplayState.Text = "寰╀綅";
+        //        //            break;
+        //        //        case "3":
+        //        //            lbDisplayState.Text = "閬嬭";
+        //        //            break;
+        //        //        case "4":
+        //        //            lbDisplayState.Text = "鍋滄";
+        //        //            break;
+        //        //    }
+        //        //    break;
+        //        case OPCInputTag.EmergencyStop:
+
+        //            ProductBindingList.Clear();
+        //            productTestCollection.Clear();
+        //            CommonUtil.StepControl.Clear();
+        //            DisplayMeasureTTL();
+
+        //            imageProcess.ClearBarcodeImage();
+        //            //Thread.Sleep(1000);
+        //            //imageProcess.CloseCameras();
+        //            //Thread.Sleep(1000);
+        //            //imageProcess.OpenCameras();
+        //            CommonUtil.WriteLog(LogType.Inf, "绯荤粺鎬ュ仠");
+
+        //            //鎶芥鍙傛暟鐨勫埛鏂�
+        //            SetCheckInfo();
+
+        //            break;
+        //        case OPCInputTag.Alarm:
+        //            int val = int.Parse(item.value.ToString());
+        //            Task.Factory.StartNew(() =>
+        //            {
+        //                UpdateAlarm(val);
+        //                WarningData warningData = new WarningData();
+        //                DownTimeData downTimeData = new DownTimeData();
+        //                DateTime now = DateTime.Now;
+        //                if (val == 0)
+        //                {
+        //                    //鏇存柊鎶ヨ
+        //                    warningData.UpdateWarning();
+        //                    //鏇存柊鍥犳姤璀﹀紩璧风殑瀹曟満
+        //                    downTimeData.UpdateDownTime(new DownTime { EndTime = now, Type = DownTimeType.Warning });
+        //                }
+        //                else
+        //                {
+        //                    //淇濆瓨鎶ヨ
+        //                    warningData.SaveWarning(val);
+        //                    //缁撴潫涓婁竴涓姤璀﹀苟璁板綍涓嬩竴涓姤璀�
+        //                    downTimeData.UpdateDownTime(new DownTime { EndTime = now, Type = DownTimeType.Warning });
+        //                    downTimeData.SaveDownTime(new DownTime { BeginTime = now, Type = DownTimeType.Warning });
+        //                }
+        //                _tempDownTimeList.Add(now);
+        //            });
+        //            break;
+        //        //UpdateAlarm(int.Parse(item.value.ToString()));
+        //        //break;
+        //        case OPCInputTag.UploadSignalRequire:
+        //            if ((bool)item.value)
+        //            {
+        //                UpdateAlarm(101);
+        //            }
+        //            break;
+        //        case OPCInputTag.X1axisLocalPos:
+        //            tbX1axisLoPos.Text = item.value.ToString();
+        //            break;
+        //        case OPCInputTag.Y1axisLocalPos:
+        //            tbY1axisLoPos.Text = item.value.ToString();
+        //            break;
+        //        case OPCInputTag.X2axisLocalPos:
+        //            tbX2axisLoPos.Text = item.value.ToString();
+        //            break;
+        //        case OPCInputTag.Y2axisLocalPos:
+        //            tbY2axisLoPos.Text = item.value.ToString();
+        //            break;
+
+        //        case OPCInputTag.TestResult:
+        //            tbPLCMsg.Text = DateTime.Now.ToString("HH:mm:ss") + ":" + OPCInputTag.TestResult + "," + item.value.ToString() + "\r\n" + tbPLCMsg.Text;
+        //            if ((bool)item.value)
+        //            {
+        //                //鍒ゆ柇OKNG
+        //                opc.Write(OPCOutputTag.TestResult, false);
+        //                //OK_NG();
+        //            }
+        //            break;
+        //        case OPCInputTag.PPGJceFbPW:
+        //            plateID = (int)item.value;
+        //            //淇濆瓨鍥犱笂涓嬫枡銆佹枡鐩樻弧鏈綔澶勭悊寮曡捣鐨勫畷鏈�
+        //            Task.Factory.StartNew(() =>
+        //            {
+        //                DateTime now = DateTime.Now;
+        //                //鍒ゆ柇褰撳墠鏃犳姤璀﹀苟涓旀椂闂磋秴鍑鸿缃殑鏃堕暱
+        //                if (string.IsNullOrEmpty(tsslWarnMsg.Text) && _plateChangeTime != null && (now - _plateChangeTime.Value).TotalSeconds > _downTimeNoAction)
+        //                {
+        //                    DownTimeData downTimeData = new DownTimeData();
+        //                    //鍒ゆ柇璁剧疆鏃堕暱鍐呮湁鏃犳姤璀�
+        //                    if (_tempDownTimeList.Count > 0)
+        //                    {
+        //                        if ((now - _tempDownTimeList[_tempDownTimeList.Count - 1]).TotalSeconds > _downTimeNoAction)
+        //                        {
+        //                            if (_tempDownTimeList[_tempDownTimeList.Count - 1] > _plateChangeTime)
+        //                            {
+        //                                downTimeData.SaveDownTime(new DownTime { BeginTime = _tempDownTimeList[_tempDownTimeList.Count - 1], EndTime = now, Type = DownTimeType.NoAction });
+        //                            }
+        //                            else
+        //                            {
+        //                                downTimeData.SaveDownTime(new DownTime { BeginTime = _plateChangeTime, EndTime = now, Type = DownTimeType.NoAction });
+        //                            }
+        //                        }
+        //                    }
+        //                    else
+        //                    {
+        //                        downTimeData.SaveDownTime(new DownTime { BeginTime = _plateChangeTime, EndTime = now, Type = DownTimeType.NoAction });
+        //                    }
+        //                }
+        //                _plateChangeTime = now;
+        //            });
+        //            break;
+        //        case OPCInputTag.UploadFinished:
+        //            if ((bool)item.value)
+        //            {
+        //                TimeSpan tsUpload = DateTime.Now - TurnDiskReadyTime;
+        //                tbUploadTime.Text = string.Format("{0:0.00}", tsUpload.TotalMilliseconds / 1000);
+        //                tbUploadTime.Invalidate();
+        //            }
+        //            break;
+        //        case OPCInputTag.UnloadFinished:
+        //            if ((bool)item.value)
+        //            {
+        //                TimeSpan tsUnload = DateTime.Now - TurnDiskReadyTime;
+        //                tbUnloadTime.Text = string.Format("{0:0.00}", tsUnload.TotalMilliseconds / 1000);
+        //                tbUnloadTime.Invalidate();
+        //            }
+        //            break;
+
+        //        #region add by Patrick 2018-07-12
+        //        case OPCInputTag.UnloadBatteryDone: //鐢垫睜涓嬫枡鍒颁綅鏃讹紝缁戝畾杞藉叿鏉$爜
+        //            if ((bool)item.value)
+        //            {
+        //                //opc.Write(OPCInputTag.UnloadBatteryDone, false);
+        //                int batteryId = CommonUtil.StepControl.GetUnloadBatteryID();
+
+        //                CommonUtil.WriteLog(LogType.Inf, $"鐢垫睜涓嬫枡鍒颁綅,Id:{batteryId}");
+
+        //                CommonUtil.StepControl.RemoveById(batteryId);
+        //                detectionData.SaveTrayBarcode(batteryId);
+        //            }
+        //            break;
+        //        case OPCInputTag.UnloadTrayMoveToOP: //褰撲笅鏂欒浇鍏峰洖鍒癘P绔紝娓呯┖杞藉叿鏉$爜
+        //            if ((bool)item.value)
+        //            {
+        //                //opc.Write(OPCInputTag.UnloadTrayMoveToOP, false);
+
+        //                allowBarcodeFlag = true;
+        //                //CarrierBarcodeCtrl.GlobalCarrierBarcode = string.Empty;
+        //                cBarcodeCtrl.CarrierBarcode = string.Empty;
+
+        //                Task.Factory.StartNew(() =>
+        //                {
+        //                    detectionDataUpload.UploadData();
+        //                });
+        //            }
+        //            break;
+        //        case OPCInputTag.UnloadTrayReady://褰撲笅鏂欒浇鍏峰氨缁紝涓嶅厑璁歌緭鍏ユ潯鐮�
+        //            if ((bool)item.value)
+        //            {
+        //                //opc.Write(OPCInputTag.UnloadTrayReady, false);
+        //                allowBarcodeFlag = false;
+        //            }
+        //            break;
+        //            #endregion
+
+        //    }
+        //}
         #endregion
 
         #region OPC鎿嶄綔
@@ -1036,7 +1563,7 @@
                 }
             }
         }
-        public void UpdateAlarm(int val)
+        public int UpdateAlarm(int val)
         {
             string info = "";
             int type = 0;
@@ -1068,6 +1595,7 @@
             }
             tsslWarnMsg.Text = info;
             MessageHandler.MessageHandlerInstance.NewMessage(info);
+            return type;
         }
         #endregion
 
@@ -1238,6 +1766,7 @@
         {
             Stop();
         }
+        int _standardToDoNum = 0;
         private void btnSetupRunMode_Click(object sender, EventArgs e)
         {
             SystemRunMode rm = new SystemRunMode();
@@ -1253,7 +1782,12 @@
                 {
                     rm = form.RunMode;
                     opc.Write(OPCOutputTag.RunMode, rm.runMode);
-                    opc.Write(OPCOutputTag.RunTimes, rm.runTimes);
+                    opc.Write(OPCOutputTag.RunTimes, rm.runTimes * 5);
+
+                    _standardToDoNum = rm.runTimes;
+                    _standardResultList.Clear();
+
+                    rbStandardBlock.Checked = true;
 
                     //閲嶅鎬�
                     opc.Write(OPCOutputTag.Repeat, rm.Repeat);

--
Gitblit v1.8.0