From ebcc1d53f14112363bbf539bcaf0202aadcdc9d7 Mon Sep 17 00:00:00 2001
From: C3032 <1057644574@qq.com>
Date: 星期一, 13 四月 2026 12:58:58 +0800
Subject: [PATCH] 2D取图计数功能完成

---
 LB_SmartVision/ProcessRun/ProcessContext.cs |   80 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/LB_SmartVision/ProcessRun/ProcessContext.cs b/LB_SmartVision/ProcessRun/ProcessContext.cs
index e46967c..c680c4f 100644
--- a/LB_SmartVision/ProcessRun/ProcessContext.cs
+++ b/LB_SmartVision/ProcessRun/ProcessContext.cs
@@ -6,6 +6,7 @@
 using LB_VisionProcesses.Alogrithms;
 using LB_VisionProcesses.Cameras;
 using LB_VisionProcesses.Communicators;
+using LB_VisionProcesses.Processes;
 using LB_VisionProcesses.Processes.ScriptTool;
 using OpenCvSharp;
 using System.Collections.Concurrent;
@@ -585,7 +586,86 @@
         [Node("Halcon2D鍥惧儚婊ゆ尝", "Halcon2D宸ュ叿", "Basic", "Halcon2D鍥惧儚婊ゆ尝")]
         public void Halcon2D鍥惧儚婊ゆ尝(FlowNode node) { RunNodeAsync(node); }
 
+        [Node("杞儙璁℃暟", "鎺у埗", "Logic", "杞儙璁℃暟鑺傜偣")]
+        public void 杞儙璁℃暟(FlowNode node)
+        {
+            string ProcessName = node.Text;
+            try
+            {
+                if (dicContext.TryGetValue(ProcessName, out IProcess obj)
+                    && obj is TyreCounterProcess counter)
+                {
+                    UpdateInputs(counter);
 
+                    if (node.Break)
+                    {
+                        node.BranchIndex = "0";
+                        node.Result = true;
+                        counter.Result = true;
+                        counter.Msg = "杞儙璁℃暟鑺傜偣宸茶烦杩�";
+                        return;
+                    }
+
+                    // 浠庡墠缃妭鐐硅幏鍙栨娴嬬粨鏋滐紙閫氳繃杈撳叆鏄犲皠锛�
+                    bool imageResult = GetPreviousResult(node);
+
+                    // 璁剧疆杈撳叆缁撴灉
+                    counter.InputImage = imageResult;
+
+                    // 杩愯杞儙璁℃暟
+                    if (!counter.Run())
+                    {
+                        node.Result = false;
+                        Result &= false;
+                        Msg += $"[{ProcessName}]{counter.Msg}";
+                    }
+                    else
+                    {
+                        node.Result = true;
+
+                        // 濡傛灉瀹屾垚涓�涓疆鑳庯紝杈撳嚭瀹屾垚淇″彿
+                        if (counter.IsTyreComplete)
+                        {
+                            Msg += $"[{ProcessName}]瀹屾垚杞儙 #{counter.CurrentTyreID - 1}锛岀粨鏋�: {(counter.TyreResult ? "OK" : "NG")}";
+                        }
+                    }
+                }
+                else
+                {
+                    node.Result = false;
+                    Result &= false;
+                    Msg += $"[{ProcessName}]鏈壘鍒拌疆鑳庤鏁板伐鍏峰疄渚�";
+                }
+            }
+            catch (Exception ex)
+            {
+                node.Result = false;
+                Result &= false;
+                Msg += $"[{ProcessName}]杩愯鍙戠敓鎰忓,{ex.Message}";
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍓嶇疆鑺傜偣鐨勬娴嬬粨鏋�
+        /// </summary>
+        private bool GetPreviousResult(FlowNode node)
+        {
+            try
+            {
+                // 鏌ユ壘鍓嶇疆鑺傜偣
+                var prevNode = dicContext.Values
+                    .OfType<IProcess>()
+                    .FirstOrDefault(p => p.Result == true || p.Result == false);
+
+                if (prevNode != null)
+                {
+                    return prevNode.Result;
+                }
+            }
+            catch { }
+
+            return true; // 榛樿杩斿洖OK
+        }
 
         #endregion
 

--
Gitblit v1.9.3