From a9e1d576c88a828baa766b5c38cce7bad0f3f25c Mon Sep 17 00:00:00 2001
From: kingno <30263@KINGNO>
Date: 星期二, 15 七月 2025 18:15:55 +0800
Subject: [PATCH] 对接客户MES,实时上传上料位,下料位篮具状态,上传产品信息

---
 src/Bro.M141.Process/MyMQTT.cs                 |  622 +++++++++++++++++++++++++
 src/Bro.M141.Process/UI/UIPrinter.cs           |   39 +
 src/Bro.M141_AOI1.Process/AOI1Process.cs       |  291 ++++++++++++
 src/Bro.M141.Process/M141Process_Mysql.cs      |    3 
 src/Bro.M141.Process/M141Config.cs             |  111 ++++
 src/Bro.M141.Process/Bro.M141.Process.csproj   |    8 
 src/Bro.M141.Process/M141Process.cs            |   75 ++
 src/Bro.M141.Process/M141Process_ImageCheck.cs |  129 +++++
 src/Bro.M141.Process/UI/UIPrinter.Designer.cs  |  130 +++++
 libs/Nuget/System.Threading.Channels.dll       |    0 
 10 files changed, 1,383 insertions(+), 25 deletions(-)

diff --git a/libs/Nuget/System.Threading.Channels.dll b/libs/Nuget/System.Threading.Channels.dll
new file mode 100644
index 0000000..629a3dc
--- /dev/null
+++ b/libs/Nuget/System.Threading.Channels.dll
Binary files differ
diff --git a/src/Bro.M141.Process/Bro.M141.Process.csproj b/src/Bro.M141.Process/Bro.M141.Process.csproj
index e050bca..17b8e84 100644
--- a/src/Bro.M141.Process/Bro.M141.Process.csproj
+++ b/src/Bro.M141.Process/Bro.M141.Process.csproj
@@ -15,6 +15,10 @@
 		<Exec Command="Copy $(SolutionDir)libs\PFW $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\SafetyDog $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\Nuget $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\halcon12 $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\HikCamera $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\IKAPCamera $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\InsCamera $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\WebServiceDll $(OutDir)" />
 	</Target>
 
+	<!--<ItemGroup>
+	  <Compile Include="MyMQTT.cs" />
+	</ItemGroup>-->
+
 	
 	<!--<ItemGroup>
 	  <Compile Include="M141Process_Mysql.cs" />
@@ -55,6 +59,7 @@
 	<ItemGroup>
 		<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
 		<PackageReference Include="NPOI" Version="2.7.1" />
+		<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
 		<PackageReference Include="ScottPlot.WinForms" Version="4.1.58" />
 		<PackageReference Include="System.ServiceModel.Duplex" Version="4.8.1" />
 		<PackageReference Include="System.ServiceModel.Federation" Version="4.8.1" />
@@ -158,6 +163,9 @@
 		<Reference Include="SunnyUI.Common">
 			<HintPath>..\..\libs\Nuget\SunnyUI.Common.dll</HintPath>
 		</Reference>
+		<Reference Include="System.Threading.Channels">
+		  <HintPath>..\..\libs\Nuget\System.Threading.Channels.dll</HintPath>
+		</Reference>
 		<Reference Include="zxing">
 		  <HintPath>..\..\libs\Nuget\zxing.dll</HintPath>
 		</Reference>
diff --git a/src/Bro.M141.Process/M141Config.cs b/src/Bro.M141.Process/M141Config.cs
index 7f46444..6323e49 100644
--- a/src/Bro.M141.Process/M141Config.cs
+++ b/src/Bro.M141.Process/M141Config.cs
@@ -6,6 +6,7 @@
 using Bro.Common.Model;
 using Bro.M135.Common;
 using Bro.Process;
+using MathNet.Numerics.Distributions;
 using Newtonsoft.Json;
 using System.ComponentModel;
 using System.Drawing.Design;
@@ -13,16 +14,13 @@
 using System.Drawing.Printing;
 using System.Reflection;
 using System.Windows.Forms.Design;
+using Windows.Services.Maps;
 using static Bro.Common.Helper.EnumHelper;
 
 namespace Bro.M141.Process
 {
     public class M141Config : ProcessConfigBase
     {
-      
-
-
-
 
 
         [Category("鎵撳嵃鏈洪厤缃�")]
@@ -73,7 +71,7 @@
         [Category("妫�娴嬪紓甯告寚绀�")]
         [Description("閫夋嫨鏌愪釜Spec锛屽叾琛ㄧず妫�娴嬭繃绋嬩腑寮傚父")]
         [DisplayName("寮傚父鎸囩ず鏍囧噯")]
-        [TypeConverter(typeof(SpecCodeSelectorConverter))] 
+        [TypeConverter(typeof(SpecCodeSelectorConverter))]
         public string CheckErrorSpecCode { get; set; } = "";
 
 
@@ -169,6 +167,15 @@
         [DisplayName("褰撳墠鏍忓叿鐮�")]
         public string basketcode { get; set; } = "NoRead";
 
+
+
+
+        [Category("鏍忓叿鏉$爜閰嶇疆")]
+        [Description("褰撳墠宸ュ崟鍙�")]
+        [DisplayName("褰撳墠宸ュ崟鍙�")]
+        public string zwoid { get; set; } = "";
+
+
         [Category("鏍忓叿鏉$爜閰嶇疆")]
         [Description("鏈珯鏄惁璇诲彇鏍忓叿鐮�")]
         [DisplayName("鏈珯鏄惁璇诲彇鏍忓叿鐮�")]
@@ -187,6 +194,86 @@
         [Description("蹇冭烦鍦板潃")]
         [DisplayName("蹇冭烦鍦板潃")]
         public int heartadd { get; set; } = 1505;
+
+
+
+        [Category("MES閰嶇疆")]
+        [Description("鏄惁涓婁紶MES")]
+        [DisplayName("鏄惁涓婁紶MES")]
+        public bool ISupMES { get; set; } = false;
+
+        [Category("MES閰嶇疆")]
+        [Description("鎺ュ彛閫夋嫨,0绡叿鎺ュ彛,1鏁版嵁涓婁紶鎺ュ彛,-1鎵�鏈夋帴鍙�")]
+        [DisplayName("鎺ュ彛閫夋嫨")]
+        public int MESchannel { get; set; } = 0;
+
+
+
+        [Category("MES閰嶇疆")]
+        [Description("璐﹀彿")]
+        [DisplayName("璐﹀彿")]
+        public string zuser { get; set; } = "aoiUser";
+
+        [Category("MES閰嶇疆")]
+        [Description("瀵嗙爜")]
+        [DisplayName("瀵嗙爜")]
+        public string zpassword { get; set; } = "Chia@aoi";
+
+        [Category("MES閰嶇疆")]
+        [Description("IP")]
+        [DisplayName("Ip")]
+        public string zIP { get; set; } = "10.2.20.114";
+
+        [Category("MES閰嶇疆")]
+        [Description("绔彛鍙�")]
+        [DisplayName("绔彛鍙�")]
+        public int zport { get; set; } = 15672;
+
+
+
+        //[Category("MES閰嶇疆")]
+        //[Description("澶囩敤鏍忓叿鐮�")]
+        //[DisplayName("澶囩敤鏍忓叿鐮�")]
+        //public string basketcode2 { get; set; } = "NoRead";
+
+        [Category("MES閰嶇疆")]
+        [Description("numpro")]
+        [DisplayName("numpro")]
+        [JsonIgnore]
+        public int numpro { get; set; } = 0;
+
+        [Category("MES閰嶇疆")]
+        [Description("mesnum1")]
+        [DisplayName("mesnum1")]
+        [JsonIgnore]
+        public int mesnum1 { get; set; } = 0;
+
+        [Category("MES閰嶇疆")]
+        [Description("mesnum2")]
+        [DisplayName("mesnum2")]
+        [JsonIgnore]
+        public int mesnum2 { get; set; } = 0;
+
+        [Category("MES閰嶇疆")]
+        [Description("mesnum3")]
+        [DisplayName("mesnum3")]
+        [JsonIgnore]
+        public int mesnum3 { get; set; } = 0;
+
+        [Category("MES閰嶇疆")]
+        [Description("mesnum4")]
+        [DisplayName("mesnum4")]
+        [JsonIgnore]
+        public int mesnum4 { get; set; } = 0;
+
+
+
+        [Category("MES閰嶇疆")]
+        [Description("plc搴忓彿鍜岀鍏风爜闆嗗悎")]
+        [DisplayName("plc搴忓彿鍜岀鍏风爜闆嗗悎")]
+        [TypeConverter(typeof(CollectionCountConvert))]
+        [Editor(typeof(ComplexCollectionEditor<PlcAndBasketcode>), typeof(UITypeEditor))]
+        public List<PlcAndBasketcode> PlcAndBasketcodes { get; set; } = new List<PlcAndBasketcode>();
 
 
     }
@@ -318,7 +405,7 @@
             {
                 var temchar = data.Split(',');
                 ret.alarmname = temchar[0];
-                ret.address =Convert.ToInt32(temchar[1]);
+                ret.address = Convert.ToInt32(temchar[1]);
                 ret.address2 = Convert.ToInt32(temchar[2]);
             }
             catch (Exception ex)
@@ -378,7 +465,19 @@
     }
 
 
