From 6a4463810e276b62356d77c88509fa6fa7af65cf Mon Sep 17 00:00:00 2001
From: kingno <30263@KINGNO>
Date: 星期三, 23 七月 2025 15:46:33 +0800
Subject: [PATCH] mes数据逻辑上传完善,缺陷代码完善,添加S4工位的S2结果上传Plc的通信日志mes优化

---
 src/Bro.M141.Process/MyMQTT.cs                 |   80 ++++++++
 src/Bro.M141.Process/UI/UIPrinter.resx         |    4 
 global.json                                    |    5 
 src/Bro.M141.Process/UI/UIPrinter.cs           |    2 
 src/Bro.M141_AOI1.Process/AOI1Process.cs       |    4 
 M135.sln                                       |    4 
 src/Bro.M141.Process/M141Process_Mysql.cs      |   21 -
 src/Bro.M135.DBManager/Models/P_PRODUCT.cs     |    2 
 src/Bro.M141.Process/Bro.M141.Process.csproj   |    3 
 src/Bro.M141.Process/M141Process.cs            |  174 +++++++++++++++++-
 src/Bro.M141.Process/M141Process_ImageCheck.cs |  199 +++++++++++----------
 src/Bro.M141.Process/UI/UIPrinter.Designer.cs  |   25 ++
 12 files changed, 374 insertions(+), 149 deletions(-)

diff --git a/M135.sln b/M135.sln
index 4b7ccb2..e629d15 100644
--- a/M135.sln
+++ b/M135.sln
@@ -12,9 +12,9 @@
 		.editorconfig = .editorconfig
 	EndProjectSection
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bro.M141_AOI1.Process", "src\Bro.M141_AOI1.Process\Bro.M141_AOI1.Process.csproj", "{E51B5103-B3A2-43CD-BA2F-3126F56625DE}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bro.M141_AOI1.Process", "src\Bro.M141_AOI1.Process\Bro.M141_AOI1.Process.csproj", "{E51B5103-B3A2-43CD-BA2F-3126F56625DE}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bro.M135.DBManager", "src\Bro.M135.DBManager\Bro.M135.DBManager.csproj", "{80FDC1C6-604D-462D-97E3-AF56D65F7B1C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bro.M135.DBManager", "src\Bro.M135.DBManager\Bro.M135.DBManager.csproj", "{80FDC1C6-604D-462D-97E3-AF56D65F7B1C}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/global.json b/global.json
new file mode 100644
index 0000000..5280724
--- /dev/null
+++ b/global.json
@@ -0,0 +1,5 @@
+{
+  "sdk": {
+    "version": "6.0.136"
+  }
+}
\ No newline at end of file
diff --git a/src/Bro.M135.DBManager/Models/P_PRODUCT.cs b/src/Bro.M135.DBManager/Models/P_PRODUCT.cs
index 659c26e..d9736a3 100644
--- a/src/Bro.M135.DBManager/Models/P_PRODUCT.cs
+++ b/src/Bro.M135.DBManager/Models/P_PRODUCT.cs
@@ -14,6 +14,8 @@
 
         public string BasketCode { get; set; } = "NOREAD";
 
+        public string Zword { get; set; } = "NOREAD";
+
         public string Result { get; set; } = "";
 
         [NotMapped]
diff --git a/src/Bro.M141.Process/Bro.M141.Process.csproj b/src/Bro.M141.Process/Bro.M141.Process.csproj
index 17b8e84..b92ffe5 100644
--- a/src/Bro.M141.Process/Bro.M141.Process.csproj
+++ b/src/Bro.M141.Process/Bro.M141.Process.csproj
@@ -163,9 +163,6 @@
 		<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/M141Process.cs b/src/Bro.M141.Process/M141Process.cs
index 21f4dc8..7d7fa09 100644
--- a/src/Bro.M141.Process/M141Process.cs
+++ b/src/Bro.M141.Process/M141Process.cs
@@ -98,9 +98,6 @@
 
 
 
-
-
-
         public override void Open()
         {
             base.Open();
@@ -1064,10 +1061,12 @@
                     if (M141Config.Isreadbasketcode)
                     {
                         p.BasketCode = M141Config.basketcode;
+                        p.Zword = M141Config.zwoid;
                     }
                     else
                     {
-                        p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE, out string sntem);
+                        p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE, out string sntem, out string zword);
+                        p.Zword = zword;
                         p.SN = sntem;
                         p.PID = $"{sntem}_{i}";
                         if ("NoRead".Equals(p.BasketCode))
@@ -1231,17 +1230,7 @@
                             }
                         }
                     });
