From 48f005ea04ee8ce6c9a044dd2fcb0febc7f74788 Mon Sep 17 00:00:00 2001
From: quanzhou <quan.zhou@broconcentric.com>
Date: 星期四, 25 十二月 2025 21:22:21 +0800
Subject: [PATCH] S5数据保存及数据上传逻辑添加日志,手动打印条码区分S6和S9

---
 src/Bro.M141_AOI1.Process/AOI1Process.cs |  308 +++++++++++++++++++++++++++++----------------------
 1 files changed, 174 insertions(+), 134 deletions(-)

diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs
index f4c2e15..7b7e435 100644
--- a/src/Bro.M141_AOI1.Process/AOI1Process.cs
+++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -615,131 +615,145 @@
             return msg;
         }
 
-        [ProcessMethod("", "MESupdata", "MES姝e父涓婁紶鍗曚釜OK浜у搧鑾峰彇鏉$爜", InvokeType.TestInvoke)]
-        public ResponseMessage MESupdata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+        ////[ProcessMethod("", "MESupdata", "MES姝e父涓婁紶鍗曚釜OK浜у搧鑾峰彇鏉$爜", InvokeType.TestInvoke)]
+        ////public ResponseMessage MESupdata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+        ////{
+        ////    ResponseMessage msg = new ResponseMessage();
+
+        ////    Plc3 = invokeDevice as PLCBase;
+        ////    //涓婁紶鍙嶉缁撴灉          
+        ////    bool Issuccess = false;
+        ////    bool Issuccess1 = false;
+
+        ////    string tary_label = string.Empty;
+
+        ////    string tary_label1 = string.Empty;
+
+        ////    var plcnum = Plc3.Read(2100, 1, out _);
+        ////    var plcnum1 = Plc3.Read(2102, 1, out _);
+        ////    if (plcnum[0] == 0)
+        ////    {
+        ////        Issuccess = true;
+        ////    }
+        ////    else
+        ////    {
+        ////        Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
+        ////        if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
+        ////        {
+        ////            StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
+        ////        }
+        ////    }
+        ////    if (plcnum1[0] == 0)
+        ////    {
+        ////        Issuccess1 = true;               
+        ////    }
+        ////    else
+        ////    {
+        ////        Issuccess1 = UpMES(plcnum1[0] + "_1", "N", out tary_label1);
+
+        ////        if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
+        ////        {
+        ////            StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
+        ////        }
+        ////    }                      
+        ////    if (Issuccess && Issuccess1)
+        ////    {
+        ////        Plc3.WriteSingleAddress(2120, 1, out _);
+        ////    }
+        ////    else
+        ////    {
+        ////        Plc3.WriteSingleAddress(2120, 2, out _);
+        ////    }
+        ////    return msg;
+        ////}
+
+        ////[ProcessMethod("", "MESupFinallydata", "MES涓婁紶鍗曚釜灏剧洏OK浜у搧鑾峰彇鏉$爜", InvokeType.TestInvoke)]
+        ////public ResponseMessage MESupFinallydata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
+        ////{
+        ////    ResponseMessage msg = new ResponseMessage();
+
+        ////    Plc3 = invokeDevice as PLCBase;
+        ////    //涓婁紶鍙嶉缁撴灉          
+        ////    bool Issuccess = false;
+        ////    bool Issuccess1 = false;
+
+        ////    string tary_label = string.Empty;
+
+        ////    string tary_label1 = string.Empty;
+
+        ////    var plcnum = Plc3.Read(2100, 1, out _);
+        ////    var plcnum1 = Plc3.Read(2102, 1, out _);
+        ////    if (plcnum[0] != 0|| plcnum1[0] != 0)
+        ////    {
+        ////        if (plcnum[0] == 0)
+        ////        {
+        ////            Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
+        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
+        ////            {
+        ////                StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
+        ////            }
+        ////        }
+        ////        else if(plcnum1[0] == 0)
+        ////        {
+        ////            Issuccess = UpMES(plcnum[0] + "_1", "Y", out tary_label);
+        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
+        ////            {
+        ////                StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
+        ////            }
+        ////        }
+        ////        else if (plcnum[0] != 0 && plcnum1[0] != 0)
+        ////        {
+        ////            Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);                   
+        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
+        ////            {
+        ////                StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
+        ////            }
+        ////            Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
+        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
+        ////            {
+        ////                StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
+        ////            }
+        ////        }
+        ////    }
+
+        ////    if (Issuccess && Issuccess1)
+        ////    {
+        ////        Plc3.WriteSingleAddress(2120, 1, out _);
+        ////    }
+        ////    else
+        ////    {
+        ////        Plc3.WriteSingleAddress(2120, 2, out _);
+        ////    }
+        ////    return msg;
+        ////}
+
+        //private bool UpMES(string PLCNum ,string endtray , out string result )
+        //{
+        //    var plist = mysqlhelper.GetProductList(PLCNum);
+        //    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 = "OK";
+        //    newp.SN = plist[0].SN;
+        //    bool isok = UptoMES(newp, endtray, out result);
+        //    return isok;
+
+        //}
+
+        [ProcessMethod("", "PLCreadTosave", "PLC鏁版嵁璇诲彇淇濆瓨", InvokeType.TestInvoke)]
+        public ResponseMessage PLCreadTosave(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
         {
             ResponseMessage msg = new ResponseMessage();
 
-            Plc3 = invokeDevice as PLCBase;
-            //涓婁紶鍙嶉缁撴灉          
-            bool Issuccess = false;
-            bool Issuccess1 = false;
+            var plcnum11 = Plc3.Read(1542, 1, out _);
+            var plcnum12 = Plc3.Read(1544, 1, out _);
 
-            string tary_label = string.Empty;
+            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PLC淇℃伅璁板綍淇濆瓨瑙﹀彂 鑾峰彇PLC搴忓彿{plcnum11[0]}鍜寋plcnum12[0]}");
 
-            string tary_label1 = string.Empty;
 
-            var plcnum = Plc3.Read(2100, 1, out _);
-            var plcnum1 = Plc3.Read(2102, 1, out _);
-            if (plcnum[0] == 0)
-            {
-                Issuccess = true;
-            }
-            else
-            {
-                Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
-                if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
-                {
-                    StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
-                }
-            }
-            if (plcnum1[0] == 0)
-            {
-                Issuccess1 = true;               
-            }
-            else
-            {
-                Issuccess1 = UpMES(plcnum1[0] + "_1", "N", out tary_label1);
-
-                if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
-                {
-                    StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
-                }
-            }                      
-            if (Issuccess && Issuccess1)
-            {
-                Plc3.WriteSingleAddress(2120, 1, out _);
-            }
-            else
-            {
-                Plc3.WriteSingleAddress(2120, 2, out _);
-            }
             return msg;
-        }
-
-        [ProcessMethod("", "MESupFinallydata", "MES涓婁紶鍗曚釜灏剧洏OK浜у搧鑾峰彇鏉$爜", InvokeType.TestInvoke)]
-        public ResponseMessage MESupFinallydata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
-        {
-            ResponseMessage msg = new ResponseMessage();
-
-            Plc3 = invokeDevice as PLCBase;
-            //涓婁紶鍙嶉缁撴灉          
-            bool Issuccess = false;
-            bool Issuccess1 = false;
-
-            string tary_label = string.Empty;
-
-            string tary_label1 = string.Empty;
-
-            var plcnum = Plc3.Read(2100, 1, out _);
-            var plcnum1 = Plc3.Read(2102, 1, out _);
-            if (plcnum[0] != 0|| plcnum1[0] != 0)
-            {
-                if (plcnum[0] == 0)
-                {
-                    Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
-                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
-                    {
-                        StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
-                    }
-                }
-                else if(plcnum1[0] == 0)
-                {
-                    Issuccess = UpMES(plcnum[0] + "_1", "Y", out tary_label);
-                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
-                    {
-                        StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
-                    }
-                }
-                else if (plcnum[0] != 0 && plcnum1[0] != 0)
-                {
-                    Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);                   
-                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
-                    {
-                        StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
-                    }
-                    Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
-                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
-                    {
-                        StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
-                    }
-                }
-            }
-           
-            if (Issuccess && Issuccess1)
-            {
-                Plc3.WriteSingleAddress(2120, 1, out _);
-            }
-            else
-            {
-                Plc3.WriteSingleAddress(2120, 2, out _);
-            }
-            return msg;
-        }
-
-        private bool UpMES(string PLCNum ,string endtray , out string result )
-        {
-            var plist = mysqlhelper.GetProductList(PLCNum);
-            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 = "OK";
-            newp.SN = plist[0].SN;
-            bool isok = UptoMES(newp, endtray, out result);
-            return isok;
-
         }
 
         private bool UptoMES( ProductModel pro, string endtray,  out string result)