+    public class PlcAndBasketcode
+    {
+        [Category("閰嶇疆")]
+        [Description("搴忓彿")]
+        [DisplayName("搴忓彿")]
+        public int id { get; set; } = 0;
 
+        [Category("閰嶇疆")]
+        [Description("鏉$爜")]
+        [DisplayName("鏉$爜")]
+        public string code { get; set; }
+
+    }
 
 
 
diff --git a/src/Bro.M141.Process/M141Process.cs b/src/Bro.M141.Process/M141Process.cs
index 3302e67..21f4dc8 100644
--- a/src/Bro.M141.Process/M141Process.cs
+++ b/src/Bro.M141.Process/M141Process.cs
@@ -94,10 +94,17 @@
         PLCBase Plc2;
         public Thread ThHeartPlc;
 
+        public RabbitMQHelper mqtt;
+
+
+
+
+
 
         public override void Open()
         {
             base.Open();
+
             devicestate = true;
             ML = DeviceCollection.FirstOrDefault(u => u is MachineLearningBase) as MachineLearningBase;
             if (ML == null)
@@ -121,6 +128,15 @@
 
             mysqlhelper.IniDBIP(M141Config.IPforall);
             RerefreshBasketcode();
+
+
+            if (M141Config.ISupMES)
+            {
+                mqtt = new RabbitMQHelper(M141Config.zIP, M141Config.zport, M141Config.zuser, M141Config.zpassword);
+                mqtt.Connect(M141Config.MESchannel);
+            }
+
+
         }
 
 
@@ -327,6 +343,27 @@
 
                 }
 
+
+
+                try
+                {
+                    if (Plc1 != null)
+                    {
+                        DateTime dt = DateTime.Now;
+                        Plc1.WriteSingleAddress(10, dt.Year, out _);
+                        Plc1.WriteSingleAddress(11, dt.Month, out _);
+                        Plc1.WriteSingleAddress(12, dt.Day, out _);
+                        Plc1.WriteSingleAddress(13, dt.Hour, out _);
+                        Plc1.WriteSingleAddress(14, dt.Minute, out _);
+                        Plc1.WriteSingleAddress(15, dt.Second, out _);
+                        Plc1.WriteSingleAddress(16, (int)dt.DayOfWeek, out _);
+                    }
+                }
+                catch
+                {
+
+                }
+
                 Thread.Sleep(1000);
             }
         }
@@ -513,18 +550,22 @@
                     {
                         string detectionName = (ML.InitialConfig as MLInitialConfigBase).DetectionConfigs.FirstOrDefault(u => u.Id == measureBind.DetectionId)?.Name;
 
-
-
                         List<DetectResult> detectResults = ML?.RunMLDetectionSync(imgSet, pidList, measureBind.DetectionId, false, null, null, "", products[0].ImagePaths);
 
 
 
                         if (measureBind.WorkPosition == "P1" && M141Config.StationCode == "S5" && detectResults.GetDefectDescList().Count == 0)
                         {
-                            var defecttem = detectResults.SelectMany(u => u.NetResults.SelectMany(m => m.DetectDetails)).Where(u => u.NetName == M141Config.defectname).ToList();
+                            var defecttem = detectResults.SelectMany(u => u.AllNetResults.SelectMany(m => m.DetectDetails)).Where(u => u.ClassName == M141Config.defectname).ToList();
+
                             List<Netdefectdetail> Netdefectdetails = mysqlhelper.GetNetdefectdetails(products[0].SEQUENCE);
 
-                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN} 杩涘叆S3S5妫�娴� S3鏁版嵁{Netdefectdetails.Count}  S5鏁版嵁{defecttem.Count}");
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5妫�娴� S3鏁版嵁{Netdefectdetails.Count}  S5鏁版嵁{defecttem.Count}");
+
+                            Netdefectdetails.ForEach(x =>
+                            {
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5妫�娴� S3鏁版嵁{x.name}  {x.centerX},{x.centerY} ");
+                            });
 
                             int num = 0;
                             foreach (var item1 in defecttem)
@@ -532,12 +573,13 @@
                                 double x1 = item1.Rect.Point_LU.X + item1.Rect.Width / 2.0;
                                 double y1 = item1.Rect.Point_LU.Y + item1.Rect.Height / 2.0;
                                 num++;
+
                                 //HOperatorSet.AffineTransPoint2d(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
                                 //HOperatorSet.ProjectiveTransPixel(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
 
-                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}鍘熷潗鏍噞num}   {x1},{y1}");
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5妫�娴�  鍘熷潗鏍噞num}   {x1},{y1}");
                                 HOperatorSet.ProjectiveTransPixel(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
-                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}鏂板潗鏍噞num}   {qx},{qy}");
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5妫�娴�  鏂板潗鏍噞num}   {qx},{qy}");
 
 
                                 Netdefectdetail temc = new Netdefectdetail()