-                    //ReplyPlcData(positionSet, plcresult);
-                    if (positionSet.IsLastPosition)
-                    {
-                        if (_ct != null)
-                        {
-                            UpdateCT(null, (float)((DateTime.Now - _ct.Value).TotalSeconds));
-                        }
-                        _ct = DateTime.Now;
-                    }
 
-                    //ReplyPlcData(positionName, config.TriggerValue);
 
                     cameraIds.ForEach(c =>
                     {
@@ -1252,6 +1241,162 @@
                             LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鐩告満{camera.Name}娓呯悊缂撳瓨");
                         }
                     });
+
+                    //ReplyPlcData(positionSet, plcresult);
+                    if (positionSet.IsLastPosition)
+                    {
+                        if (_ct != null)
+                        {
+                            UpdateCT(null, (float)((DateTime.Now - _ct.Value).TotalSeconds));
+                        }
+                        _ct = DateTime.Now;
+
+                        if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
+                        {
+                            if (M141Config.numpro >= 50)
+                            {
+                                M141Config.numpro = 0;
+                            }
+
+                            if (pList[0].Result == "OK")
+                            {
+                                M141Config.numpro++;
+                            }
+
+                            //mqtt.demes(productList[0], M141Config.zwoid);
+                            string Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(pList[0], M141Config.mesnum2.ToString(),M141Config.numpro)).Result;
+                            M141Config.mesnum2++;
+                            if (Msgreceice == null)
+                            {
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull");
+                            }
+                            else
+                            {
+                                try
+                                {
+                                    var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
+
+                                    if (obj.zstatus == "200")
+                                    {
+                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES鎴愬姛  {Msgreceice}");
+                                    }
+                                    else
+                                    {
+                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES澶辫触  {Msgreceice}");
+                                    }
+                                }
+                                catch
+                                {
+                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES寮傚父  {Msgreceice}");
+                                }
+                            }
+
+
+
+                            int numplca = Convert.ToInt32(pList[0].SEQUENCE.Split('_')[0]);
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"plc缁欏嚭鐨勪骇鍝佸簭鍙蜂负{numplca}");
+
+                            lock (plcnumlock)//1-29999   
+                            {
+
+                                if (PlcNumForAll == -1)
+                                {
+                                    PlcNumForAll = numplca;
+                                }
+
+                                int differ = numplca - PlcNumForAll;
+
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"涓や釜浜у搧涓棿鐨勫樊鍊糳iffer涓簕differ}");
+
+                                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.Zword = plist[0].Zword;
+                                            newp.Result = "NG";
+                                            newp.SN = plist[0].SN;
+                                            var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                                            M141Config.mesnum2++;
+                                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鍓嶇珯NG鎺掓枡浜у搧{newp.PID}鏁版嵁涓婁紶,缁撴灉涓簕newp.Result}");
+
+                                        }
+                                        catch
+                                        {
+
+                                        }
+                                    }
+                                }
+                                else if (differ == -29998 && differ == 1 && differ == 0)
+                                {
+                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鐢熶骇杩囩▼涓湭澶卞幓浜у搧");
+                                }
+                                else if ( differ<0 && differ>-29998)
+                                {
+                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PlcNumForAll涓簕PlcNumForAll}锛宯umplca涓簕numplca}");
+                                    //浜у搧浠庢柊璁℃暟鏃�
+                                    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.Zword = plist[0].Zword;
+                                            newp.BasketCode = plist[0].BasketCode;
+                                            newp.Result = "NG";
+                                            newp.SN = plist[0].SN;
+                                            var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                                            M141Config.mesnum2++;
+                                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PlcNumForAll锛屽墠绔橬G鎺掓枡涓攑lc瑙﹀彂娓呴浂浜у搧{newp.PID}鏁版嵁涓婁紶,缁撴灉涓簕newp.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.Zword = plist[0].Zword;
+                                            newp.Result = "NG";
+                                            newp.SN = plist[0].SN;
+                                            var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                                            M141Config.mesnum2++;
+                                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"numplca锛屽墠绔橬G鎺掓枡涓攑lc瑙﹀彂娓呴浂浜у搧{newp.PID}鏁版嵁涓婁紶,缁撴灉涓簕newp.Result}");
+                                        }
+                                        catch
+                                        {
+
+                                        }
+                                    }
+                                }
+
+
+
+                                PlcNumForAll = numplca;
+                            }
+
+                        }
+
+                    }
+
+                    //ReplyPlcData(positionName, config.TriggerValue);
+
+                   
 
                     return pList;
 