@@ -784,7 +798,6 @@
                     result = string.Empty;
                     return false;
                 }
-
             }
         }
 
@@ -799,14 +812,17 @@
 
             bool Issuccess1 = false;
 
-            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅璁板綍淇濆瓨瑙﹀彂");
+            //LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅璁板綍淇濆瓨瑙﹀彂");
 
             var plcnum = Plc3.Read(2100, 1, out _);
+           
             Issuccess = GetProImformation(plcnum[0]);
 
             var plcnum1 = Plc3.Read(2102, 1, out _);
             Issuccess1 = GetProImformation(plcnum1[0]);
-            
+
+            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅璁板綍淇濆瓨瑙﹀彂 鑾峰彇PLC搴忓彿{plcnum[0]}鍜寋plcnum1[0]}");
+
             if (Issuccess && Issuccess1)
             {
                 Plc3.WriteSingleAddress(2120, 1, out _);
@@ -869,11 +885,16 @@
             bool Issuccess = false;
             bool Issuccess1 = false;
 
+           // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅涓婁紶mes瑙﹀彂");
             var plcnum = Plc3.Read(2100, 1, out _);
             Issuccess = GetProImformation(plcnum[0]);
 
             var plcnum1 = Plc3.Read(2102, 1, out _);
             Issuccess1 = GetProImformation(plcnum1[0]);
+
+            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅涓婁紶mes瑙﹀彂锛岃幏鍙朠LC搴忓彿{plcnum[0]}鍜寋plcnum1[0]}");
+
+            string saveTary_ID=string.Empty;
 
             if (!Issuccess && !Issuccess1)
             {
@@ -881,12 +902,12 @@
                 return msg;
             }
                       
