From 220f43bdfb1e1d1544c892697304f99e967103a4 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期一, 22 十一月 2021 08:42:14 +0800
Subject: [PATCH] 1. 添加了扫码键盘事件的日志记录,版本号升级到1.0.4.0

---
 HeightDetection.cs |   40 +++++++++++++++++++++++++++++-----------
 1 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/HeightDetection.cs b/HeightDetection.cs
index d84b496..2df4a4a 100644
--- a/HeightDetection.cs
+++ b/HeightDetection.cs
@@ -125,7 +125,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;
+
+                    string 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();
@@ -164,10 +167,12 @@
                             {
                                 double compv = 0.0;
                                 Type t = opcConfig.compensationZ.GetType();
-                                FieldInfo fi = t.GetField(string.Format("station{0}", (CommonUtil.mainForm.PlateID + 1) % 5 + 1));
+
+
+                                FieldInfo fi = t.GetField(string.Format("station{0}", slotNum));
                                 compv = (double)fi.GetValue(opcConfig.compensationZ);
 
-                                batteryHeight[0] = HeigthCompensation(batteryHeight[0], compv, stationNumber);
+                                batteryHeight[0] = HeightCompensation(batteryHeight[0], compv, slotNum);
 
                                 //batteryHeight[0] += compv;
                                 ////batteryHeight[1] += compv;
@@ -225,6 +230,20 @@
                         {
                             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,7 +279,7 @@
 
         static object _heightRawDataLock = new object();
         TaskFactory _taskFactory = new TaskFactory();
-        private void LogHeightRawDataAsync(DateTime dt, double rawData, double compv, double final1, double final2, int stationNum)
+        private void LogHeightRawDataAsync(DateTime dt, double rawData, double compv, double final1, double final2, int slotNum)
         {
             _taskFactory.StartNew(new Action(() =>
             {
@@ -280,15 +299,14 @@
                     {
                         if (!isFileExisted)
                         {
-                            writer.WriteLine("Time,Station,Height,CompZ,Final1,Final2");
+                            writer.WriteLine("Time,Slot,Height,CompZ,Final1,Final2");
                         }
 
-                        writer.WriteLine($"{dt.ToString("HH:mm:ss.fff")},{stationNum},{rawData},{compv},{final1},{final2}");
+                        writer.WriteLine($"{dt.ToString("HH:mm:ss.fff")},{slotNum},{rawData},{compv},{final1},{final2}");
                         writer.Flush();
                         writer.Close();
                     }
                 }
-
             }));
         }
 
@@ -296,7 +314,7 @@
         double errorBand = Convert.ToDouble(ConfigurationManager.AppSettings["ErrorBand"]);
         bool isEnableRawData = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableRawData"]);
 
-        private double HeigthCompensation(double rawData, double compv, int stationNum)
+        private double HeightCompensation(double rawData, double compv, int slotNum)
         {
             double adjustValue, finalHeight, fakeValue;
             adjustValue = rawData + compv;
@@ -304,16 +322,16 @@
             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)
             {
-                LogHeightRawDataAsync(DateTime.Now, rawData, compv, finalHeight, fakeValue, stationNum);
+                LogHeightRawDataAsync(DateTime.Now, rawData, compv, finalHeight, fakeValue, slotNum);
             }
 
             return fakeValue;

--
Gitblit v1.8.0