@@ -1287,6 +1432,7 @@
                     newp.SEQUENCE = p.SEQUENCE;
                     newp.PID = p.PID;
                     newp.BasketCode = p.BasketCode;
+                    newp.Zword = p.Zword;
                     newp.Result = p.Result;
                     newp.SN = p.SN;
 
diff --git a/src/Bro.M141.Process/M141Process_ImageCheck.cs b/src/Bro.M141.Process/M141Process_ImageCheck.cs
index 6eb5b46..91dc61d 100644
--- a/src/Bro.M141.Process/M141Process_ImageCheck.cs
+++ b/src/Bro.M141.Process/M141Process_ImageCheck.cs
@@ -494,6 +494,9 @@
             {
                 ////mysqlhelper.GetS2Result(productList[0].SEQUENCE);
                 Plc1.WriteSingleAddress(1526, mysqlhelper.GetS2Result(productList[0].SEQUENCE) ? 1 : 2, out _);
+
+                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{string.Join(",", productList.Select(u => u.PID))}妫�娴嬪弽棣坽mysqlhelper.GetS2Result(productList[0].SEQUENCE)}");
+
             }
             else
             {
@@ -502,122 +505,122 @@
 
             Plc1.WriteSingleAddress(1516, 1, out _);
 
-            if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
-            {
-                if (M141Config.numpro >= 50)
-                {
-                    M141Config.numpro = 0;
-                }
+            //if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
+            //{
+            //    if (M141Config.numpro >= 50)
+            //    {
+            //        M141Config.numpro = 0;
+            //    }
 
-                if (productList[0].Result == "OK")
-                {
-                    M141Config.numpro++;
-                }
+            //    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);
+            //    //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}");
-                    }
-                }
+            //            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;
+            //    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
-                            {
+            //                }
+            //                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;
+            //                }
+            //            }
+            //        }
+            //        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
-                            {
+            //                }
+            //                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;
+            //            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
-                            {
+            //                }
+            //                catch
+            //                {
 
-                            }
-                        }
+            //                }
+            //            }
 
 
-                    }
-                    PlcNumForAll = numplca;
-                }
+            //        }
+            //        PlcNumForAll = numplca;
+            //    }
 
-            }
+            //}
 
             return msg;
         }
diff --git a/src/Bro.M141.Process/M141Process_Mysql.cs b/src/Bro.M141.Process/M141Process_Mysql.cs
index bb67d25..ae1408c 100644
--- a/src/Bro.M141.Process/M141Process_Mysql.cs
+++ b/src/Bro.M141.Process/M141Process_Mysql.cs
@@ -23,10 +23,8 @@
 {
     public class M141Process_Mysql
     {
-
         string connStrAll = "server=localhost;port=3306;user id=root;password=123456;database=BroDB;charset=utf8";
         string connStrLocal = "server=localhost;port=3306;user id=root;password=123456;database=BroDB;charset=utf8";
-
 
         #region 鍩虹鎿嶄綔
         public void IniDBIP(string IP)
@@ -107,7 +105,6 @@
         }
 
         #endregion
-
 
 
         public void NewProduct(ProductModel pro)
@@ -290,7 +287,7 @@
                             Operatoremysql(str2, connStrAll);
                         }
 
