From ed8d469ccdc0e627d8f180bb92a9d78dbdb008b1 Mon Sep 17 00:00:00 2001
From: jace.tang <1536884497@qq.com>
Date: 星期六, 11 二月 2023 21:34:01 +0800
Subject: [PATCH] 调整sizeDetection输出结果的判断

---
 HeightDetection.cs |  119 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 96 insertions(+), 23 deletions(-)

diff --git a/HeightDetection.cs b/HeightDetection.cs
index 2df4a4a..bcb6d0b 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);
@@ -128,7 +129,7 @@
 
                     int slotNum = (CommonUtil.mainForm.PlateID + 1) % 5 + 1;
 
-                    string tempFileName = slotNum.ToString() + "_" + productNo.Trim().Replace("/", "").Replace("\"", "'") + "_" + DateTime.Now.ToString("HHmmssff") + "_" + detectID.ToString();
+                    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();
@@ -191,26 +192,76 @@
                                 cellHeightResult = MeasureState.NA;
                             }
                             #endregion
+
+                            //淇濆瓨楂樺害鍥剧墖
+                            if (cellHeightResult == MeasureState.OK)
+                            {
+                                heightResult = MeasureState.OK;
+                                DateTime dt = DateTime.Now;
+                                if (dt.Second >= 10 && dt.Second <= 15)
+                                {
+                                    heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + $"_{heightResult.ToString()}\\{ tempFileName}");
+                                }
+
+                            }
+                            else if (cellHeightResult == MeasureState.NG)
+                            {
+                                heightResult = MeasureState.NG;
+                                heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + $"_{heightResult.ToString()}\\{ tempFileName}");
+                            }
+                            else
+                            {
+                                heightResult = MeasureState.NA;
+                                heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + $"_{heightResult.ToString()}\\{ tempFileName}");
+                            }
+
+
+
                         }
                         else
                         {
                             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;
+
+                                cellHeightResult = batteryHeight[0] >= opcConfig.standardHeightLimit.Min
+                                && batteryHeight[0] <= opcConfig.standardHeightLimit.Max ? MeasureState.OK : MeasureState.NG;
                             }
 
                             //batteryHeight[1] = 999.999;
+                            else
+                            {
+                                cellHeightResult = MeasureState.NA;
+                            }
 
-                            cellHeightResult = batteryHeight[0] >= opcConfig.standardHeightLimit.Min
-                            && batteryHeight[0] <= opcConfig.standardHeightLimit.Max ? MeasureState.OK : MeasureState.NG;
+                            //淇濆瓨楂樺害鍥剧墖
+                            if (cellHeightResult == MeasureState.OK)
+                            {
+                                heightResult = MeasureState.OK;
+                                heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"\" + tempFileName);
+                            }
+                            else if (cellHeightResult == MeasureState.NG)
+                            {
+                                heightResult = MeasureState.NG;
+                                heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"\" + tempFileName);
+                            }
+                            else
+                            {
+                                heightResult = MeasureState.NA;
+                                heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + $"_{heightResult.ToString()}\\{ tempFileName}");
+                            }
+
+
+
                         }
 
                         timeStr = DateTime.Now.ToString("hh:mm:ss fff");
+                        heightResult = cellHeightResult;
 
                         //淇濆瓨楂樺害鍥剧墖
                         //if (cellHeightResult == MeasureState.OK)
@@ -224,25 +275,41 @@
                         //    heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"_NG\" + tempFileName);
                         //}
 
-                        heightResult = cellHeightResult;
+                        //淇濆瓨浜у搧鍙婃爣鍑嗗潡楂樺害鍥剧墖
+                        //if (heightResult != MeasureState.OK)
+                        //{
+                            
+                        //    if (CommonUtil.DetectionOption == DetectionOption.doStandardBlock)
+                        //    {
+                        //        heightFileName=VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"\" + tempFileName);
+                        //    }
+                        //    else
+                        //    {
+                        //        heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + $"_{heightResult.ToString()}\\{ tempFileName}");
+                        //    }
+                            
+                        //}
+                        //else
+                        //{
+                        //    if (opcConfig.IsSaveHeightOKImage||CommonUtil.DetectionOption == DetectionOption.doStandardBlock)
+                        //    {
+                        //        if (CommonUtil.DetectionOption == DetectionOption.doStandardBlock)
+                        //        {
+                        //            heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"\" + tempFileName);
+                        //        }
+                        //        else
+                        //        {
+                        //            DateTime dt = DateTime.Now;
+                        //            if (dt.Second >= 10 && dt.Second <= 15)
+                        //            {
+                        //                heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + @"_OK\" + tempFileName);
+                        //            }
+                                        
+                        //        }
+                                    
+                        //    }
 
-                        if (heightResult != MeasureState.OK)
-                        {
-                            heightFileName = VisionDetect.SaveImageAs(hi, CommonUtil.ProductHeightImageDir + $"_{heightResult.ToString()}\\{ tempFileName}");
-                        }
-                        else
-                        {
-                            if (opcConfig.IsSaveHeightOKImage)
-                            {
-                                //DateTime dt = DateTime.Now;
-
-                                //if (dt.Second >= 10 && dt.Second <= 15)
-                                {
-                                    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()));
@@ -260,6 +327,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.ProductNoImageDir}_NA\\{tempFileName}");
             }
             finally
             {

--
Gitblit v1.8.0