@@ -1158,7 +1200,26 @@
 
                         //UpdatePositionResultToDB(detail);
                         //var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
-                        ReplyPlcData(positionSet, plcresult);
+
+                        if (M141Config.StationCode == "S4" && isOK)
+                        {
+                            ////mysqlhelper.GetS2Result(productList[0].SEQUENCE);
+                            //Plc1.WriteSingleAddress(1526, mysqlhelper.GetS2Result(productList[0].SEQUENCE) ? 1 : 2, out _);
+
+                            bool temS2 = mysqlhelper.GetS2Result(p.SEQUENCE);
+                            ReplyPlcData(positionSet, new List<bool>() { temS2 });
+                            if (!temS2)
+                            {
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"{p.SN}    S2宸ョ珯NG鎶涙枡");
+                            }
+                        }
+                        else
+                        {
+                            ReplyPlcData(positionSet, plcresult);
+                        }
+
+
+
                         mysqlhelper.UpdateProduct(p);
                         if (positionSet.IsLastPosition)
                         {
diff --git a/src/Bro.M141.Process/M141Process_ImageCheck.cs b/src/Bro.M141.Process/M141Process_ImageCheck.cs
index dfcf451..6eb5b46 100644
--- a/src/Bro.M141.Process/M141Process_ImageCheck.cs
+++ b/src/Bro.M141.Process/M141Process_ImageCheck.cs
@@ -9,6 +9,7 @@
 using Microsoft.VisualBasic;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
+using NPOI.SS.Formula.Functions;
 using NPOI.SS.UserModel;
 using NPOI.Util;
 using NPOI.XSSF.UserModel;
@@ -450,7 +451,8 @@
         public ResponseMessage ProductDataUpload(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
         {
             ResponseMessage msg = new ResponseMessage();
-            string inputSequence = Plc1.Read(1536, 1, out _)[0].ToString();
+            int numplca = Plc1.Read(1536, 1, out _)[0];
+            string inputSequence = numplca.ToString();
 
             var productList = new List<int>() { 1 }.Select(u =>
             {
@@ -458,6 +460,10 @@
                 return FindProductBySequence(sequence, true);
             }).ToList();
 
+            if (PlcNumForAll == -1)
+            {
+                PlcNumForAll = numplca;
+            }
 
             int waitInterval = 300;
             int repeatTime = M141Config.DetectTimeout / waitInterval;
@@ -496,9 +502,128 @@
 
             Plc1.WriteSingleAddress(1516, 1, out _);
 
+            if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
+            {
+                if (M141Config.numpro >= 50)
+                {
+                    M141Config.numpro = 0;
+                }
+
+                if (productList[0].Result == "OK")
+                {
+                    M141Config.numpro++;
+                }
+
+                //mqtt.demes(productList[0], M141Config.zwoid);
+                string Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(productList[0], M141Config.zwoid, M141Config.numpro)).Result;
+                if (Msgreceice == null)
+                {
+                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull");
+                }
+                else
+                {
+                    try
+                    {
+                        var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
+
+                        if (obj.zstatus == "200")
+                        {
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES鎴愬姛  {Msgreceice}");
+                        }
+                        else
+                        {
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES澶辫触  {Msgreceice}");
+                        }
+                    }
+                    catch
+                    {
+                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父  {Msgreceice}");
+                    }
+                }
+
+
+
+                lock (plcnumlock)
+                {
+                    int differ = numplca - PlcNumForAll;
+                    if (differ > 1)
+                    {
+                        for (int i = PlcNumForAll + 1; i < numplca; i++)
+                        {
+                            try
+                            {
+                                var plist = mysqlhelper.GetProductList(i + "_1");
+                                ProductModel newp = new ProductModel();
+                                newp.SEQUENCE = plist[0].SEQUENCE;
+                                newp.PID = plist[0].PID;
+                                newp.BasketCode = plist[0].BasketCode;
+                                newp.Result = "NG";
+                                newp.SN = plist[0].SN;
+                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+
+                            }
+                            catch
+                            {
+
+                            }
+                        }
+                    }
+                    else if (differ != -29998)
+                    {
+                        for (int i = PlcNumForAll + 1; i <= 29999; i++)
+                        {
+                            try
+                            {
+                                var plist = mysqlhelper.GetProductList(i + "_1");
+                                ProductModel newp = new ProductModel();
+                                newp.SEQUENCE = plist[0].SEQUENCE;
+                                newp.PID = plist[0].PID;
+                                newp.BasketCode = plist[0].BasketCode;
+                                newp.Result = "NG";
+                                newp.SN = plist[0].SN;
+                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+
+                            }
+                            catch
+                            {
+
+                            }
+                        }
+
+
+
+                        for (int i = 1; i < numplca; i++)
+                        {
+                            try
+                            {
+                                var plist = mysqlhelper.GetProductList(i + "_1");
+                                ProductModel newp = new ProductModel();
+                                newp.SEQUENCE = plist[0].SEQUENCE;
+                                newp.PID = plist[0].PID;
+                                newp.BasketCode = plist[0].BasketCode;
+                                newp.Result = "NG";
+                                newp.SN = plist[0].SN;
+                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+
+                            }
+                            catch
+                            {
+
+                            }
+                        }
+
+
+                    }
+                    PlcNumForAll = numplca;
+                }
+
+            }
+
             return msg;
         }
 
+        object plcnumlock = new object();
+        int PlcNumForAll = -1;
 
         private bool _isDemoStarted = false;
         [ProcessMethod("OfflineDemo", "OfflineDemo", "绂荤嚎娴嬭瘯", InvokeType.CalibInvoke)]
@@ -552,7 +677,7 @@
                         continue;
                     }
 
-                    var sn = nameDatas[0]+"_1";
+                    var sn = nameDatas[0] + "_1";
                     var imageSeq = nameDatas[2][^1].ToString();
                     var measureBind = M141Config.MeasureBindCollection.FirstOrDefault(u => u.ImageSaveSeq == imageSeq);
 