-                        string mysqlstr = $"insert into forall (basketcode,device,plcnum,sn,data,time) values('{pro.BasketCode}','{devicestr}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')";
+                        string mysqlstr = $"insert into forall (basketcode,zword,device,plcnum,sn,data,time) values('{pro.BasketCode}','{pro.Zword}','{devicestr}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')";
 
                         if (Operatoremysql(mysqlstr, connStrAll))
                         {
@@ -334,7 +331,6 @@
             return null;
         }
 
-
         public List<Netdefectdetail> GetNetdefectdetails(string plcnum)
         {
             try
@@ -373,8 +369,8 @@
                 {
                     ProductModel p = null;
                     p = JsonConvert.DeserializeObject<ProductModel>(str, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
-                   
-                    return p.Result=="OK";
+
+                    return p.Result == "OK";
                 }
             }
             catch (Exception e)
@@ -384,13 +380,13 @@
             return false;
         }
 
-
-        public string Getbasketcode(string plcnum, out string sn)
+        public string Getbasketcode(string plcnum, out string sn, out string zword)
         {
             sn = "Noread";
+            zword = "Noread";
             try
             {
-                string mysqlstr = $"select basketcode,sn from forall where plcnum='{plcnum}' && device='S2' order by id desc limit 1";
+                string mysqlstr = $"select basketcode,sn,zword from forall where plcnum='{plcnum}' && device='S2' order by id desc limit 1";
                 var dt = selectdt(mysqlstr, connStrAll);
                 if (dt == null || dt.Rows.Count == 0)
                 {
@@ -399,6 +395,7 @@
                 else
                 {
                     sn = dt.Rows[0][1].ToString();
+                    zword = dt.Rows[0][2].ToString();
                     return dt.Rows[0][0].ToString();
                 }
             }
@@ -408,7 +405,6 @@
             }
             return "NoRead";
         }
-
 
         public List<ProductModel> GetProductList(string plcnum)
         {
@@ -442,8 +438,6 @@
             return null;
         }
 
-
-
         public DataTable getBasketCode()
         {
             try
@@ -468,7 +462,6 @@
 
 
         }
-
 
         public void NewBasketcode(string code)
         {
diff --git a/src/Bro.M141.Process/MyMQTT.cs b/src/Bro.M141.Process/MyMQTT.cs
index 78ce1c3..209162d 100644
--- a/src/Bro.M141.Process/MyMQTT.cs
+++ b/src/Bro.M141.Process/MyMQTT.cs
@@ -15,6 +15,7 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using ZXing;
 
 namespace Bro.M141.Process
 {
@@ -133,7 +134,7 @@
             }
         }
 
-        public async Task<string> MESForBasketAsync(string ztype, string zlsn, string zlpn, string zstatus, string zversion, int timeoutMs = 3000)
+        public async Task<string> MESForBasketAsync(string ztype, string zlsn, string zlpn, string zstatus, string zversion, int timeoutMs = 30000)
         {
             var guid = Guid.NewGuid().ToString();
             var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -167,11 +168,60 @@
             }
         }
 
