jace.tang
2022-06-13 ab94f070d797edbe927d7d58a460cc4eddf48b03
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,6 +476,69 @@
        //    }
        //}
        //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)
        {
@@ -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));
                        //克隆对象的CSV数据记录
                        detectionData.CSVDataRecord(clone, filePath);
                        detectionData.CSVDataRecord(clone, standardCSVFileName);
                }
                if (lengthMeasureState == MeasureState.OK && widthMeasureState == MeasureState.OK)
                    measureResultTTL.SizePassQuantity++;
                    if (_standardResultList.Count() == _standardToDoNum)
                    {
                        int plateId = _standardResultList[0].PlateID;
                if (lengthMeasureState == MeasureState.NG || widthMeasureState == MeasureState.NG)
                    measureResultTTL.SizeFailQuantity++;
                        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();
                    }
                }
                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("接收到PLC信号:{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,7 +991,8 @@
                //    }
                //    break;
                case OPCInputTag.EmergencyStop:
                    if (itemValue == 1)
                    {
                    ProductBindingList.Clear();
                    productTestCollection.Clear();
                    CommonUtil.StepControl.Clear();
@@ -820,10 +1007,10 @@
                    //抽检参数的刷新
                    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: //当下料载具回到OP端,清空载具条码
                    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("接收到PLC信号:{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)
        //                            {
        //                                //取消抽检时放入NG料盘,更新数据库抽检标志
        //                                //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}产品应放入OK 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}产品应放入NG 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}产品应放入NA 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: //当下料载具回到OP端,清空载具条码
        //            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);