diff --git a/src/Bro.M141.Process/M141Process_Mysql.cs b/src/Bro.M141.Process/M141Process_Mysql.cs
index 59cd94f..bb67d25 100644
--- a/src/Bro.M141.Process/M141Process_Mysql.cs
+++ b/src/Bro.M141.Process/M141Process_Mysql.cs
@@ -199,7 +199,7 @@
                     //string destr = "delete from forall where id not in (select id from (select id from forall order BY id desc limit 1000) as subquery)";
                     //Operatoremysql(destr, connStrAll);
 
-                    if (string.IsNullOrEmpty(netname) /*|| devicestr != "S3" */)
+                    if (string.IsNullOrEmpty(netname) || devicestr != "S3")
                     {
                         if (pro.Details != null)
                         {
@@ -213,7 +213,6 @@
                                     item.DefectList.AddRange(defects.Distinct());
                                     item.DefectList = item.DefectList.Distinct().ToList();
                                 }
-
                             }
                         }
                     }
diff --git a/src/Bro.M141.Process/MyMQTT.cs b/src/Bro.M141.Process/MyMQTT.cs
new file mode 100644
index 0000000..78ce1c3
--- /dev/null
+++ b/src/Bro.M141.Process/MyMQTT.cs
@@ -0,0 +1,622 @@
+锘縰sing Bro.Common.Helper;
+using Bro.M135.Common;
+using Bro.Process.DataBase.Models;
+using Microsoft.VisualBasic.Devices;
+using Newtonsoft.Json;
+using Org.BouncyCastle.Asn1.Pkcs;
+using Org.BouncyCastle.Utilities.Encoders;
+using RabbitMQ.Client;
+using RabbitMQ.Client.Events;
+using SourceGrid.Cells.Editors;
+using Sunny.UI.Win32;
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Bro.M141.Process
+{
+    public class RabbitMQHelper
+    {
+        private readonly ConnectionFactory _factory;
+        private IConnection _connection;
+        private IModel _sendChannel;
+        private IModel _receiveChannel1;
+        private IModel _receiveChannel2;
+
+        private readonly ConcurrentDictionary<string, TaskCompletionSource<string>> _pendingTask1 = new();
+        private readonly ConcurrentDictionary<string, TaskCompletionSource<string>> _pendingTask2 = new();
+
+        private readonly string _queue1 = "auto_line_mac_queue_bak";
+        private readonly string _queue2 = "auto_line_mac_barcode_queue_bak";
+
+        public RabbitMQHelper(string host = "10.2.20.114", int port = 15672, string user = "aoiUser", string pwd = "Chia@aoi")
+        {
+            _factory = new ConnectionFactory
+            {
+                HostName = host,
+                Port = port,
+                UserName = user,
+                Password = pwd,
+                VirtualHost = "/",
+                Ssl = new SslOption { Enabled = false },
+                AutomaticRecoveryEnabled = true,
+                NetworkRecoveryInterval = TimeSpan.FromMilliseconds(5000),
+                RequestedConnectionTimeout = TimeSpan.FromMilliseconds(3000)
+            };
+        }
+
+        public void Connect(int channel)
+        {
+            if (_connection != null && _connection.IsOpen) return;
+
+            _connection = _factory.CreateConnection();
+            _sendChannel = _connection.CreateModel();
+
+
+            if (channel == 0)
+            {
+                _receiveChannel1 = _connection.CreateModel();
+                InitConsumer(_receiveChannel1, _queue1, HandleQueue1Message);
+            }
+            else if (channel == 1)
+            {
+                _receiveChannel2 = _connection.CreateModel();
+                InitConsumer(_receiveChannel2, _queue2, HandleQueue2Message);
+            }
+            else if (channel == -1)
+            {
+                _receiveChannel1 = _connection.CreateModel();
+                InitConsumer(_receiveChannel1, _queue1, HandleQueue1Message);
+                _receiveChannel2 = _connection.CreateModel();
+                InitConsumer(_receiveChannel2, _queue2, HandleQueue2Message);
+            }
+
+
+
+            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, "RabbitMQ 杩炴帴鎴愬姛");
+        }
+
+        private void InitConsumer(IModel channel, string queueName, Action<string> handler)
+        {
+            channel.QueueDeclare(queueName, durable: true, exclusive: false, autoDelete: false);
+            var consumer = new EventingBasicConsumer(channel);
+            consumer.Received += (_, ea) =>
+            {
+                var msg = Encoding.UTF8.GetString(ea.Body.ToArray());
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 鏀跺埌娑堟伅 [{queueName}]锛歿msg}");
+                handler?.Invoke(msg);
+                channel.BasicAck(ea.DeliveryTag, false);
+            };
+            channel.BasicConsume(queue: queueName, autoAck: false, consumer: consumer);
+        }
+
+        private void HandleQueue1Message(string message)
+        {
+            try
+            {
+                var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(message);
+                if (obj?.zbguid != null && _pendingTask1.TryRemove(obj.zbguid, out var tcs))
+                {
+                    tcs.TrySetResult(message);
+                }
+                else
+                {
+                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 绡叿 鏀跺埌鏈尮閰� zbguid锛歿obj?.zbguid}");
+                }
+            }
+            catch (Exception ex)
+            {
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 瑙f瀽寮傚父锛歿ex.Message}");
+            }
+        }
+
+        private void HandleQueue2Message(string message)
+        {
+            try
+            {
+                var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(message);
+                if (obj?.zbguid != null && _pendingTask2.TryRemove(obj.zbguid, out var tcs))
+                {
+                    tcs.TrySetResult(message);
+                }
+                else
+                {
+                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 鐗╂枡 鏀跺埌鏈尮閰� zbguid锛歿obj?.zbguid}");
+                }
+            }
+            catch (Exception ex)
+            {
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 鐗╂枡 瑙f瀽寮傚父锛歿ex.Message}");
+            }
+        }
+
+        public async Task<string> MESForBasketAsync(string ztype, string zlsn, string zlpn, string zstatus, string zversion, int timeoutMs = 3000)
+        {
+            var guid = Guid.NewGuid().ToString();
+            var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
+            _pendingTask1[guid] = tcs;
+
+            var msgObj = new AutoLineMacQueue
+            {
+                zbguid = guid,
+                zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
+                ztype = ztype,
+                zversion = zversion,
+                zline = "NQ216",
+                zlsn = zlsn,
+                zlpn = zlpn,
+                zstatus = zstatus
+            };
+
+            var message = JsonConvert.SerializeObject(msgObj);
+            var body = Encoding.UTF8.GetBytes(message);
+            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 绡叿 鍙戦��1锛歿message}");
+            _sendChannel.BasicPublish("", "auto_line_mac_queue", null, body);
+
+            var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
+            _pendingTask1.TryRemove(guid, out _);
+            if (completed == tcs.Task)
+                return await tcs.Task;
+            else
+            {
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 绡叿 杩斿洖瓒呮椂1锛寊bguid={guid}");
+                return null;
+            }
+        }
+
+        public async Task<string> MESForProduceAsync(ProductModel pro, string zwoid, int znonum, string endtray = "N", string line = "NQ216", int timeoutMs = 3000)
+        {
+            var guid = Guid.NewGuid().ToString();
+            var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
+            _pendingTask2[guid] = tcs;
+
+
+            var msgObj = new AutoLineMacBarcodeQueue
+            {
+                zbguid = guid,
+                zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
+                zline = line,
+                zbarcode = pro.SN,
+                zresult = string.IsNullOrWhiteSpace(pro.Result) ? "NG" : pro.Result,
+                zreson = pro.Result == "OK" ? "" : "SZ2014",
+                zno = znonum.ToString(),
+                zwoid = zwoid,
+                endtray = endtray
+            };
+
+            var message = JsonConvert.SerializeObject(msgObj);
+            var body = Encoding.UTF8.GetBytes(message);
+            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ鍙戦�佷骇鍝亄pro.PID} 鏁版嵁2锛歿message}");
+            _sendChannel.BasicPublish("", "auto_line_mac_barcode_queue", null, body);
+
+            var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
+            _pendingTask2.TryRemove(guid, out _);
+            if (completed == tcs.Task)
+                return await tcs.Task;
+            else
+            {
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ杩斿洖瓒呮椂2锛孭ID={pro.PID}");
+                return null;
+            }
+        }
+
+        public void Disconnect()
+        {
+            _sendChannel?.Close();
+            _receiveChannel1?.Close();
+            _receiveChannel2?.Close();
+            _connection?.Close();
+            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 杩炴帴鏂紑");
+        }
+    }
+
+
+
+
+
+
+    //using Bro.Common.Helper;
+    //using Bro.M135.Common;
+    //using Bro.Process.DataBase.Models;
+    //using Microsoft.VisualBasic.Devices;
+    //using Newtonsoft.Json;
+    //using Org.BouncyCastle.Asn1.Pkcs;
+    //using Org.BouncyCastle.Utilities.Encoders;
+    //using RabbitMQ.Client;
+    //using RabbitMQ.Client.Events;
+    //using SourceGrid.Cells.Editors;
+    //using Sunny.UI.Win32;
+    //using System;
+    //using System.Collections.Generic;
+    //using System.Linq;
+    //using System.Text;
+    //using System.Threading.Tasks;
+
+    //namespace Bro.M141.Process
+    //{
+
+
+    //    public class RabbitMQHelper
+    //    {
+    //        private readonly ConnectionFactory _factory;
+    //        private IConnection _connection;
+    //        private IModel _sendChannel;
+    //        private IModel _receiveChannel1;
+    //        private IModel _receiveChannel2;
+    //        private EventingBasicConsumer _consumer1;
+    //        private EventingBasicConsumer _consumer2;
+
+    //        private TaskCompletionSource<string> _responseTcs1;
+    //        private TaskCompletionSource<string> _responseTcs2;
+    //        private readonly object _lock1 = new();
+    //        private readonly object _lock2 = new();
+
+
+    //        private readonly string _queue1 = "auto_line_mac_queue_bak";
+    //        private readonly string _queue2 = "auto_line_mac_barcode_queue_bak";
+
+
+    //        public string AAzword { get; private set; }
+
+
+    //        public RabbitMQHelper(string _host = "10.2.20.114", int _port = 15672, string _user = "aoiUser", string _pwd = "Chia@aoi")
+    //        {
+    //            _factory = new ConnectionFactory
+    //            {
+    //                HostName = _host,
+    //                Port = _port,
+    //                UserName = _user,
+    //                Password = _pwd,
+    //                VirtualHost = "/",
+    //                Ssl = new SslOption { Enabled = false },
+    //                AutomaticRecoveryEnabled = true,
+    //                NetworkRecoveryInterval = TimeSpan.FromMilliseconds(5000),//鎺夌嚎5绉掕嚜鍔ㄩ噸杩�
+    //                RequestedConnectionTimeout = TimeSpan.FromMilliseconds(3000)//杩炴帴瓒呮椂
+    //            };
+    //        }
+
+    //        public void Connect()
+    //        {
+    //            if (_connection != null && _connection.IsOpen) return;
+
+    //            _connection = _factory.CreateConnection();
+    //            _sendChannel = _connection.CreateModel();
+    //            _receiveChannel1 = _connection.CreateModel();
+    //            _receiveChannel2 = _connection.CreateModel();
+
+    //            InitConsumer(_receiveChannel1, _queue1, HandleQueue1Message);
+    //            InitConsumer(_receiveChannel2, _queue2, HandleQueue2Message);
+    //            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 杩炴帴鎴愬姛");
+    //        }
+
+    //        private void InitConsumer(IModel channel, string queueName, Action<string> handler)
+    //        {
+    //            channel.QueueDeclare(queueName, durable: true, exclusive: false, autoDelete: false);
+    //            var consumer = new EventingBasicConsumer(channel);
+    //            consumer.Received += (model, ea) =>
+    //            {
+    //                var msg = Encoding.UTF8.GetString(ea.Body.ToArray());
+    //                handler?.Invoke(msg);
+    //                channel.BasicAck(ea.DeliveryTag, false);
+    //            };
+    //            channel.BasicConsume(queue: queueName, autoAck: false, consumer: consumer);
+    //        }
+
+    //        private void HandleQueue1Message(string message)
+    //        {
+    //            lock (_lock1)
+    //            {
+    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ鏀跺埌1  {message}");
+    //                _responseTcs1?.TrySetResult(message);
+    //            }
+    //        }
+
+    //        private void HandleQueue2Message(string message)
+    //        {
+    //            lock (_lock2)
+    //            {
+    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ鏀跺埌2  {message}");
+    //                _responseTcs2?.TrySetResult(message);
+    //            }
+    //        }
+
+    //        public async Task<string> MESForBasketAsync(string ztype, string zlsn, string zlpn, string zstatus, string zversion, int timeoutMs = 3000)
+    //        {
+    //            try
+    //            {
+
+    //                var guid = Guid.NewGuid().ToString();
+    //                var md = new AutoLineMacQueue
+    //                {
+    //                    zbguid = guid,
+    //                    zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
+    //                    ztype = ztype,
+    //                    zversion = zversion,
+    //                    zline = "NQ216",
+    //                    zlsn = zlsn,
+    //                    zlpn = zlpn,
+    //                    zstatus = zstatus
+    //                };
+
+    //                var message = JsonConvert.SerializeObject(md);
+
+    //                var body = Encoding.UTF8.GetBytes(message);
+    //                var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
+
+    //                void FeedbackHandler(string raw)
+    //                {
+    //                    try
+    //                    {
+    //                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(raw);
+    //                        if (obj?.zbguid == guid)
+    //                        {
+    //                            tcs.TrySetResult(raw);
+    //                        }
+    //                        else
+    //                        {
+    //                            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"1涓嶄竴鑷�  鍙憑guid}  鏀秢obj?.zbguid}");
+    //                        }
+    //                    }
+    //                    catch (Exception eex)
+    //                    {
+    //                        CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, eex.ToString());
+    //                    }
+    //                }
+    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ鍙戦��1  {message}");
+    //                lock (_lock1)
+    //                {
+    //                    _responseTcs1 = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
+    //                    _responseTcs1.Task.ContinueWith(t => { if (t.Result != null) FeedbackHandler(t.Result); });
+    //                    _sendChannel.BasicPublish("", "auto_line_mac_queue", null, body);
+    //                }
+
+
+
+    //                var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
+    //                return completed == tcs.Task ? await tcs.Task : null;
+    //            }
+    //            catch (Exception ee)
+    //            {
+    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, ee.ToString());
+    //            }
+    //            return null;
+    //        }
+
+    //        public async Task<string> MESForproduceAsync(ProductModel pro, string zwoid, int znonum, string line = "NQ216", int timeoutMs = 3000)
+    //        {
+    //            try
+    //            {
+
+
+    //                var guid = Guid.NewGuid().ToString();
+    //                AutoLineMacBarcodeQueue md = new AutoLineMacBarcodeQueue
+    //                {
+    //                    zbguid = guid,
+    //                    zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
+    //                    zline = line,
+    //                    zbarcode = pro.SN,
+    //                    zresult = pro.Result == "" ? "NG" : pro.Result,
+    //                    zreson = pro.Result == "OK" ? "" : "SZ2014",
+    //                    zno = znonum.ToString(),
+    //                    //zno = "1",
+    //                    zwoid = zwoid,
+    //                    endtray = "N",
+    //                    //endtray = "Y"
+    //                };
+
+
+
+
+    //                string message = JsonConvert.SerializeObject(md);
+    //                var body = Encoding.UTF8.GetBytes(message);
+    //                var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
+
+    //                void FeedbackHandler(string raw)
+    //                {
+    //                    try
+    //                    {
+    //                        var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(raw);
+    //                        if (obj?.zbguid == guid)
+    //                        {
+    //                            tcs.TrySetResult(raw);
+    //                        }
+    //                        else
+    //                        {
+    //                            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"2涓嶄竴鑷�  鍙憑guid}  鏀秢obj?.zbguid}");
+    //                        }
+    //                    }
+    //                    catch (Exception eex)
+    //                    {
+    //                        CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, eex.ToString());
+    //                    }
+    //                }
+
+    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ鍙戦�佷骇鍝亄pro.PID}鏁版嵁2     {message}");
+    //                lock (_lock2)
+    //                {
+    //                    _responseTcs2 = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
+    //                    _responseTcs2.Task.ContinueWith(t => { if (t.Result != null) FeedbackHandler(t.Result); });
+    //                    _sendChannel.BasicPublish("", "auto_line_mac_barcode_queue", null, body);
+    //                }
+
+
+    //                var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
+    //                return completed == tcs.Task ? await tcs.Task : null;
+    //            }
+    //            catch (Exception ee)
+    //            {
+    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, ee.ToString());
+    //            }
+    //            return null;
+    //        }
+
+
+
+
+    //        public void Disconnect()
+    //        {
+    //            _sendChannel?.Close();
+    //            _receiveChannel1?.Close();
+    //            _receiveChannel2?.Close();
+    //            _connection?.Close();
+    //        }
+
+
+
+    //    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    public class AutoLineMacQueue
+    {
+        /// <summary>
+        /// 鍞竴ID
+        /// </summary>
+        public string zbguid { get; set; } = Guid.NewGuid().ToString();
+
+        /// <summary>
+        /// 鏃堕棿鎴筹紝绮剧‘鍒拌�楃
+        /// </summary>
+        public string zdate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff");
+
+        /// <summary>
+        /// 1锛氬叆鍙f灦瀛愮姸鎬佷笂鎶�
+        ///2锛氬紑濮嬩綔涓氾紙3鍙蜂綅鎵爜鍚庯紝寮�濮嬭В缁戯級
+        ///3锛氬嚭鍙f灦瀛愮姸鎬佷笂鎶�
+        ///4锛氬嚭绌虹锛堢瀛愬凡缁忓仠鍦�4鍙蜂綅锛�
+        /// </summary>
+        public string ztype { get; set; }
+
+        /// <summary>
+        /// 姣忎釜ztype涓嬪搴旂嫭绔嬩竴涓簭鍒楀彿锛屼竴涓笟鍔″姩浣滀竴涓紝浠�0寮�濮嬶紝
+        /// 姣忔鍔�1锛屽埌杈鹃槇鍊煎悗鍙噸缃紙姣斿100鍚庝粠0寮�濮嬶級锛屽彧瑕佸拰涓婁竴
+        /// 娆$殑涓嶄竴鏍峰嵆鍙�
+        /// 涓氬姟鍔ㄤ綔瑙i噴锛氭瘮濡倆type涓�2鏃讹紝Q01-000001瑙g粦鏃朵紶搴忓垪鍙�1锛�
+        /// 濡傛灉Q01-000001鍦ㄤ竴浜涘紓甯告儏鍐典笅锛岄渶瑕侀噸璇曞垯杩樻槸浼犲簭鍒楀彿涓�1,
+        /// 涓嬩竴涓猀01-000002瑙g粦鏃朵紶搴忓垪鍙�2
+        /// 閫氫織鐨勮锛氫竴涓獄type+zversion鍙兘鎴愬姛澶勭悊涓�娆★紙闃堝�奸噸缃鑷�
+        /// 鐨勯噸澶嶉櫎澶栵級
+        /// </summary>
+        public string zversion { get; set; }
+
+        /// <summary>
+        /// 鐩墠鍥哄畾NQ216锛堣嫢鍚庢湡鎵╁睍绾块渶涓庡搴旂嚎鍒獻D涓�鑷达級
+        /// </summary>
+        public string zline { get; set; }
+
+        /// <summary>
+        /// ztype涓�1鏃讹細DS02216
+        /// ztype涓�2,3,4鏃讹細DS02217锛堣嫢鍚庢湡鎵╁睍绾块渶涓庡強鏋跺瓙ID涓�鑷达級
+        /// </summary>
+        public string zlsn { get; set; }
+
+        /// <summary>
+        /// MES鍙帴鏀舵纭牸寮忕殑鏁版嵁锛屽Q01-000001锛岄敊璇暟鎹細杩斿洖
+        /// 999锛屽閬囧埌鏈壂鍒扮爜涔嬬被鐨勯棶棰橈紝鐢辫澶囬噸鎵鐞嗗悗锛屽彇鍒版纭�
+        /// 绡叿鐮佸悗锛屽啀涓婃姏缁橫ES
+        /// </summary>
+        public string zlpn { get; set; }
+
+        /// <summary>
+        /// 0锛氭灦瀛愮┖闂诧紙1鍙蜂綅鎼埌2鍙蜂綅瀹屾垚銆�4鍙蜂綅agv宸茶浇璧扮瀛愶級
+        /// 1锛氭灦瀛愭弧杞斤紙1鍙蜂綅agv閫佺宸插埌浣嶏級
+        /// 2锛氶婊¤浇锛堣〃绀�4鍙蜂綅棰勬弧杞斤紝3鍙蜂綅寮�濮嬪線4鍙蜂綅鎼椂锛�
+        /// </summary>
+        public string zstatus { get; set; }
+
+    }
+
+    public class AutoLineMacQueueBak
+    {
+        public string zbguid { get; set; }
+
+        /// <summary>
+        /// 200锛氭垚鍔燂紱999锛氬け璐�
+        /// </summary>
+        public string zstatus { get; set; }
+
+        public string zerrmsg { get; set; }
+
+        /// <summary>
+        /// ztype涓�2瑙g粦鏃讹紝瑙g粦鎴愬姛浼氳繑鍥炲伐鍗曞彿锛屽悗缁璦oi浣滀笟鏃讹紝闇�甯︿笂宸ュ崟鍙蜂笂鎶涚粰mes
+        /// </summary>
+        public string zwoid { get; set; }
+    }
+
+    public class AutoLineMacBarcodeQueue
+    {
+        /// <summary>
+        /// 鍞竴ID
+        /// </summary>
+        public string zbguid { get; set; } = Guid.NewGuid().ToString();
+
+        /// <summary>
+        /// 鏃堕棿鎴筹紝绮剧‘鍒拌�楃
+        /// </summary>
+        public string zdate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff");
+
+        public string zline { get; set; }
+        public string zbarcode { get; set; }
+
+        /// <summary>
+        /// OK/NG
+        /// </summary>
+        public string zresult { get; set; }
+
+        /// <summary>
+        /// 鏍囧噯鐨勭己闄蜂唬鐮�
+        /// </summary>
+        public string zreson { get; set; }
+
+        /// <summary>
+        /// 鏉$爜鍦ㄥ綋鍓峵ray涓殑搴忓彿
+        /// </summary>
+        public string zno { get; set; }
+
+        /// <summary>
+        /// 瑙g粦鏃讹紝mes鍥炰紶鐨勫伐鍗曞彿
+        /// </summary>
+        public string zwoid { get; set; }
+
+        /// <summary>
+        /// 榛樿锛歂;闆舵暟灏剧洏锛歒
+        /// </summary>
+        public string endtray { get; set; } = "N";
+    }
+
+    public class AutoLineMacBarcodeQueueBak
+    {
+        public string zbguid { get; set; }
+
+        /// <summary>
+        /// 200锛氭垚鍔燂紱999锛氬け璐�
+        /// </summary>
+        public string zstatus { get; set; }
+        public string zerrmsg { get; set; }
+
+        /// <summary>
+        /// tray鐩樻爣绛炬潯鐮�
+        /// </summary>
+        public string tary_label { get; set; }
+    }
+
+
+}
diff --git a/src/Bro.M141.Process/UI/UIPrinter.Designer.cs b/src/Bro.M141.Process/UI/UIPrinter.Designer.cs
index 65db655..65661b5 100644
--- a/src/Bro.M141.Process/UI/UIPrinter.Designer.cs
+++ b/src/Bro.M141.Process/UI/UIPrinter.Designer.cs
@@ -34,11 +34,21 @@
             label1 = new Label();
             button3 = new Button();
             textBox2 = new TextBox();
