From 57e86e9be5d5fa6f854761ca915a64ee67869724 Mon Sep 17 00:00:00 2001
From: quanzhou <quan.zhou@broconcentric.com>
Date: 星期一, 19 一月 2026 13:15:07 +0800
Subject: [PATCH] S5上传产品信息上传mes添加逻辑判断是否最后一片产品获取tray盘码

---
 src/Bro.M141_AOI1.Process/AOI1Process.cs |  149 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 101 insertions(+), 48 deletions(-)

diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs
index 7b7e435..d56ccac 100644
--- a/src/Bro.M141_AOI1.Process/AOI1Process.cs
+++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -329,10 +329,10 @@
                         {
                             try
                             {
-                                var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(zwordstr);
-                                ConfigAOI1.zwoid = obj.zwoid;
+                                var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(zwordstr);                 
                                 if (!string.IsNullOrEmpty(obj.zwoid) && obj.zstatus == "200")
                                 {
+                                    ConfigAOI1.zwoid = obj.zwoid;
                                     Plc1.WriteSingleAddress(1524, 1, out _);
                                     Plc1.WriteSingleAddress(1514, 1, out _);
                                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid鑾峰彇鎴愬姛 {obj.zstatus} {obj.zwoid} ");
@@ -747,8 +747,8 @@
         {
             ResponseMessage msg = new ResponseMessage();
 
-            var plcnum11 = Plc3.Read(1542, 1, out _);
-            var plcnum12 = Plc3.Read(1544, 1, out _);
+            var plcnum11 = Plc1.Read(1542, 1, out _);
+            var plcnum12 = Plc1.Read(1544, 1, out _);
 
             LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PLC淇℃伅璁板綍淇濆瓨瑙﹀彂 鑾峰彇PLC搴忓彿{plcnum11[0]}鍜寋plcnum12[0]}");
 
@@ -784,7 +784,7 @@
                     else
                     {
                         LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pro.PID}鏁版嵁涓婁紶MES澶辫触  {tems}");
-                        result = "obj.zerrmsg";
+                        result = string.Empty;
                         if (obj.zerrmsg.Contains("閲嶅鏁版嵁"))
                         {
                             return true;
@@ -877,6 +877,11 @@
            
         }
 
+        /// <summary>
+        /// 浜у搧闆剁洏涓婁紶鍚姩鏍囪瘑
+        /// </summary>
+        private bool isStartclear =false;
+
         [ProcessMethod("", "MEStogetcode", "MES涓婁紶鏁存壒鏁版嵁骞惰幏鍙栨潯鐮�", InvokeType.TestInvoke)]
         public ResponseMessage MEStogetcode(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
         {
@@ -894,14 +899,8 @@
 
             LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅涓婁紶mes瑙﹀彂锛岃幏鍙朠LC搴忓彿{plcnum[0]}鍜寋plcnum1[0]}");
 
-            string saveTary_ID=string.Empty;
-
-            if (!Issuccess && !Issuccess1)
-            {
-                Plc3.WriteSingleAddress(2120, 2, out _);
-                return msg;
-            }
-                      
+            string saveTary_ID= string.Empty;
+  
             LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅涓婁紶MES瑙﹀彂锛屼骇鍝佷俊鎭暟閲忎负锛歿M141Config.Productioncode.Count}");
 
             if (M141Config.Productioncode.Count == 50)
@@ -917,7 +916,26 @@
                     newp.Result = "OK";
                     newp.SN = M141Config.Productioncode[0].SN;
                     string tary_ID = string.Empty;
-                    bool isok = UptoMES(newp, "N", out tary_ID);
+                    bool isok = true;
+                    if (M141Config.Productioncode.Count==1)
+                    {
+                        if (isStartclear)
+                        {
+                           
+                            isok = UptoMES(newp, "Y", out tary_ID);
+                            isStartclear = false;
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩闆剁洏灏炬暟涓婁紶");
+                        }
+                        else
+                        {
+                            isok = UptoMES(newp, "N", out tary_ID);
+                        }
+                    }
+                    else
+                    {
+                        isok = UptoMES(newp, "N", out tary_ID);
+                    }
+                       
                     if (!isok)
                     {
                         Plc3.WriteSingleAddress(2120, 2, out _);
@@ -925,13 +943,22 @@
                     }
                     if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                     {
-                        saveTary_ID = tary_ID;
-                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");                      
-                        M141Config.MES_codes.Add(new MES_code
+                        if (M141Config.Productioncode.Count == 1)
                         {
-                            Printers_code = tary_ID
-                        });
-                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鏉$爜锛歿tary_ID}宸茶Е鍙慡6鎵撳嵃骞朵笖淇濆瓨");
+                            saveTary_ID = tary_ID;
+                            StartPrint(tary_ID, "Honeywell PX240S (300 dpi)");
+                            M141Config.MES_codes.Add(new MES_code
+                            {
+                                Printers_code = tary_ID
+                            });
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鏉$爜锛歿tary_ID}宸茶Е鍙慡6鎵撳嵃骞朵笖淇濆瓨");
+                        }
+                        else
+                        {
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"鏉$爜锛歿tary_ID}涓嶆槸鍦ㄦ渶鍚庝竴浠朵骇鍝佽幏鍙�,鍚姩闆剁洏娓呴櫎澶嶄綅浜у搧涓婁紶鍔ㄤ綔");
+                            isStartclear = true;
+                        }
+                        
                     }                
                     M141Config.Productioncode.RemoveAt(0);
                 }