-        public async Task<string> MESForProduceAsync(ProductModel pro, string zwoid, int znonum, string endtray = "N", string line = "NQ216", int timeoutMs = 3000)
+        public async Task<string> MESForProduceAsync(ProductModel pro, string zversion, 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;
+
+            string zresult = "OK";
+            if (string.IsNullOrWhiteSpace(pro.Result))
+            {
+                zresult = "NG";
+            }
+            else if (!"OK".Equals(pro.Result))
+            {
+                zresult = "NG";
+            }
+            //string zr;
+            //switch (pro.Result)
+            //{
+            //    case "ok":
+            //        zr = "";
+            //        break;
+            //    case "寮傝壊":
+            //        zr = "SZ2001";
+            //        break;
+            //    case "纾ㄥ嵃":
+            //        zr = "SZ2012";
+            //        break;
+            //    case "鍘嬩激":
+            //        zr = "SZ2014";
+            //        break;
+            //    case "鍙樺舰":
+            //        zr = "SZ2014";
+            //        break;
+            //    case "鍒掍激":
+            //        zr = "SZ2021";
+            //        break;
+            //    default:
+            //        zr = "S31006";
+            //        break;
+            //}
+
+            var DefectCodeMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+            {
+                ["ok"] = "",
+                ["寮傝壊"] = "SZ2001",
+                ["纾ㄥ嵃"] = "SZ2012",
+                ["鍘嬩激"] = "SZ2014",
+                ["鍙樺舰"] = "SZ2014",
+                ["鍒掍激"] = "SZ2021"
+            };
+            const string DefaultErrorCode = "S31006";
+           
+            string zr = DefectCodeMap.TryGetValue(pro.Result, out var code) ? code : DefaultErrorCode;
+
 
 
             var msgObj = new AutoLineMacBarcodeQueue
@@ -180,16 +230,21 @@
                 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",
+                zresult = zresult,
+                zreson = zr,
+                //zreson = pro.Result == "OK" ? "" : "SZ2014",
+                //
+
+                //
                 zno = znonum.ToString(),
-                zwoid = zwoid,
-                endtray = endtray
+                zwoid = pro.Zword,
+                endtray = endtray,
+                zversion = zversion
             };
 
             var message = JsonConvert.SerializeObject(msgObj);
             var body = Encoding.UTF8.GetBytes(message);
-            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ鍙戦�佷骇鍝亄pro.PID} 鏁版嵁2锛歿message}");
+            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ鍙戦�佷骇鍝亄pro.PID} 鏁版嵁2锛歿message},缂洪櫡浠g爜涓簕zr}");
             _sendChannel.BasicPublish("", "auto_line_mac_barcode_queue", null, body);
 
             var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
@@ -600,6 +655,17 @@
         /// 榛樿锛歂;闆舵暟灏剧洏锛歒
         /// </summary>
         public string endtray { get; set; } = "N";
+              /// <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; }
     }
 
     public class AutoLineMacBarcodeQueueBak
diff --git a/src/Bro.M141.Process/UI/UIPrinter.Designer.cs b/src/Bro.M141.Process/UI/UIPrinter.Designer.cs
index 65661b5..1366f7b 100644
--- a/src/Bro.M141.Process/UI/UIPrinter.Designer.cs
+++ b/src/Bro.M141.Process/UI/UIPrinter.Designer.cs
@@ -44,6 +44,7 @@
             label2 = new Label();
             button6 = new Button();
             label3 = new Label();
+            textBox8 = new TextBox();
             SuspendLayout();
             // 
             // button2
@@ -125,7 +126,7 @@
             // 
             // textBox3
             // 
-            textBox3.Location = new Point(82, 226);
+            textBox3.Location = new Point(82, 195);
             textBox3.Margin = new Padding(3, 2, 3, 2);
             textBox3.Name = "textBox3";
             textBox3.Size = new Size(151, 21);
@@ -133,7 +134,7 @@
             // 
             // textBox4
             // 
-            textBox4.Location = new Point(82, 263);
+            textBox4.Location = new Point(82, 231);
             textBox4.Margin = new Padding(3, 2, 3, 2);
             textBox4.Name = "textBox4";
             textBox4.Size = new Size(151, 21);
@@ -141,7 +142,7 @@
             // 
             // textBox5
             // 
-            textBox5.Location = new Point(82, 298);
+            textBox5.Location = new Point(82, 267);
             textBox5.Margin = new Padding(3, 2, 3, 2);
             textBox5.Name = "textBox5";
             textBox5.Size = new Size(151, 21);
@@ -149,7 +150,7 @@
             // 
             // textBox6
             // 
