patrick.xu
2021-11-22 220f43bdfb1e1d1544c892697304f99e967103a4
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
@@ -207,6 +221,10 @@
            opc.Write(OPCOutputTag.DetectResult_OK, false);
            opc.Write(OPCOutputTag.DetectResult_NG, false);
            CommonUtil.WriteLog(LogType.Inf, "初始化下料NA");
            //250表示启动时需要大复位报警
            opc.Write(OPCOutputTag.Alarm, 250);
            CommonUtil.WriteLog(LogType.Inf, "软件启动大复位");
            string continuousNGStr = ConfigurationManager.AppSettings["ContinuousNGThreshold"];
            if (int.TryParse(continuousNGStr, out int temp))
@@ -666,7 +684,7 @@
                                opc.Write(OPCOutputTag.DetectResult_OK, true);
                                opc.Write(OPCOutputTag.DetectResult_NG, false);
                                CommonUtil.WriteLog(LogType.Inf, $"{x.DetectID}|{x.ProductNo}产品应放入OK Tray");
                                CommonUtil.WriteLog(LogType.Inf, $"{x?.DetectID}|{x?.ProductNo}产品应放入OK Tray");
                                _continuousNG = 0;
                                break;
@@ -674,7 +692,7 @@
                                opc.Write(OPCOutputTag.DetectResult_OK, false);
                                opc.Write(OPCOutputTag.DetectResult_NG, true);
                                CommonUtil.WriteLog(LogType.Inf, $"{x.DetectID}|{x.ProductNo}产品应放入NG Tray");
                                CommonUtil.WriteLog(LogType.Inf, $"{x?.DetectID}|{x?.ProductNo}产品应放入NG Tray");
                                CommonUtil.StepControl.RemoveById(detectID);
                                _continuousNG++;
@@ -683,7 +701,7 @@
                                opc.Write(OPCOutputTag.DetectResult_OK, false);
                                opc.Write(OPCOutputTag.DetectResult_NG, false);
                                CommonUtil.WriteLog(LogType.Inf, $"{x.DetectID}|{x.ProductNo}产品应放入NA Tray");
                                CommonUtil.WriteLog(LogType.Inf, $"{x?.DetectID}|{x?.ProductNo}产品应放入NA Tray");
                                CommonUtil.StepControl.RemoveById(detectID);
                                _continuousNG = 0;
@@ -714,7 +732,7 @@
                        if (_continuousNG >= _continuousNGThreshold)
                        {
                            //脚本中设置报警码2000表示连续NG次数到达设定报警上限
                            opc.Write(OPCInputTag.Alarm, 2000);
                            opc.Write(OPCOutputTag.Alarm, 2000);
                            CommonUtil.WriteLog(LogType.Inf, $"产品连续NG{_continuousNG}次,报警提示");
                            _continuousNG = 0;
@@ -942,7 +960,6 @@
                    if ((bool)item.value)
                    {
                        //opc.Write(OPCInputTag.UnloadTrayReady, false);
                        allowBarcodeFlag = false;
                    }
                    break;
@@ -1071,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)
@@ -1643,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)