@@ -939,7 +966,7 @@
             }
             else if (M141Config.Productioncode.Count > 50)
             {
-                //涓�旀湁浜у搧琚彇璧�
+                //涓�旀湁浜у搧琚彇璧板鑷存潯鐮佸ぇ浜庡疄闄呮暟閲�
                 for (int i = 0; i < 50; i++)
                 {
                     ProductModel newp = new ProductModel();
@@ -951,7 +978,25 @@
                     newp.Result = "OK";
                     newp.SN = M141Config.Productioncode[count - 1].SN;
                     string tary_ID = string.Empty;
-                    bool isok = UptoMES(newp, "N", out tary_ID);
+                    bool isok = true;
+                    if (i==49)
+                    {
+                        if (isStartclear)
+                        {
+                            isok = UptoMES(newp, "Y", out tary_ID);
+                            isStartclear = false;
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩闆剁洏灏炬暟涓婁紶");
+                        }
+                        else
+                        {
+                            isok = UptoMES(newp, "N", out tary_ID);
+                        }
+                    }
+                    else
+                    {
+
+                        isok = UptoMES(newp, "N", out tary_ID);
+                    }                
                     if (!isok)
                     {
                         Plc3.WriteSingleAddress(2120, 2, out _);
@@ -960,13 +1005,22 @@
                     }
                     if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                     {
-                        saveTary_ID = tary_ID;
-                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
-                        M141Config.MES_codes.Add(new MES_code
+                        if (i == 49)
                         {
-                            Printers_code = tary_ID
-                        });
-                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鏉$爜锛歿tary_ID}宸茶Е鍙慡6鎵撳嵃骞朵笖淇濆瓨");
+                            saveTary_ID = tary_ID;
+                            StartPrint(tary_ID, "Honeywell PX240S (300 dpi)");
+                            M141Config.MES_codes.Add(new MES_code
+                            {
+                                Printers_code = tary_ID
+                            });
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鏉$爜锛歿tary_ID}宸茶Е鍙慡6鎵撳嵃骞朵笖淇濆瓨");
+                        }
+                        else
+                        {
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"鏉$爜锛歿tary_ID}涓嶆槸鍦ㄦ渶鍚庝竴浠朵骇鍝佽幏鍙�,鍚姩闆剁洏娓呴櫎澶嶄綅浜у搧涓婁紶鍔ㄤ綔");
+                            isStartclear = true;
+                        }
+                        
                     }
                     M141Config.Productioncode.RemoveAt(count - 1);
                 }
@@ -974,7 +1028,7 @@
             }
             else if (M141Config.Productioncode.Count > 0 && M141Config.Productioncode.Count < 50)
             {
-                //浜у搧缂哄皯闇�瑕侀澶栫殑鏉$爜琛ユ晳
+                //浜у搧缂哄皯闇�瑕佹竻闄ら浂鐩�
                 while (M141Config.Productioncode.Count > 0)
                 {
                     ProductModel newp = new ProductModel();
@@ -990,7 +1044,7 @@
                     if (M141Config.Productioncode.Count==1)
                     {
                         isok = UptoMES(newp, "Y", out tary_ID);
-                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}瑙﹀彂闆舵暟灏剧洏");
+                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩闆剁洏灏炬暟涓婁紶");
                     }
                     else
                     {
@@ -1003,13 +1057,21 @@
                     }
                     if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                     {
-                        saveTary_ID = tary_ID;
-                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
-                        M141Config.MES_codes.Add(new MES_code
+                        if (M141Config.Productioncode.Count == 1)
                         {
-                            Printers_code = tary_ID
-                        });
-                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鏉$爜锛歿tary_ID}宸茶Е鍙慡6鎵撳嵃骞朵笖淇濆瓨");
+                            saveTary_ID = tary_ID;
+                            StartPrint(tary_ID, "Honeywell PX240S (300 dpi)");
+                            M141Config.MES_codes.Add(new MES_code
+                            {
+                                Printers_code = tary_ID
+                            });
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鏉$爜锛歿tary_ID}宸茶Е鍙慡6鎵撳嵃骞朵笖淇濆瓨");
+                        }
+                        else
+                        {
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"鏉$爜锛歿tary_ID}涓嶆槸鍦ㄦ渶鍚庝竴浠朵骇鍝佽幏鍙�,鍚姩闆剁洏娓呴櫎澶嶄綅浜у搧涓婁紶鍔ㄤ綔");
+                            isStartclear = true;
+                        }
                     }
                     M141Config.Productioncode.RemoveAt(0);
                 }
@@ -1019,20 +1081,11 @@
             {
                 if (M141Config.Isprint && !string.IsNullOrEmpty(saveTary_ID))
                 {
-                    StartPrint(saveTary_ID, "Honeywell PX240S(300 dpi)");
+                    StartPrint(saveTary_ID, "Honeywell PX240S (300 dpi)");
                 }      
             }
-            if (Issuccess && Issuccess1)
-            {
-                Plc3.WriteSingleAddress(2120, 1, out _);
-                return msg;
-            }
-            else
-            {
-                Plc3.WriteSingleAddress(2120, 2, out _);
-                return msg;
-            }
-            
+               Plc3.WriteSingleAddress(2120, 1, out _);
+               return msg;       
         }
 
         [ProcessMethod("", "MESup1", "MES涓婁紶杩涙枡鍙g┖绡�", InvokeType.TestInvoke)]

--
Gitblit v1.8.0