From 6caff8e3b06535a9652a791454135cf0e6ac110e Mon Sep 17 00:00:00 2001
From: kingno <30263@KINGNO>
Date: 星期一, 23 六月 2025 09:59:46 +0800
Subject: [PATCH] 新增篮具码,界面

---
 src/Bro.M141.Process/M141Process.cs |  100 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 67 insertions(+), 33 deletions(-)

diff --git a/src/Bro.M141.Process/M141Process.cs b/src/Bro.M141.Process/M141Process.cs
index 2fad3d8..3302e67 100644
--- a/src/Bro.M141.Process/M141Process.cs
+++ b/src/Bro.M141.Process/M141Process.cs
@@ -17,6 +17,7 @@
 using ScottPlot.Drawing.Colormaps;
 using Sunny.UI;
 using Sunny.UI.Win32;
+using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Drawing.Imaging;
@@ -38,31 +39,34 @@
 
         public M141Process(string productCode) : base(productCode) { }
         #endregion
+
         TaskFactory _taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);
+
         public event Action<string, P_PRODUCT_DETAIL, string> OnSinglePostionDetectResultUpdate;
+
         protected M141Config M141Config => Config as M141Config;
 
         public static object _productListLock = new object();
         public List<ProductModel> ProductList = new List<ProductModel>();
         MachineLearningBase ML = null;
-        TcpListenerWrap TcpListener = null;
         Spec _errorSpec = null;
 
-        TcpListenerWrap _realTimeServer = null;
+        //volatile int _productIndex = 0;
 
-        volatile int _productIndex = 0;
+        public M141Process_Mysql mysqlhelper = new M141Process_Mysql();
 
-        int _backgroundImageWidth = 2448;
+        public event Action RerefreshBasketcodeUI;
 
-        M141Process_Mysql mysqlhelper = new M141Process_Mysql();
-
+        public void RerefreshBasketcode()
+        {
+            RerefreshBasketcodeUI?.Invoke();
+        }
 
 
 
         public override void InitialProcessMethods()
         {
             base.InitialProcessMethods();
-
 
             if (ThHeartPlc == null)
             {
@@ -91,7 +95,6 @@
         public Thread ThHeartPlc;
 
 
-
         public override void Open()
         {
             base.Open();
@@ -117,7 +120,7 @@
             _positionSpecHeads.Clear();
 
             mysqlhelper.IniDBIP(M141Config.IPforall);
-
+            RerefreshBasketcode();
         }
 
 
@@ -128,9 +131,13 @@
 
         }
 
+
         public void Heartplc()
         {
             Thread.Sleep(1000);
+
+            //Open();
+
             string _statisticFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Statistic.json");
             if (File.Exists(_statisticFilePath))
             {
@@ -421,8 +428,6 @@
         Dictionary<string, List<string>> _positionSpecHeads = new Dictionary<string, List<string>>();
 
 
-
-
         volatile int uploadId = 0;
 
 
@@ -500,33 +505,58 @@
                         throw new Exception($"浜у搧{string.Join(",", pidList)}妫�娴媨measureBind.GetDisplayText()}鏈兘鑾峰彇鍥剧墖瀵硅薄");
                     }
 
+                    RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedMonitorId, resultList);
+                    RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedCombineMethodId, resultList);
+
                     //妫�娴嬮『搴� ML->鑷畾涔夋娴�
                     if (!string.IsNullOrWhiteSpace(measureBind.DetectionId))
                     {
                         string detectionName = (ML.InitialConfig as MLInitialConfigBase).DetectionConfigs.FirstOrDefault(u => u.Id == measureBind.DetectionId)?.Name;
 
 
-                        //List<string> pidList2 = new List<string>();//pidList.Select(u => u.Split('_')[u.Split('_').Length - 1]).ToList();
-                        //Dictionary<string, string> dicpid = new Dictionary<string, string>();
 
-                        //for (int i = 0; i < pidList.Count; i++)
-                        //{
-                        //    var tem = pidList[i].Split('_')[pidList[i].Split('_').Length - 1];
-                        //    pidList2.Add(tem);
-                        //    dicpid[tem] = pidList[i];
-                        //}
+                        List<DetectResult> detectResults = ML?.RunMLDetectionSync(imgSet, pidList, measureBind.DetectionId, false, null, null, "", products[0].ImagePaths);
 
 
-                        List<DetectResult> detectResults = ML?.RunMLDetectionSync(imgSet, pidList, measureBind.DetectionId);
+
+                        if (measureBind.WorkPosition == "P1" && M141Config.StationCode == "S5" && detectResults.GetDefectDescList().Count == 0)
+                        {
+                            var defecttem = detectResults.SelectMany(u => u.NetResults.SelectMany(m => m.DetectDetails)).Where(u => u.NetName == M141Config.defectname).ToList();
+                            List<Netdefectdetail> Netdefectdetails = mysqlhelper.GetNetdefectdetails(products[0].SEQUENCE);
+
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN} 杩涘叆S3S5妫�娴� S3鏁版嵁{Netdefectdetails.Count}  S5鏁版嵁{defecttem.Count}");
+
+                            int num = 0;
+                            foreach (var item1 in defecttem)
+                            {
+                                double x1 = item1.Rect.Point_LU.X + item1.Rect.Width / 2.0;
+                                double y1 = item1.Rect.Point_LU.Y + item1.Rect.Height / 2.0;
+                                num++;
+                                //HOperatorSet.AffineTransPoint2d(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
+                                //HOperatorSet.ProjectiveTransPixel(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
+
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}鍘熷潗鏍噞num}   {x1},{y1}");
+                                HOperatorSet.ProjectiveTransPixel(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}鏂板潗鏍噞num}   {qx},{qy}");
+
+
+                                Netdefectdetail temc = new Netdefectdetail()
+                                {
+                                    centerX = qx,
+                                    centerY = qy,
+                                    name = M141Config.defectname,
+                                };
+                                if (Netdefectdetails.Any(u => u == temc))
+                                {
+                                    item1.IsAbandoned = false;
+                                    item1.FinalResult = ResultState.NG;
+                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{products[0].PID}_{products[0].SEQUENCE}宸ヤ綅{measureBind.WorkPosition}   S3S5缁勫悎妫�娴嬫鍑虹己闄�:{item1.NetName}");
+                                    break;
+                                }
+                            }
+                        }
+
                         List<DetectResult> ngResults = new List<DetectResult>();