+            button5 = new Button();
+            richTextBox1 = new RichTextBox();
+            textBox3 = new TextBox();
+            textBox4 = new TextBox();
+            textBox5 = new TextBox();
+            textBox6 = new TextBox();
+            textBox7 = new TextBox();
+            label2 = new Label();
+            button6 = new Button();
+            label3 = new Label();
             SuspendLayout();
             // 
             // button2
             // 
-            button2.Location = new Point(154, 69);
+            button2.Location = new Point(154, 51);
             button2.Margin = new Padding(3, 2, 3, 2);
             button2.Name = "button2";
             button2.Size = new Size(93, 46);
@@ -49,7 +59,7 @@
             // 
             // button1
             // 
-            button1.Location = new Point(27, 69);
+            button1.Location = new Point(27, 51);
             button1.Margin = new Padding(3, 2, 3, 2);
             button1.Name = "button1";
             button1.Size = new Size(93, 46);
@@ -77,7 +87,7 @@
             // 
             // button3
             // 
-            button3.Location = new Point(27, 167);
+            button3.Location = new Point(27, 101);
             button3.Margin = new Padding(2);
             button3.Name = "button3";
             button3.Size = new Size(69, 33);
@@ -88,25 +98,123 @@
             // 
             // textBox2
             // 
-            textBox2.Location = new Point(27, 221);
+            textBox2.Location = new Point(27, 138);
             textBox2.Margin = new Padding(3, 2, 3, 2);
             textBox2.Name = "textBox2";
             textBox2.Size = new Size(269, 21);
             textBox2.TabIndex = 6;
             // 
