From bd5297c64f39c360a7bf41435a88ae5e70840fc2 Mon Sep 17 00:00:00 2001 From: jace.tang <1536884497@qq.com> Date: 星期二, 14 六月 2022 14:28:54 +0800 Subject: [PATCH] merge --- HeightDetection.cs | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 45 insertions(+), 7 deletions(-) diff --git a/HeightDetection.cs b/HeightDetection.cs index 7d4663d..415b929 100644 --- a/HeightDetection.cs +++ b/HeightDetection.cs @@ -73,6 +73,7 @@ HObject ihImage = null; HObject hi = new HObject(); + string tempFileName = ""; try { opc.Write(OPCOutputTag.DetectionStart2, false); @@ -125,7 +126,10 @@ CommonUtil.mainForm.Invoke(new Action(() => CommonUtil.mainForm.AppendDetectionData(productNo))); int detectID = CommonUtil.StepControl.GetDetectHeightID(); - string tempFileName = CommonUtil.mainForm.PlateID.ToString() + "_" + productNo.Trim().Replace("/", "").Replace("\"", "'") + "_" + DateTime.Now.ToString("HHmmssff") + "_" + detectID.ToString(); + + int slotNum = (CommonUtil.mainForm.PlateID + 1) % 5 + 1; + + tempFileName = slotNum.ToString() + "_" + productNo.Trim().Replace("/", "").Replace("\"", "'") + "_" + DateTime.Now.ToString("HHmmssff") + "_" + detectID.ToString(); if (productNo.Trim().Length == CommonUtil.ProductNoLength) { string productNoFileName = CommonUtil.ProductNoImageDir + @"\" + productNo + "_" + detectID.ToString(); @@ -165,7 +169,7 @@ double compv = 0.0; Type t = opcConfig.compensationZ.GetType(); - int slotNum = (CommonUtil.mainForm.PlateID + 1) % 5 + 1; + FieldInfo fi = t.GetField(string.Format("station{0}", slotNum)); compv = (double)fi.GetValue(opcConfig.compensationZ); @@ -194,9 +198,9 @@ if (batteryHeight[0] != 999.999 && batteryHeight[0] != -999.999) { double compv = 0.0; - Type t = opcConfig.standardCompensationZ.GetType(); + Type t = opcConfig.compensationZ.GetType(); FieldInfo fi = t.GetField(string.Format("station{0}", (CommonUtil.mainForm.PlateID + 1) % 5 + 1)); - compv = (double)fi.GetValue(opcConfig.standardCompensationZ); + compv = (double)fi.GetValue(opcConfig.compensationZ); batteryHeight[0] += compv; } @@ -225,8 +229,36 @@ if (heightResult != MeasureState.OK) { - heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + $"_{heightResult.ToString()}\\{ tempFileName}"); + + if (CommonUtil.DetectionOption == DetectionOption.doStandardBlock) + { + VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"\" + tempFileName); + } + else + { + heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + $"_{heightResult.ToString()}\\{ tempFileName}"); + } + } + else + { + if (opcConfig.IsSaveHeightOKImage||CommonUtil.DetectionOption == DetectionOption.doStandardBlock) + { + //DateTime dt = DateTime.Now; + //if (dt.Second >= 10 && dt.Second <= 15) + if (CommonUtil.DetectionOption == DetectionOption.doStandardBlock) + { + VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"\" + tempFileName); + } + else + { + VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"_OK\" + tempFileName); + } + + } + + } + CommonUtil.WriteLog(LogType.Inf, string.Format("楂樺害妫�娴嬪畬鎴�,缁撴灉锛歿0} H:{1:F4}, {2:F4}, {3}, {4}", productNo, batteryHeight[0], batteryHeight[1], timeStr, CommonUtil.StepControl.ToString())); } @@ -243,6 +275,12 @@ catch (Exception ex) { CommonUtil.WriteLog(LogType.Exc, string.Format("妫�娴嬩骇鍝佹潯鐮佸拰鍘氬害杩囩▼涓嚭鐜板紓甯革細{0}", ex.Message)); + + if (string.IsNullOrWhiteSpace(tempFileName)) + { + tempFileName = DateTime.Now.ToString("HHmmssfff"); + } + VisionDetect.SaveImageAs(ihImage, $"{CommonUtil.ProductSizeImageDir}_NA\\{tempFileName}"); } finally { @@ -305,11 +343,11 @@ double standardGap = opcConfig.batteryHeightLimit.Max - standardValue; double gap = adjustValue - standardValue; - fakeValue = finalHeight = (gap / (errorBand / 2.0)) * standardGap + standardValue; + fakeValue = finalHeight = Math.Round(((gap / (errorBand / 2.0)) * standardGap + standardValue), 5); if (finalHeight < opcConfig.batteryHeightLimit.Min || finalHeight > opcConfig.batteryHeightLimit.Max) { - fakeValue = standardValue + (CommonUtil.random.NextDouble() - 0.5) * 2.0 * standardGap; + fakeValue = Math.Round((standardValue + (CommonUtil.random.NextDouble() - 0.5) * 2.0 * standardGap), 5); } if (isEnableRawData) -- Gitblit v1.8.0