From f9e7cfbc3d3323158139a8f0b89286f90fd6326b Mon Sep 17 00:00:00 2001
From: quanzhou <quan.zhou@broconcentric.com>
Date: 星期三, 27 八月 2025 16:46:15 +0800
Subject: [PATCH] 合并

---
 src/Bro.M141_AOI1.Process/AOI1Process.cs |  150 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 140 insertions(+), 10 deletions(-)

diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs
index a6e11ba..e2a093d 100644
--- a/src/Bro.M141_AOI1.Process/AOI1Process.cs
+++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -249,6 +249,25 @@
                                 }
                                 else
                                 {
+                                    try
+                                    {
+                                        if (zwordstr.Contains("version閿欒"))
+                                        {
+                                            Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));
+                                            MatchCollection matches = reg.Matches(obj.zerrmsg);
+                                            if (matches[0] != null && matches.Count == 3)
+                                            {
+                                                ConfigAOI1.mesnum2 = int.Parse(matches[0].Value)+1;
+                                            }
+                                            else
+                                            {
+                                                ConfigAOI1.mesnum2 = 0;
+                                            }
+                                        }
+                                    }
+                                    catch (Exception ex) 
+                                    {
+                                    }                                 
                                     Plc1.WriteSingleAddress(1524, 2, out _);
                                     Plc1.WriteSingleAddress(1514, 1, out _);
                                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid鑾峰彇澶辫触 {zwordstr} ");
@@ -348,8 +367,7 @@
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"妫�娴嬩骇鍝佺嚎杞粨搴﹁緭鍏ョ偣鏁版嵁  {string.Join(',', pointdataF)}");
 
                     var tool = GetHalconTool(null, "", opConfig.AlgorithemPath);
-                    var ret = tool.RunProcedure(new Dictionary<string, HalconDotNet.HTuple>() { { "INPUT_Points", pointdataF.ToArray() } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results", "OUTPUT_PointZ" }, null);
-
+                    var ret = tool.RunProcedure(new Dictionary<string, HalconDotNet.HTuple>() { { "INPUT_Points", pointdataF.ToArray() } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results", "OUTPUT_PointZ" }, null);                   
                     if (ret == null)
                     {
                         LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鑴氭湰{opConfig.AlgorithemPath}杩愯寮傚父锛岃繑鍥炲�间负null");
@@ -436,6 +454,26 @@
                                     else
                                     {
                                         item.ActualValue = retcal.Item2["OUTPUT_Results"].HTupleToDouble()[0];
+
+                                        if (item.IsEnableCompensation && item.CompensationValue.Count > 1)
+                                        {                                            
+                                            string index = opConfig.TriggerStr.Split('#')[0];
+                                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{item.Code}杩涘叆鍙岄噸琛ュ伩{index}锛屽垵濮嬪�间负{item.ActualValue}");
+
+                                            if (index=="1")
+                                            {
+                                                item.ActualValue += item.CompensationValue[0];
+                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{item.Code}杩涘叆鍙岄噸琛ュ伩,琛ュ伩鍊间负{item.CompensationValue[0]}锛屾渶缁堢粨鏋滀负{item.ActualValue}");
+                                            }
+                                            else
+                                            {
+                                                item.ActualValue += item.CompensationValue[1];
+                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{item.Code}杩涘叆鍙岄噸琛ュ伩,琛ュ伩鍊间负{item.CompensationValue[1]}锛屾渶缁堢粨鏋滀负{item.ActualValue}");
+                                            }
+
+                                        }
+
+
                                         LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{results[0].PID}鑾峰彇璁$畻鍏紡鏁版嵁{item.Code}  {item.GetMeasureValueStr()}");
                                     }
                                 }
@@ -528,6 +566,25 @@
                             }
                             else
                             {
+                                try
+                                {
+                                    if (Msg.Contains("version閿欒"))
+                                    {
+                                        Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));
+                                        MatchCollection matches = reg.Matches(obj.zerrmsg);
+                                        if (matches[0] != null && matches.Count == 3)
+                                        {
+                                            ConfigAOI1.mesnum1 = int.Parse(matches[0].Value)+ 1;
+                                        }
+                                        else
+                                        {
+                                            ConfigAOI1.mesnum1 = 0;
+                                        }
+                                    }
+                                }
+                                catch (Exception ex)
+                                {
+                                }
                                 Plc1.WriteSingleAddress(1590, 2, out _);
                             }
                             LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿  杩涙枡鍙g┖绡� 涓婁紶{(obj?.zstatus == "200" ? "鎴愬姛" : "澶辫触")}   {obj?.zstatus}");
@@ -535,6 +592,7 @@
                         }
                         catch
                         {
+                            
                             LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿  杩涙枡鍙g┖绡� 鑾峰彇杩斿洖鍊艰В鏋愬紓甯�  杩斿洖鏁版嵁{Msg} ");
                             Plc1.WriteSingleAddress(1590, 2, out _);
                         }
