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/M141Process.cs |  174 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 160 insertions(+), 14 deletions(-)

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;
 

--
Gitblit v1.8.0