From b4a7ed3e39a05bcd26d8308ff568206637cefc9e Mon Sep 17 00:00:00 2001
From: kingno <30263@KINGNO>
Date: 星期三, 27 八月 2025 16:50:32 +0800
Subject: [PATCH] 完整版封装码打印

---
 src/Bro.M141.Process/M141Process_ImageCheck.cs |  150 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 138 insertions(+), 12 deletions(-)

diff --git a/src/Bro.M141.Process/M141Process_ImageCheck.cs b/src/Bro.M141.Process/M141Process_ImageCheck.cs
index dfcf451..46108d4 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;
@@ -35,7 +36,7 @@
         ManualResetEvent set2 = new ManualResetEvent(false);
 
 
-        public event Action<string> StartPrinter;
+     
 
         [ProcessMethod("ImageCheck", "ImageCheckOperation", "閫氱敤鍥剧墖妫�娴嬫搷浣�", InvokeType.TestInvoke)]
         public ResponseMessage ImageCheckOperation(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -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;
@@ -488,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
             {
@@ -496,9 +505,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 +680,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);
 
@@ -585,8 +713,8 @@
             ResponseMessage msg = new ResponseMessage();
 
             Plc2 = invokeDevice as PLCBase;
-            string message = "";
-            StartPrinter.Invoke(message);
+            string message = "nothing";
+            StartPrint(message);
             return msg;
         }
 
@@ -739,17 +867,20 @@
 
 
 
-        private void UpdateProductResultAsync(ProductModel p)
+        private void UpdateProductResultAsync(ProductModel p, string name)
         {
             UpdateProductResult(p, out bool isOK);
 
             _taskFactory.StartNew(() =>
             {
                 _csvHead = p.GetCSVHead(ref _specHeadList, ref _positionList);
-                CSVRecordAsync($"ProductRecord_{DateTime.Now.ToString("yyyyMMdd")}.csv", p.GetCSVData(_specHeadList, _positionList), _csvHead);
+                //CSVRecordAsync($"ProductRecord_{DateTime.Now.ToString("yyyyMMdd")}.csv", p.GetCSVData(_specHeadList, _positionList), _csvHead);
+                CSVRecordAsync(name, p.GetCSVData(_specHeadList, _positionList), _csvHead);
                 //_manager_P_Product.UpdateProductResult(p.ID, p.PID, p.SN, p.Result);
             });
 
+            //杩炵画NG鏁版嵁璁板綍
+            CheckContinuousNGAlarmAsync(p);
         }
 
 
@@ -857,10 +988,5 @@
 
             public object data { get; set; }
         }
-
-
-
-
-
     }
 }

--
Gitblit v1.8.0