quanzhou
2025-09-11 31de09d1ba504cb036ae29a98a9efbb0c2d61914
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} ");
@@ -264,6 +283,7 @@
                    }
                    else
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接");
                        Plc1.WriteSingleAddress(1524, 1, out _);
                        Plc1.WriteSingleAddress(1514, 1, out _);
                    }
@@ -348,8 +368,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 +455,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 +567,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 篮具  进料口空篮 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
@@ -535,6 +593,7 @@
                        }
                        catch
                        {
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口空篮 获取返回值解析异常  返回数据{Msg} ");
                            Plc1.WriteSingleAddress(1590, 2, out _);
                        }
@@ -548,6 +607,7 @@
            }
            else
            {
                LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接");
                Plc1.WriteSingleAddress(1590, 1, out _);
            }
@@ -589,6 +649,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 _);
                            }
@@ -609,6 +688,7 @@
            }
            else
            {
                LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接");
                Plc1.WriteSingleAddress(1590, 1, out _);
            }
@@ -639,6 +719,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 篮具  下料口空篮 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
@@ -658,6 +757,7 @@
            }
            else
            {
                LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接");
                Plc1.WriteSingleAddress(1591, 1, out _);
            }
@@ -684,7 +784,29 @@
                        {
                            ConfigAOI1.mesnum3++;
                        }
                        LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口满载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 篮具  下料口满载1 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
                    }
                    catch
                    {
@@ -695,8 +817,6 @@
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口满载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 +832,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 篮具  下料口满载 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
@@ -730,14 +869,10 @@
            }
            else
            {
                LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接");
                Plc1.WriteSingleAddress(1591, 1, out _);
            }
            return msg;
        }
    }
}