-
-
-                        //for (int i = 0; i < detectResults.Count; i++)
-                        //{
-                        //    detectResults[i].PID = dicpid[detectResults[i].PID];
-                        //}
-
-
                         detectResults.GroupBy(u => u.PID).ToList().ForEach(u =>
                         {
                             if (u.ToList().Count > 0 && u.ToList().Any(m => m.ResultState != EnumHelper.ResultState.OK))
@@ -544,8 +574,7 @@
                         detectResults.AddRange(ngResults);
                         resultList.AddRange(detectResults);
                     }
-                    RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedMonitorId, resultList);
-                    RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedCombineMethodId, resultList);
+
                 }
                 catch (Exception ex)
                 {
@@ -768,7 +797,7 @@
                         {
                             products.ForEach(p =>
                             {
-                                var pResults = resultList.Where(u => u.PID == p.PID).ToList();
+                                var pResults = resultList.ToList();
                                 p.AddNewDetectResults(M141Config.StationCode, measureBind.WorkPosition, pResults);
                                 LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{p.PID}_{p.SEQUENCE}娣诲姞宸ヤ綅{measureBind.WorkPosition}妫�娴嬬粨鏋滐紝鏁伴噺{pResults.Count}");
                             });
@@ -998,6 +1027,7 @@
                     {
                         p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE, out string sntem);
                         p.SN = sntem;
+                        p.PID = $"{sntem}_{i}";
                         if ("NoRead".Equals(p.BasketCode))
                         {
                             LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{p.PID}_{p.SEQUENCE}鑾峰彇妗嗗叿鐮佸け璐� 璧嬪�糔oread");
@@ -1032,8 +1062,9 @@
 
                     //鍒濆鍖栦骇鍝佺殑妫�娴嬫鏁�
                     var checkIndexList = M141Config.MeasureBindCollection.Where(u => u.WorkPosition == b.WorkPosition && u.ProductIndices.Contains(i)).Select(u => u.CheckIndex).OrderBy(u => u).ToList();
-                    p.InitialPositionCheckList(b.WorkPosition, checkIndexList);
+                    p.InitialPositionCheckList(b.WorkPosition, checkIndexList, M141Config.StationCode);
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{p.PID}_{p.SEQUENCE}宸叉竻鐞唟b.WorkPosition}妫�娴嬫暟鎹�傚綋鍓嶅凡瀹屾垚宸ヤ綅{string.Join(",", p.Details.Select(u => u.PositionName))}");
+
                 });
 
                 //鍒濆鍖栧伐浣嶇殑妫�娴嬫鏁�
@@ -1132,7 +1163,7 @@
                         if (positionSet.IsLastPosition)
                         {
                             UpdateProductResultAsync(p);
-                            mysqlhelper.NewForAll(p, M141Config.StationCode);
+                            mysqlhelper.NewForAll(p, M141Config.StationCode, M141Config.defectname);
                             if (M141Config.IsfinDevice)
                             {
                                 SummaryAllprodata(p);
@@ -1197,6 +1228,8 @@
                     newp.BasketCode = p.BasketCode;
                     newp.Result = p.Result;
                     newp.SN = p.SN;
+
+                    Thread.Sleep(500);
                     var plist = mysqlhelper.GetProductList(p.SEQUENCE);
 
 
@@ -1207,6 +1240,7 @@
                             newp.Details.AddRange(item.Details);
                         }
                     }
+                    //LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"AllDeviceProductRecord浠庢暟鎹簱鑾峰彇鍒版暟鎹畕p.SEQUENCE} plist鏁伴噺{plist.Count} Details鏁伴噺{newp.Details.Count}");
 
                     //newp.Details.AddRange(p.Details);
 

--
Gitblit v1.8.0