From 220f43bdfb1e1d1544c892697304f99e967103a4 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期一, 22 十一月 2021 08:42:14 +0800
Subject: [PATCH] 1. 添加了扫码键盘事件的日志记录,版本号升级到1.0.4.0

---
 MainForm.cs |  113 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 94 insertions(+), 19 deletions(-)

diff --git a/MainForm.cs b/MainForm.cs
index 726e365..3c791e3 100644
--- a/MainForm.cs
+++ b/MainForm.cs
@@ -137,6 +137,8 @@
             this.KeyPreview = true;
             this.KeyPress += MainForm_KeyPress;
 
+            Trace.TraceInformation("閿洏浜嬩欢宸插姞杞�");
+
             hcXyView.Focus();
         }
 
@@ -144,16 +146,28 @@
         CarrierBarcodeCtrl cBarcodeCtrl = null;
         private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
         {
-            if (e.KeyChar == 27)
+            try
             {
-                hcXyView.Focus();
-            }
-            else
-            {
-                if (allowBarcodeFlag)
+                if (e.KeyChar == 27)
                 {
-                    cBarcodeCtrl.AddChar(e.KeyChar);
+                    hcXyView.Focus();
                 }
+                else
+                {
+                    if (allowBarcodeFlag)
+                    {
+                        Trace.TraceInformation($"閿洏杈撳叆锛歿e.KeyChar}");
+                        cBarcodeCtrl.AddChar(e.KeyChar);
+                    }
+                    else
+                    {
+                        Trace.TraceInformation($"褰撳墠涓嶅厑璁告寜閿緭鍏ワ細{e.KeyChar}");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                Trace.TraceError($"閿洏浜嬩欢寮傚父锛歿ex.Message}");
             }
         }
         #endregion
@@ -203,6 +217,24 @@
 
             CommonUtil.IsRunning = true;
             SetControls();
+
+            opc.Write(OPCOutputTag.DetectResult_OK, false);
+            opc.Write(OPCOutputTag.DetectResult_NG, false);
+            CommonUtil.WriteLog(LogType.Inf, "鍒濆鍖栦笅鏂橬A");
+
+            //250琛ㄧず鍚姩鏃堕渶瑕佸ぇ澶嶄綅鎶ヨ
+            opc.Write(OPCOutputTag.Alarm, 250);
+            CommonUtil.WriteLog(LogType.Inf, "杞欢鍚姩澶у浣�");
+
+            string continuousNGStr = ConfigurationManager.AppSettings["ContinuousNGThreshold"];
+            if (int.TryParse(continuousNGStr, out int temp))
+            {
+                _continuousNGThreshold = temp;
+            }
+            else
+            {
+                _continuousNGThreshold = 999;
+            }
         }
 
         public void Stop()
@@ -592,6 +624,9 @@
             lblEmptyQuantity.Text = measureResultTTL.EmptyQuantity.ToString();
         }
 
+        int _continuousNGThreshold = 999;
+        int _continuousNG = 0;
+
         #region PLC 鐩戝惉
         void OPCEventHandler(object sender, EventTool.ListenEventArgs e)
         {
@@ -611,11 +646,12 @@
                         MeasureState pState = MeasureState.NA;
 
                         int detectID = CommonUtil.StepControl.GetUnloadStepID();
+                        ProductMeasureResult x = null;
                         if (detectID > 0)
                         {
-                            var x = (from t in productTestCollection
-                                     where t.DetectID == detectID
-                                     select t
+                            x = (from t in productTestCollection
+                                 where t.DetectID == detectID
+                                 select t
                                     ).FirstOrDefault();
                             if (x != default(ProductMeasureResult))
                             {
@@ -647,18 +683,28 @@
                             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
@@ -682,6 +728,15 @@
                             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;
@@ -878,8 +933,10 @@
                     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);
                     }
@@ -903,7 +960,6 @@
                     if ((bool)item.value)
                     {
                         //opc.Write(OPCInputTag.UnloadTrayReady, false);
-
                         allowBarcodeFlag = false;
                     }
                     break;
@@ -1032,18 +1088,34 @@
         #region 浜嬩欢
         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
         {
-            Stop();
-            SaveMeasureTTL();
-            Task.Factory.StartNew(() =>
+            try
             {
+                Stop();
+                SaveMeasureTTL();
+                //Task.Factory.StartNew(() =>
+                //{
                 SpotCheckData data = new SpotCheckData();
                 data.UpdateLastBreakProductQty(measureResultTTL.ProductQuntity);
                 DownTimeData downTimeData = new DownTimeData();
                 DownTime downTime = new DownTime() { BeginTime = DateTime.Now, Type = DownTimeType.Closed };
                 downTimeData.SaveDownTime(downTime);
-            });
+                //});
 
-            MessageHandler.MessageHandlerInstance.Close();
+                MessageHandler.MessageHandlerInstance.Close();
+            }
+            catch (Exception ex)
+            {
+                Trace.TraceError($"鐣岄潰鍏抽棴寮傚父锛歿ex.Message}");
+            }
+            finally
+            {
+                lock (CommonUtil.UploadDataLock)
+                {
+                    //CommonUtil.UploadDoneHandle.WaitOne();
+                    CommonUtil.UploadDataEnable = false;
+                    System.Environment.Exit(0);
+                }
+            }
         }
 
         private void btnConfig_Click(object sender, EventArgs e)
@@ -1604,8 +1676,11 @@
 
         private void btnPlcOperation_Click(object sender, EventArgs e)
         {
-            FormPlcOperation frm = new FormPlcOperation(opc);
-            frm.ShowDialog();
+            //if (new ConfigPassword("").ShowDialog() == DialogResult.OK)
+            {
+                FormPlcOperation frm = new FormPlcOperation(opc);
+                frm.ShowDialog();
+            }
         }
 
         private void btnCheck_Click(object sender, EventArgs e)

--
Gitblit v1.8.0