-            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅涓婁紶MES瑙﹀彂");
+            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧淇℃伅涓婁紶MES瑙﹀彂锛屼骇鍝佷俊鎭暟閲忎负锛歿M141Config.Productioncode.Count}");
 
             if (M141Config.Productioncode.Count == 50)
-            {
+            {               
                 //浜у搧姝e父涓婁紶
-                while(M141Config.Productioncode.Count>0)
+                while (M141Config.Productioncode.Count>0)
                 {
                     ProductModel newp = new ProductModel();
                     newp.SEQUENCE = M141Config.Productioncode[0].SEQUENCE;
@@ -900,10 +921,12 @@
                     if (!isok)
                     {
                         Plc3.WriteSingleAddress(2120, 2, out _);
+                        return msg;
                     }
                     if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                     {
-                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
+                        saveTary_ID = tary_ID;
+                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");                      
                         M141Config.MES_codes.Add(new MES_code
                         {
                             Printers_code = tary_ID
@@ -912,6 +935,7 @@
                     }                
                     M141Config.Productioncode.RemoveAt(0);
                 }
+                M141Config.Productioncode.Clear();
             }
             else if (M141Config.Productioncode.Count > 50)
             {
@@ -919,20 +943,24 @@
                 for (int i = 0; i < 50; i++)
                 {
                     ProductModel newp = new ProductModel();
-                    newp.SEQUENCE = M141Config.Productioncode[-1].SEQUENCE;
-                    newp.PID = M141Config.Productioncode[-1].PID;
-                    newp.BasketCode = M141Config.Productioncode[-1].BasketCode;
-                    newp.Zword = M141Config.Productioncode[-1].Zword;
+                    int count = M141Config.Productioncode.Count;
+                    newp.SEQUENCE = M141Config.Productioncode[count - 1].SEQUENCE;
+                    newp.PID = M141Config.Productioncode[count - 1].PID;
+                    newp.BasketCode = M141Config.Productioncode[count - 1].BasketCode;
+                    newp.Zword = M141Config.Productioncode[count - 1].Zword;
                     newp.Result = "OK";
-                    newp.SN = M141Config.Productioncode[-1].SN;
+                    newp.SN = M141Config.Productioncode[count - 1].SN;
                     string tary_ID = string.Empty;
                     bool isok = UptoMES(newp, "N", out tary_ID);
                     if (!isok)
                     {
                         Plc3.WriteSingleAddress(2120, 2, out _);
+                        return msg;
+
                     }
                     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
                         {
@@ -940,11 +968,11 @@
                         });
                         LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鏉$爜锛歿tary_ID}宸茶Е鍙慡6鎵撳嵃骞朵笖淇濆瓨");
                     }
-                    M141Config.Productioncode.RemoveAt(-1);
+                    M141Config.Productioncode.RemoveAt(count - 1);
                 }
                 M141Config.Productioncode.Clear();
             }
-            else if (M141Config.Productioncode.Count < 50)
+            else if (M141Config.Productioncode.Count > 0 && M141Config.Productioncode.Count < 50)
             {
                 //浜у搧缂哄皯闇�瑕侀澶栫殑鏉$爜琛ユ晳
                 while (M141Config.Productioncode.Count > 0)
@@ -971,9 +999,11 @@
                     if (!isok)
                     {
                         Plc3.WriteSingleAddress(2120, 2, out _);
+                        return msg;
                     }
                     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
                         {
@@ -983,16 +1013,26 @@
                     }
                     M141Config.Productioncode.RemoveAt(0);
                 }
+                M141Config.Productioncode.Clear();
+            }
+            else if (M141Config.Productioncode.Count == 0)
+            {
+                if (M141Config.Isprint && !string.IsNullOrEmpty(saveTary_ID))
+                {
+                    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;
             }
-            return msg;
+            
         }
 
         [ProcessMethod("", "MESup1", "MES涓婁紶杩涙枡鍙g┖绡�", InvokeType.TestInvoke)]
@@ -1074,7 +1114,6 @@
 
             return msg;
         }
-
 
         [ProcessMethod("", "MESup2", "MES涓婁紶杩涙枡鍙f弧杞�", InvokeType.TestInvoke)]
         public ResponseMessage MESup2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -1330,5 +1369,6 @@
             }
             return msg;
         }
+
     }
 }

--
Gitblit v1.8.0