From 0865af247a3f51c5e0b2ef148107ea7dd768d28b Mon Sep 17 00:00:00 2001
From: TD <Administrator@PC-20240810NGQJ>
Date: Thu, 27 Mar 2025 17:51:07 +0800
Subject: [PATCH] 111

---
 DH.Devices.Vision/SimboVisionDriver.cs |  4 +--
 DHSoftware/MainWindow.cs               | 39 +++++++++++-------------
 DHSoftware/productModel.cs             | 42 ++++++++++++++++++--------
 3 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/DH.Devices.Vision/SimboVisionDriver.cs b/DH.Devices.Vision/SimboVisionDriver.cs
index 7a99870..37efa21 100644
--- a/DH.Devices.Vision/SimboVisionDriver.cs
+++ b/DH.Devices.Vision/SimboVisionDriver.cs
@@ -140,8 +140,8 @@ namespace DH.Devices.Vision
                     //  LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} RunInference BEGIN");
                     mlWatch.Start();
                     //20230802改成多线程推理 RunInferenceFixed
-
-                    var result = mlSet.StationMLEngine.RunInference(req);
+                   // MLResult result = new MLResult();
+                   var result = mlSet.StationMLEngine.RunInference(req);
                     // var result = mlSet.StationMLEngine.RunInferenceFixed(req);
                     mlWatch.Stop();
                     // LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} RunInference END");
diff --git a/DHSoftware/MainWindow.cs b/DHSoftware/MainWindow.cs
index 088d776..fa2fc4d 100644
--- a/DHSoftware/MainWindow.cs
+++ b/DHSoftware/MainWindow.cs
@@ -689,11 +689,7 @@ namespace DHSoftware
 
             //   ProductBaseCount = _MGSCameraList.Count;
 
-            for (int i = 0; i < ProductBaseCount * ProductListMulti; i++)
-            {
-                ConcurrentDictionary<uint, ProductData> products = new ConcurrentDictionary<uint, ProductData>();
-                _productLists.Add(products);
-            }
+         
 
             //流程执行时PLC
             PLC.StartProcess();
@@ -706,7 +702,7 @@ namespace DHSoftware
 
         private uint PieceCount = 0;
         private List<ConcurrentDictionary<uint, ProductData>> _productLists = new List<ConcurrentDictionary<uint, ProductData>>();
-        private int ProductListMulti = 2;
+        private int ProductListMulti = 1;
         private int ProductBaseCount = 0;
 
         private int PieceNumberToIndex(uint pn)
@@ -798,8 +794,8 @@ namespace DHSoftware
                             }
                             else
                             {
-                                // Thread.Sleep(20);
-                                await Task.Delay(20);
+                                 Thread.Sleep(20);
+                                //await Task.Delay(20);
                             }
                             retryTimes--;
                         }
@@ -852,10 +848,7 @@ namespace DHSoftware
                             }));
                             //重新生成实例 销毁之前的实例
 
-                            using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
-                            {
-                                sw.WriteLine(productNumber + "提前推出" + camera.CameraName);
-                            }
+                          
                             //  LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.Name} 找到产品{productNumber},但是没有推理1");
 
                             return;
@@ -864,7 +857,8 @@ namespace DHSoftware
                         double totalTime = 0.0;
                         List<ResultState> resultStates = new List<ResultState>();
                         List<string>? detectionDict = _cameraRelatedDetectionDict[camera.CameraName];
-
+                        Stopwatch stopwatch = new Stopwatch();
+                        stopwatch.Start();
                         for (int i = 0; i < detectionDict.Count; i++)
                         {
                             string detectionId = detectionDict[i];
@@ -879,7 +873,8 @@ namespace DHSoftware
                                 product.ResultCollection.Add(temp1);
                             }
                         }
-
+                        stopwatch.Stop();
+                    
                         product.InferenceOne();
 
                         // LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理完成,产品{productNumber}");
@@ -907,14 +902,14 @@ namespace DHSoftware
                         product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
                             ? ResultState.B_NG
                             : ResultState.OK;
-                        if (product.ProductResult == ResultState.OK)
-                        {
-                            PLC.Blowing(productNumber, 1);
-                        }
-                        else
-                        {
-                            PLC.Blowing(productNumber, 2);
-                        }
+                        //if (product.ProductResult == ResultState.OK)
+                        //{
+                        //    PLC.Blowing(productNumber, 1);
+                        //}
+                        //else
+                        //{
+                        //    PLC.Blowing(productNumber, 2);
+                        //}
                         product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
                         product.ProductLabel = product.ProductResult.GetEnumDescription();
 
diff --git a/DHSoftware/productModel.cs b/DHSoftware/productModel.cs
index 2e910bb..9484d1a 100644
--- a/DHSoftware/productModel.cs
+++ b/DHSoftware/productModel.cs
@@ -73,32 +73,48 @@ namespace DHSoftware
         public ProductData( string batchNO, uint pieceNumber, int inferenceLeft = -1) : this(pieceNumber)
         {
             InferenceLeft = inferenceLeft;
-            _countdownEvent = new CountdownEvent(inferenceLeft);
+            //_countdownEvent = new CountdownEvent(inferenceLeft);
 
             BatchNO = batchNO;
           
         }
       
 
-        public void InferenceOne()
-        {
-            //lock (_inferenceLock)
-            //{
-            //    Interlocked.Decrement(ref InferenceLeft);
-            //}
+        //public void InferenceOne()
+        //{
+        //    //lock (_inferenceLock)
+        //    //{
+        //    //    Interlocked.Decrement(ref InferenceLeft);
+        //    //}
 
           
-            _countdownEvent.Signal();
+        //    _countdownEvent.Signal();
          
+        //}
+
+        //public bool InferenceFinished()
+        //{
+        //    //lock (_inferenceLock)
+        //    //{
+        //    //    return 0 == InferenceLeft;
+        //    //}
+        //    return _countdownEvent.CurrentCount == 0; // 判断计数器是否为 0
+        //}
+        public void InferenceOne()
+        {
+            lock (_inferenceLock)
+            {
+                Interlocked.Decrement(ref InferenceLeft);
+
+            }
         }
 
         public bool InferenceFinished()
         {
-            //lock (_inferenceLock)
-            //{
-            //    return 0 == InferenceLeft;
-            //}
-            return _countdownEvent.CurrentCount == 0; // 判断计数器是否为 0
+            lock (_inferenceLock)
+            {
+                return 0 == InferenceLeft;
+            }
         }