+            // button5
+            // 
+            button5.Location = new Point(107, 439);
+            button5.Margin = new Padding(3, 2, 3, 2);
+            button5.Name = "button5";
+            button5.Size = new Size(93, 46);
+            button5.TabIndex = 8;
+            button5.Text = "鍙戠";
+            button5.UseVisualStyleBackColor = true;
+            button5.Click += button5_Click;
+            // 
+            // richTextBox1
+            // 
+            richTextBox1.Location = new Point(328, 26);
+            richTextBox1.Name = "richTextBox1";
+            richTextBox1.Size = new Size(270, 509);
+            richTextBox1.TabIndex = 9;
+            richTextBox1.Text = "";
+            // 
+            // textBox3
+            // 
+            textBox3.Location = new Point(82, 226);
+            textBox3.Margin = new Padding(3, 2, 3, 2);
+            textBox3.Name = "textBox3";
+            textBox3.Size = new Size(151, 21);
+            textBox3.TabIndex = 10;
+            // 
+            // textBox4
+            // 
+            textBox4.Location = new Point(82, 263);
+            textBox4.Margin = new Padding(3, 2, 3, 2);
+            textBox4.Name = "textBox4";
+            textBox4.Size = new Size(151, 21);
+            textBox4.TabIndex = 11;
+            // 
+            // textBox5
+            // 
+            textBox5.Location = new Point(82, 298);
+            textBox5.Margin = new Padding(3, 2, 3, 2);
+            textBox5.Name = "textBox5";
+            textBox5.Size = new Size(151, 21);
+            textBox5.TabIndex = 12;
+            // 
+            // textBox6
+            // 
+            textBox6.Location = new Point(82, 336);
+            textBox6.Margin = new Padding(3, 2, 3, 2);
+            textBox6.Name = "textBox6";
+            textBox6.Size = new Size(151, 21);
+            textBox6.TabIndex = 13;
+            // 
+            // textBox7
+            // 
+            textBox7.Location = new Point(82, 379);
+            textBox7.Margin = new Padding(3, 2, 3, 2);
+            textBox7.Name = "textBox7";
+            textBox7.Size = new Size(151, 21);
+            textBox7.TabIndex = 14;
+            // 
+            // label2
+            // 
+            label2.AutoSize = true;
+            label2.Location = new Point(96, 415);
+            label2.Name = "label2";
+            label2.Size = new Size(174, 13);
+            label2.TabIndex = 15;
+            label2.Text = "ztype, zlsn, zlpn, zstatus, zversion";
+            // 
+            // button6
+            // 
+            button6.Location = new Point(107, 489);
+            button6.Margin = new Padding(3, 2, 3, 2);
+            button6.Name = "button6";
+            button6.Size = new Size(93, 46);
+            button6.TabIndex = 16;
+            button6.Text = "鍙戠墿鏂�";
+            button6.UseVisualStyleBackColor = true;
+            button6.Click += button6_Click;
+            // 
+            // label3
+            // 
+            label3.AutoSize = true;
+            label3.Location = new Point(96, 537);
+            label3.Name = "label3";
+            label3.Size = new Size(139, 13);
+            label3.TabIndex = 17;
+            label3.Text = "sn,result,zword,zno,entray";
+            // 
             // UIPrinter
             // 
             AutoScaleDimensions = new SizeF(6F, 13F);
             AutoScaleMode = AutoScaleMode.Font;