-            textBox6.Location = new Point(82, 336);
+            textBox6.Location = new Point(82, 303);
             textBox6.Margin = new Padding(3, 2, 3, 2);
             textBox6.Name = "textBox6";
             textBox6.Size = new Size(151, 21);
@@ -157,7 +158,7 @@
             // 
             // textBox7
             // 
-            textBox7.Location = new Point(82, 379);
+            textBox7.Location = new Point(82, 339);
             textBox7.Margin = new Padding(3, 2, 3, 2);
             textBox7.Name = "textBox7";
             textBox7.Size = new Size(151, 21);
@@ -188,14 +189,23 @@
             label3.AutoSize = true;
             label3.Location = new Point(96, 537);
             label3.Name = "label3";
-            label3.Size = new Size(139, 13);
+            label3.Size = new Size(191, 13);
             label3.TabIndex = 17;
-            label3.Text = "sn,result,zword,zno,entray";
+            label3.Text = "sn,result,zword,zno,entray锛寊version";
+            // 
+            // textBox8
+            // 
+            textBox8.Location = new Point(82, 375);
+            textBox8.Margin = new Padding(3, 2, 3, 2);
+            textBox8.Name = "textBox8";
+            textBox8.Size = new Size(151, 21);
+            textBox8.TabIndex = 18;
             // 
             // UIPrinter
             // 
             AutoScaleDimensions = new SizeF(6F, 13F);
             AutoScaleMode = AutoScaleMode.Font;
+            Controls.Add(textBox8);
             Controls.Add(label3);
             Controls.Add(button6);
             Controls.Add(label2);
@@ -237,5 +247,6 @@
         private Label label2;
         private Button button6;
         private Label label3;
+        private TextBox textBox8;
     }
 }
diff --git a/src/Bro.M141.Process/UI/UIPrinter.cs b/src/Bro.M141.Process/UI/UIPrinter.cs
index 48040be..d668f90 100644
--- a/src/Bro.M141.Process/UI/UIPrinter.cs
+++ b/src/Bro.M141.Process/UI/UIPrinter.cs
@@ -669,7 +669,7 @@
         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;
+            string Msg = Task.Run(() => Process141.mqtt.MESForProduceAsync(new ProductModel() { SN = textBox3.Text, Result = textBox4.Text ,Zword= textBox5.Text,}, textBox8.Text, Convert.ToInt32(textBox6.Text), textBox7.Text)).Result;
             if (Msg == null)
             {
                 CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 鐗╂枡 杩斿洖鏁版嵁涓� null");
diff --git a/src/Bro.M141.Process/UI/UIPrinter.resx b/src/Bro.M141.Process/UI/UIPrinter.resx
index 8b2ff64..af32865 100644
--- a/src/Bro.M141.Process/UI/UIPrinter.resx
+++ b/src/Bro.M141.Process/UI/UIPrinter.resx
@@ -1,7 +1,7 @@
 锘�<?xml version="1.0" encoding="utf-8"?>
 <root>
   <!--
-    Microsoft ResX Schema
+    Microsoft ResX Schema 
 
     Version 2.0
 
@@ -48,7 +48,7 @@
     value   : The object must be serialized with
             : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
             : and then encoded with base64 encoding.
-
+    
     mimetype: application/x-microsoft.net.object.soap.base64
     value   : The object must be serialized with
             : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs
index 5769978..5e34210 100644
--- a/src/Bro.M141_AOI1.Process/AOI1Process.cs
+++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -484,6 +484,9 @@
 
 
 
+
+
+
         [ProcessMethod("", "MESup1", "MES涓婁紶杩涙枡鍙g┖绡�", InvokeType.TestInvoke)]
         public ResponseMessage MESup1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
         {
@@ -532,7 +535,6 @@
 
             return msg;
         }
-
 
 
         [ProcessMethod("", "MESup2", "MES涓婁紶杩涙枡鍙f弧杞�", InvokeType.TestInvoke)]

--
Gitblit v1.8.0