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输出结果的判断

---
 SizeDetection.cs |   65 ++++++++++++++++++++++++++++----
 1 files changed, 56 insertions(+), 9 deletions(-)

diff --git a/SizeDetection.cs b/SizeDetection.cs
index 2f5f8cb..d8ae93e 100644
--- a/SizeDetection.cs
+++ b/SizeDetection.cs
@@ -232,6 +232,7 @@
                 timeStr, CommonUtil.StepControl.ToString()));
 
             HObject hImage = null;
+            string tempFileName = "";
             try
             {
                 Thread.Sleep(50);
@@ -242,7 +243,7 @@
                 {
                     return;
                 }
-                string tempFileName = GetCurrentProductSN(detectID);
+                tempFileName = GetCurrentProductSN(detectID);
                 string productNo = GetProductNo(detectID);
 
                 int times = 3;
@@ -289,6 +290,7 @@
                     tupleDictionary.Add("OUTPUT_RectArea", new HTuple());
                     tupleDictionary.Add("INPUT_Rect", rectROI);
                     tupleDictionary.Add("INPUT_RectThreshold", rectThreshold);
+                    tupleDictionary.Add("INPUT_Type", CommonUtil.DetectionOption == DetectionOption.doStandardBlock ? 2 : 1);
                     #endregion
 
                     _tool.SetDictionary(tupleDictionary, imageDictionary);
@@ -394,13 +396,13 @@
                     }
                     else
                     {
-                        Type t = opcConfig.standardCompensationL.GetType();
+                        Type t = opcConfig.compensationL.GetType();
                         FieldInfo fi = t.GetField(string.Format("station{0}", CommonUtil.mainForm.PlateID));
-                        compL = (double)fi.GetValue(opcConfig.standardCompensationL);
+                        compL = (double)fi.GetValue(opcConfig.compensationL);
 
-                        t = opcConfig.standardCompensationW.GetType();
+                        t = opcConfig.compensationW.GetType();
                         fi = t.GetField(string.Format("station{0}", CommonUtil.mainForm.PlateID));
-                        compW = (double)fi.GetValue(opcConfig.standardCompensationW);
+                        compW = (double)fi.GetValue(opcConfig.compensationW);
 
                         btyLength += compL;
                         btyWidth += compW;
@@ -410,13 +412,49 @@
 
                         if (lengthMeasureState == MeasureState.OK && widthMeasureState == MeasureState.OK)
                         {
-                            ms = MeasureState.OK;
+                            //ms = MeasureState.OK;
                             //VisionDetect.SaveImageAs(hImage, CommonUtil.ScreenshotsDir + @"\" + tempFileName);
+                            VisionDetect.SaveImageAs(hImage, CommonUtil.ProductSizeImageDir + @"\" + tempFileName);
                         }
                         else
                         {
-                            ms = MeasureState.NG;
-                            fileName = VisionDetect.SaveImageAs(hImage, CommonUtil.ScreenshotsDir + @"_NG\" + tempFileName);
+                            //ms = MeasureState.NG;
+                            if (btyLength >= MaxLength || btyLength <= MinLength || btyWidth >= MaxWidth || btyWidth <= MinWidth)
+                            {
+                                lengthMeasureState = MeasureState.NA;
+                                widthMeasureState = MeasureState.NA;
+                                ms = MeasureState.NA;
+                            }
+                            else
+                            {
+                                ms = MeasureState.NG;
+                            }
+
+                            if (ms != MeasureState.NA)
+                            {
+                                if (!isNA)
+                                {
+                                    ms = MeasureState.NG;
+                                    fileName = VisionDetect.SaveImageAs(hImage, CommonUtil.ProductSizeImageDir + @"\" + tempFileName);
+                                }
+                                else
+                                {
+                                    lengthMeasureState = MeasureState.NA;
+                                    widthMeasureState = MeasureState.NA;
+                                    ms = MeasureState.NA;
+                                    fileName = VisionDetect.SaveImageAs(hImage, CommonUtil.ProductSizeImageDir + $"_{ms.ToString()}\\{ tempFileName}");
+                                }
+                            }
+                            else
+                            {
+                                fileName = VisionDetect.SaveImageAs(hImage, CommonUtil.ProductSizeImageDir + $"_{ms.ToString()}\\{ tempFileName}");
+                            }
+
+
+
+                            //ms = MeasureState.NG;
+                            //fileName = VisionDetect.SaveImageAs(hImage, CommonUtil.ScreenshotsDir + @"_NG\" + tempFileName);
+                            //fileName = VisionDetect.SaveImageAs(hImage, CommonUtil.ProductSizeImageDir + @"\" + tempFileName);
                         }
                     }
 
@@ -466,6 +504,7 @@
             catch (Exception ex)
             {
                 CommonUtil.WriteLog(LogType.Exc, string.Format("浜у搧灏哄妫�娴嬪嚭鐜板紓甯革細{0}", ex.Message));
+                fileName = VisionDetect.SaveImageAs(hImage, $"{CommonUtil.ProductSizeImageDir}_NA\\{tempFileName}");
             }
             finally
             {
@@ -664,9 +703,17 @@
                 weekPlus = 0;
             }
             weekOfYear += weekPlus;
-
             string week = weekOfYear.ToString().Length == 1 ? "0" + weekOfYear.ToString() : weekOfYear.ToString();
+
+            var yearPlusStr = ConfigurationManager.AppSettings["YearPlus"];
+            int yearPlus = 0;
+            if (!int.TryParse(yearPlusStr, out yearPlus))
+            {
+                yearPlus = 0;
+            }
             string year = dt.Year.ToString().Substring(dt.Year.ToString().Length - 1, 1);
+            year = (int.Parse(year) + yearPlus).ToString();
+
             return year + week;
         }
     }

--
Gitblit v1.8.0