+            Controls.Add(label3);
+            Controls.Add(button6);
+            Controls.Add(label2);
+            Controls.Add(textBox7);
+            Controls.Add(textBox6);
+            Controls.Add(textBox5);
+            Controls.Add(textBox4);
+            Controls.Add(textBox3);
+            Controls.Add(richTextBox1);
+            Controls.Add(button5);
             Controls.Add(textBox2);
             Controls.Add(button3);
             Controls.Add(label1);
             Controls.Add(textBox1);
             Controls.Add(button1);
             Controls.Add(button2);
-            Margin = new Padding(2, 2, 2, 2);
+            Margin = new Padding(2);
             Name = "UIPrinter";
-            Size = new Size(305, 277);
+            Size = new Size(669, 576);
             ResumeLayout(false);
             PerformLayout();
         }
@@ -119,5 +227,15 @@
         private Label label1;
         private Button button3;
         private TextBox textBox2;
+        private Button button5;
+        private RichTextBox richTextBox1;
+        private TextBox textBox3;
+        private TextBox textBox4;
+        private TextBox textBox5;
+        private TextBox textBox6;
+        private TextBox textBox7;
+        private Label label2;
+        private Button button6;
+        private Label label3;
     }
 }
diff --git a/src/Bro.M141.Process/UI/UIPrinter.cs b/src/Bro.M141.Process/UI/UIPrinter.cs
index 949bd0d..48040be 100644
--- a/src/Bro.M141.Process/UI/UIPrinter.cs
+++ b/src/Bro.M141.Process/UI/UIPrinter.cs
@@ -1,6 +1,7 @@
 锘�
 using Bro.Common.Helper;
 using Bro.Common.Interface;
