From 66e0168fe68ae5641041b2bceb3f0bb9640df09f Mon Sep 17 00:00:00 2001
From: quanzhou <quan.zhou@broconcentric.com>
Date: 星期五, 22 八月 2025 09:21:39 +0800
Subject: [PATCH] 添加MES超时队列匹配功能,vision错误自动累加和清零动作
---
src/Bro.M141_AOI1.Process/AOI1Process.cs | 539 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 524 insertions(+), 15 deletions(-)
diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs
index 3b6bd8b..e2a093d 100644
--- a/src/Bro.M141_AOI1.Process/AOI1Process.cs
+++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -1,4 +1,5 @@
锘縰sing Bro.Common.Base;
+using Bro.Common.Factory;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
@@ -6,12 +7,15 @@
using Bro.M141.Process;
using Bro.UI.Model.Winform;
using HalconDotNet;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
using NPOI.POIFS.Crypt.Dsig;
using NPOI.SS.Formula.Functions;
using NPOI.XSSF.Streaming.Values;
using System.Collections.Concurrent;
using System.Net.Sockets;
using System.Text.RegularExpressions;
+using static Bro.Common.Helper.EnumHelper;
using static NPOI.HSSF.Util.HSSFColor;
using static Org.BouncyCastle.Crypto.Engines.SM2Engine;
using static Org.BouncyCastle.Math.EC.ECCurve;
@@ -29,12 +33,23 @@
AOI1Config ConfigAOI1 => Config as AOI1Config;
-
-
public override void Open()
{
+
+ //string configPath = @"C:\Users\30263\Desktop\666.txt";
+
+ //string _configBackupStr = "";
+ //using (StreamReader reader = new StreamReader(configPath, System.Text.Encoding.UTF8))
+ //{
+ // _configBackupStr = reader.ReadToEnd();
+
+ //}
+
+ //ProductModel p = JsonConvert.DeserializeObject<ProductModel>(_configBackupStr, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
+
base.Open();
}
+
[ProcessMethod("", "PositionCheck_P1", "宸ヤ綅1妫�娴�", InvokeType.TestInvoke)]
public ResponseMessage PositionCheck_P1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -53,6 +68,7 @@
return msg;
}
+
[ProcessMethod("", "PositionCheck_P2", "宸ヤ綅2妫�娴�", InvokeType.TestInvoke)]
public ResponseMessage PositionCheck_P2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
{
@@ -70,6 +86,7 @@
return msg;
}
+
[ProcessMethod("", "PositionCheck_P3", "宸ヤ綅3妫�娴�", InvokeType.TestInvoke)]
public ResponseMessage PositionCheck_P3(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
{
@@ -86,7 +103,6 @@
return msg;
}
-
[ProcessMethod("ImageCheck", "ReadBarcode", "璇荤爜", InvokeType.TestInvoke)]
@@ -116,14 +132,47 @@
}
else
{
- ret.Add(1);
+ if (barcode.Split('-').Length > 5)
+ {
+ int mh = Plc1.Read(4000, 1, out _)[0];
+ string codestr = barcode.Split('-')[4];
+ if (codestr == "L")
+ {
+ codestr = "10";
+ }
+
+ if (codestr.Equals(mh.ToString()))
+ {
+ ret.Add(1);
+ }
+ else
+ {
+ ret.Add(2);
+ Plc1.WriteSingleAddress(4010, 1, out _);//缁檖lc鎶ヨ
+ }
+ }
+ else
+ {
+ ret.Add(999);
+ }
}
FillSpecResults(results[0].PID, results[0].Specs, ret, opConfig.Products[0].SEQUENCE);
opConfig.Products[0].SN = barcode;
- opConfig.Products[0].Details.ForEach(u => u.SN = barcode);
+ opConfig.Products[0].PID = barcode + "_1";
+ opConfig.Products[0].Details.ForEach(u =>
+ {
+ u.SN = barcode;
+ u.PID = barcode + "_1";
+ u.ResultList.ForEach(x =>
+ {
+
+ x.PID = barcode + "_1";
+
+ });
+ });
LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{opConfig.Products[0].PID}鏉$爜鑾峰彇涓簕barcode}");
}
@@ -148,16 +197,102 @@
}
else
{
- Plc1.WriteSingleAddress(1524, 1, out _);
- Plc1.WriteSingleAddress(1514, 1, out _);
ConfigAOI1.basketcode = barcode;
+ int num = Plc1.Read(1577, 1, out _)[0];
+
+ if (ConfigAOI1.PlcAndBasketcodes.Count > 10)
+ {
+ ConfigAOI1.PlcAndBasketcodes.RemoveAt(0);
+ }
+
+ if (ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num))
+ {
+ ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code = barcode;
+ }
+ else
+ {
+ ConfigAOI1.PlcAndBasketcodes.Add(new PlcAndBasketcode
+ {
+ code = barcode,
+ id = num,
+ });
+ }
+
LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"鑾峰彇鍒版爮鍏风爜涓簕barcode}");
+
+ mysqlhelper.NewBasketcode(barcode);
+ RerefreshBasketcode();
+
+ if (ConfigAOI1.ISupMES)
+ {
+ //string zword = mqtt.MESForBasketAsync("2", "DS02217", barcode, "1", num.ToString()).Result;
+ string zwordstr = Task.Run(() => mqtt.MESForBasketAsync("2", "DS02217", barcode, "1", ConfigAOI1.mesnum2.ToString())).Result;
+
+ ConfigAOI1.mesnum2++;
+ if (ConfigAOI1.ISokMes)
+ {
+ Plc1.WriteSingleAddress(1524, 1, out _);
+ Plc1.WriteSingleAddress(1514, 1, out _);
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"宸插己鍒惰鏍忓叿鐮佽繍琛岃澶�");
+ }
+ else
+ {
+ try
+ {
+ var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(zwordstr);
+ ConfigAOI1.zwoid = obj.zwoid;
+ if (!string.IsNullOrEmpty(obj.zwoid) && obj.zstatus == "200")
+ {
+ Plc1.WriteSingleAddress(1524, 1, out _);
+ Plc1.WriteSingleAddress(1514, 1, out _);
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid鑾峰彇鎴愬姛 {obj.zstatus} {obj.zwoid} ");
+ }
+ 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} ");
+ }
+ }
+ catch
+ {
+ Plc1.WriteSingleAddress(1524, 2, out _);
+ Plc1.WriteSingleAddress(1514, 1, out _);
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ zwoid鑾峰彇寮傚父 杩斿洖鏁版嵁涓� {zwordstr} ");
+ }
+ }
+ }
+ else
+ {
+ Plc1.WriteSingleAddress(1524, 1, out _);
+ Plc1.WriteSingleAddress(1514, 1, out _);
+ }
+ SaveProcessConfig(ConfigAOI1);
}
+
}
return msg;
}
-
private string BarcodeScannerCommunicate(TcpClientWrapBase client)
@@ -190,6 +325,7 @@
return "NOREAD";
}
+
private bool CheckBarcodeValid(string barcode)
{
bool isBarcodeValid = true;
@@ -199,10 +335,6 @@
}
return isBarcodeValid;
}
-
-
-
-
[ProcessMethod("ImageCheck", "CheckLineProfile", "妫�娴嬩骇鍝佺嚎杞粨搴�", InvokeType.TestInvoke)]
@@ -235,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");
@@ -259,7 +390,8 @@
if (datasZ.Count == CheckPointList.Count)
{
string Postion = "P" + opConfig.TriggerStr.Split('#')[0];
- string csvhead = "Time,Pid,Postion";
+ string csvhead = "Time,Pid" +
+ ",Postion";
string csvdata = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}T,{results[0].PID},{Postion}";
for (int i = 0; i < CheckPointList.Count; i++)
@@ -322,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()}");
}
}
@@ -348,6 +500,33 @@
}
+ [ProcessMethod("ImageCheck", "GetMatrix", "鑾峰彇鐭╅樀", InvokeType.TestInvoke)]
+ public ResponseMessage GetMatrix(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+ {
+ ResponseMessage msg = new ResponseMessage();
+ if (config is IImageCheckOperationConfig opConfig)
+ {
+ var tool = GetHalconTool(null, "", opConfig.AlgorithemPath);
+ var ret = tool.RunProcedure(null, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results" }, null);
+
+
+ if (ret == null)
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鑴氭湰{opConfig.AlgorithemPath}杩愯寮傚父锛岃繑鍥炲�间负null");
+ }
+ else if (!ret.Item1)
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鑴氭湰{opConfig.AlgorithemPath}杩愯寮傚父锛寋ret.Item4}");
+ }
+ else
+ {
+ List<double> datas = ret.Item2["OUTPUT_Results"].HTupleToDouble();
+ opConfig.Products[0].Centermatrix = datas;
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{opConfig.Products[0].PID}鐭╅樀鑾峰彇涓� {string.Join(',', datas)}");
+ }
+ }
+ return msg;
+ }
@@ -355,10 +534,340 @@
+ [ProcessMethod("", "MESup1", "MES涓婁紶杩涙枡鍙g┖绡�", InvokeType.TestInvoke)]
+ public ResponseMessage MESup1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+ {
+ ResponseMessage msg = new ResponseMessage();
+
+ //int num = Plc1.Read(1575, 1, out _)[0];
+ //mqtt.Send("1", "DS02216", "", "0", num.ToString());
+ //Plc1.WriteSingleAddress(1590, 1, out _);
+ if (ConfigAOI1.ISupMES)
+ {
+ string Msg = Task.Run(() => mqtt.MESForBasketAsync("1", "DS02216", "", "0", ConfigAOI1.mesnum1.ToString())).Result;
+
+ if (ConfigAOI1.ISokMes)
+ {
+ ConfigAOI1.mesnum1++;
+ Plc1.WriteSingleAddress(1590, 1, out _);
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"宸插己鍒禡ES涓婁紶杩涙枡鍙g┖绡�");
+ }
+ else
+ {
+ if (Msg != null)
+ {
+ try
+ {
+ var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
+ if (obj?.zstatus == "200")
+ {
+ ConfigAOI1.mesnum1++;
+ Plc1.WriteSingleAddress(1590, 1, out _);
+ }
+ 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}");
+
+ }
+ catch
+ {
+
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 杩涙枡鍙g┖绡� 鑾峰彇杩斿洖鍊艰В鏋愬紓甯� 杩斿洖鏁版嵁{Msg} ");
+ Plc1.WriteSingleAddress(1590, 2, out _);
+ }
+ }
+ else
+ {
+ Plc1.WriteSingleAddress(1590, 2, out _);
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 杩涙枡鍙g┖绡� 鑾峰彇杩斿洖鍊煎け璐� 杩斿洖鏁版嵁null ");
+ }
+ }
+ }
+ else
+ {
+ Plc1.WriteSingleAddress(1590, 1, out _);
+
+ }
+
+ return msg;
+ }
+ [ProcessMethod("", "MESup2", "MES涓婁紶杩涙枡鍙f弧杞�", InvokeType.TestInvoke)]
+ public ResponseMessage MESup2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+ {
+ ResponseMessage msg = new ResponseMessage();
+ //int num = Plc1.Read(1575, 1, out _)[0];
+
+ //mqtt.Send("1", "DS02216", "", "1", num.ToString());
+ //Plc1.WriteSingleAddress(1590, 1, out _);
+
+ if (ConfigAOI1.ISupMES)
+ {
+ string Msg = Task.Run(() => mqtt.MESForBasketAsync("1", "DS02216", "", "1", ConfigAOI1.mesnum1.ToString())).Result;
+ if (ConfigAOI1.ISokMes)
+ {
+ ConfigAOI1.mesnum1++;
+ Plc1.WriteSingleAddress(1590, 1, out _);
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"宸插己鍒禡ES涓婁紶杩涙枡鍙f弧杞�");
+ }
+ else
+ {
+ if (Msg != null)
+ {
+
+ try
+ {
+ var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
+ if (obj?.zstatus == "200")
+ {
+ ConfigAOI1.mesnum1++;
+ Plc1.WriteSingleAddress(1590, 1, out _);
+ }
+ 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 绡叿 杩涙枡鍙f弧杞� 涓婁紶{(obj?.zstatus == "200" ? "鎴愬姛" : "澶辫触")} {obj?.zstatus}");
+ }
+ catch
+ {
+ Plc1.WriteSingleAddress(1590, 2, out _);
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 杩涙枡鍙f弧杞� 鑾峰彇杩斿洖鍊艰В鏋愬紓甯� 杩斿洖鏁版嵁{Msg} ");
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 杩涙枡鍙f弧杞� 鑾峰彇杩斿洖鍊艰В鏋愬紓甯� 杩斿洖鏁版嵁null ");
+ Plc1.WriteSingleAddress(1590, 2, out _);
+ }
+ }
+ }
+ else
+ {
+ Plc1.WriteSingleAddress(1590, 1, out _);
+ }
+ return msg;
+ }
+ [ProcessMethod("", "MESup3", "MES涓婁紶涓嬫枡鍙g┖绡�", InvokeType.TestInvoke)]
+ public ResponseMessage MESup3(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+ {
+ ResponseMessage msg = new ResponseMessage();
+
+ if (ConfigAOI1.ISupMES)
+ {
+ int num = Plc1.Read(1578, 1, out _)[0];
+
+ string Msg = Task.Run(() => mqtt.MESForBasketAsync("3", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "0", ConfigAOI1.mesnum3.ToString())).Result;
+ if (Msg != null)
+ {
+
+ try
+ {
+ var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
+ if (obj?.zstatus == "200")
+ {
+ ConfigAOI1.mesnum3++;
+ Plc1.WriteSingleAddress(1591, 1, out _);
+ }
+ 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}");
+
+ }
+ catch
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 涓嬫枡鍙g┖绡� 鑾峰彇杩斿洖鍊艰В鏋愬紓甯� 杩斿洖鏁版嵁{Msg} ");
+ Plc1.WriteSingleAddress(1591, 2, out _);
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 杩涙枡鍙d笅鏂欏彛绌虹绌虹 鑾峰彇杩斿洖鍊艰В鏋愬紓甯� 杩斿洖鏁版嵁null ");
+ Plc1.WriteSingleAddress(1591, 2, out _);
+ }
+ }
+ else
+ {
+ Plc1.WriteSingleAddress(1591, 1, out _);
+ }
+
+ return msg;
+ }
+
+ [ProcessMethod("", "MESup4", "MES涓婁紶涓嬫枡鍙f弧杞�", InvokeType.TestInvoke)]
+ public ResponseMessage MESup4(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+ {
+ ResponseMessage msg = new ResponseMessage();
+
+ if (ConfigAOI1.ISupMES)
+ {
+ int num = Plc1.Read(1578, 1, out _)[0];
+ //mqtt.Send("3", "DS02217", ConfigAOI1.Dicbasketcode.ContainsKey(num) ? ConfigAOI1.Dicbasketcode[num] : ConfigAOI1.basketcode, "2", num.ToString());
+
+ string Msg = Task.Run(() => mqtt.MESForBasketAsync("3", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "2", ConfigAOI1.mesnum3.ToString())).Result;
+ if (Msg != null)
+ {
+ try
+ {
+ var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
+ if (obj?.zstatus == "200")
+ {
+ ConfigAOI1.mesnum3++;
+ }
+ 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
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 涓嬫枡鍙f弧杞�1 鑾峰彇杩斿洖鍊艰В鏋愬紓甯� 杩斿洖鏁版嵁{Msg} ");
+ }
+ }
+ else
+ {
+ 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;
+ if (Msg != null)
+ {
+ try
+ {
+ var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
+ if (obj?.zstatus == "200")
+ {
+ ConfigAOI1.mesnum4++;
+ Plc1.WriteSingleAddress(1591, 1, out _);
+ }
+ 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}");
+ }
+ catch
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 涓嬫枡鍙f弧杞� 鑾峰彇杩斿洖鍊艰В鏋愬紓甯� 杩斿洖鏁版嵁{Msg} ");
+ Plc1.WriteSingleAddress(1591, 2, out _);
+ }
+ }
+ else
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 涓嬫枡鍙f弧杞� 鑾峰彇杩斿洖鍊艰В鏋愬紓甯� 杩斿洖鏁版嵁null ");
+ Plc1.WriteSingleAddress(1591, 2, out _);
+ }
+ }
+ else
+ {
+ Plc1.WriteSingleAddress(1591, 1, out _);
+ }
+ return msg;
+ }
}
}
--
Gitblit v1.8.0