@@ -589,6 +647,25 @@
                             }
                             else
                             {
+                                try
+                                {
+                                    if (Msg.Contains("version閿欒"))
+                                    {
+                                        Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));
+                                        MatchCollection matches = reg.Matches(obj.zerrmsg);
+                                        if (matches[0] != null && matches.Count == 3)
+                                        {
+                                            ConfigAOI1.mesnum1 = int.Parse(matches[0].Value) + 1;
+                                        }
+                                        else
+                                        {
+                                            ConfigAOI1.mesnum1 = 0;
+                                        }
+                                    }
+                                }
+                                catch (Exception ex)
+                                {
+                                }
                                 Plc1.WriteSingleAddress(1590, 2, out _);
                             }
 
@@ -639,6 +716,25 @@
                         }
                         else
                         {
+                            try
+                            {
+                                if (Msg.Contains("version閿欒"))
+                                {
+                                    Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));
+                                    MatchCollection matches = reg.Matches(obj.zerrmsg);
+                                    if (matches[0] != null && matches.Count == 3)
+                                    {
+                                        ConfigAOI1.mesnum3 = int.Parse(matches[0].Value)+1;
+                                    }
+                                    else
+                                    {
+                                        ConfigAOI1.mesnum3 = 0;
+                                    }
+                                }
+                            }
+                            catch (Exception ex)
+                            {
+                            }
                             Plc1.WriteSingleAddress(1591, 2, out _);
                         }
                         LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿  涓嬫枡鍙g┖绡� 涓婁紶{(obj?.zstatus == "200" ? "鎴愬姛" : "澶辫触")}   {obj?.zstatus}");
@@ -684,7 +780,29 @@
                         {
                             ConfigAOI1.mesnum3++;
                         }
-                        LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿  涓嬫枡鍙f弧杞�1 涓婁紶{(obj?.zstatus == "200" ? "鎴愬姛" : "澶辫触")}   {obj?.zstatus}");
+                        else
+                        {
+                            try
+                            {
+                                if (Msg.Contains("version閿欒"))
+                                {
+                                    Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));
+                                    MatchCollection matches = reg.Matches(obj.zerrmsg);
+                                    if (matches[0] != null && matches.Count == 3)
+                                    {
+                                        ConfigAOI1.mesnum3 = int.Parse(matches[0].Value) + 1;
+                                    }
+                                    else
+                                    {
+                                        ConfigAOI1.mesnum3 = 0;
+                                    }
+                                }
+                            }
+                            catch (Exception ex)
+                            {
+                            }
+                        }
+                            LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿  涓嬫枡鍙f弧杞�1 涓婁紶{(obj?.zstatus == "200" ? "鎴愬姛" : "澶辫触")}   {obj?.zstatus}");
                     }
                     catch
                     {
@@ -695,8 +813,6 @@
                 {
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿  涓嬫枡鍙f弧杞�1 鑾峰彇杩斿洖鍊艰В鏋愬紓甯�  杩斿洖鏁版嵁null ");
                 }
-
-
                 Thread.Sleep(1000);
                 //mqtt.Send("4", "DS02217", ConfigAOI1.Dicbasketcode.ContainsKey(num) ? ConfigAOI1.Dicbasketcode[num] : ConfigAOI1.basketcode, "1", num.ToString());
                 Msg = Task.Run(() => mqtt.MESForBasketAsync("4", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "1", ConfigAOI1.mesnum4.ToString())).Result;
@@ -712,6 +828,25 @@
                         }
                         else
                         {
+                            try
+                            {
+                                if (Msg.Contains("version閿欒"))
+                                {
+                                    Regex reg = new Regex("[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));
+                                    MatchCollection matches = reg.Matches(obj.zerrmsg);
+                                    if (matches[0] != null && matches.Count == 3)
+                                    {
+                                        ConfigAOI1.mesnum4 = int.Parse(matches[0].Value) + 1;
+                                    }
+                                    else
+                                    {
+                                        ConfigAOI1.mesnum4 = 0;
+                                    }
+                                }
+                            }
+                            catch (Exception ex)
+                            {
+                            }
                             Plc1.WriteSingleAddress(1591, 2, out _);
                         }
                         LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿  涓嬫枡鍙f弧杞� 涓婁紶{(obj?.zstatus == "200" ? "鎴愬姛" : "澶辫触")}   {obj?.zstatus}");
@@ -734,10 +869,5 @@
             }
             return msg;
         }
-
-
-
-
-
     }
 }

--
Gitblit v1.8.0