+using Bro.M135.Common;
 using Bro.UI.Model.Winform;
 using Sunny.UI;
 using System;
@@ -644,5 +645,43 @@
             //鍙湁鍦ㄦ墦鍗版満寮傚父鏃跺啀娆′笅鍙戞墦鍗颁换鍔″悗锛屾墠鑳借幏鍙栧埌鎵撳嵃鏈虹姸鎬併�傝繖鏄洜涓烘墦鍗版満椹卞姩绋嬪簭閫氬父鍙湪澶勭悊鎵撳嵃璇锋眰鏃舵洿鏂板叾鐘舵�佷俊鎭�傚鏋滄墦鍗版満娌℃湁鎺ユ敹鍒版柊鐨勬墦鍗颁换鍔★紝鍙兘鏃犳硶绔嬪嵆鍙嶆槧鍑虹湡瀹炵姸鎬併��
             textBox2.Text = "taskNum:" + taskNum + ",statuscode:" + statuscode + ",status:" + status;
         }
+
+
+
+
+
+        int num = 0;
+        //鍙戦��
+        private void button5_Click(object sender, EventArgs e)
+        {
+            //mqtt.Send("2", "DS02217", Config141.basketcode, "1", (num++).ToString());
+            string Msg = Task.Run(() => Process141.mqtt.MESForBasketAsync(textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text)).Result;
+            if (Msg == null)
+            {
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ杩斿洖鏁版嵁涓� null");
+            }
+            else
+            {
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ杩斿洖鏁版嵁涓� {Msg}");
+            }
+        }
+
+        int pronum = 0;
+        private void button6_Click(object sender, EventArgs e)//sn,result,zword,zno,entray
+        {
+            string Msg = Task.Run(() => Process141.mqtt.MESForProduceAsync(new ProductModel() { SN = textBox3.Text, Result = textBox4.Text }, textBox5.Text, Convert.ToInt32(textBox6.Text), textBox7.Text)).Result;
+            if (Msg == null)
+            {
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 鐗╂枡 杩斿洖鏁版嵁涓� null");
+            }
+            else
+            {
+                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 鐗╂枡 杩斿洖鏁版嵁涓� {Msg}");
+            }
+        }
+
+      
+
+
     }
 }
diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs
index 9b8a134..5769978 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;
@@ -7,6 +8,7 @@
 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;
@@ -195,15 +197,71 @@
                 }
                 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++;
+
+                        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
+                            {
+                                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;
@@ -424,5 +482,234 @@
         }
 
 
+
+
+        [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 (Msg != null)
+                {
+                    try
+                    {
+                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
+                        if (obj?.zstatus == "200")
+                        {
+                            ConfigAOI1.mesnum1++;
+                            Plc1.WriteSingleAddress(1590, 1, out _);
+                        }
+                        else
+                        {
+                            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 (Msg != null)
+                {
+
+                    try
+                    {
+                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
+                        if (obj?.zstatus == "200")
+                        {
+                            ConfigAOI1.mesnum1++;
+                            Plc1.WriteSingleAddress(1590, 1, out _);
+                        }
+                        else
+                        {
+                            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
+                        {
+                            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++;
+                        }
+                        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
+                        {
+                            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