From eda17eddf88e6108cadbf8dcef5c2195c1a7b708 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期三, 01 四月 2026 10:55:05 +0800
Subject: [PATCH] 提交VS生成临时文件

---
 LB_VisionProcesses/Processes/BarcodeReaderProcess.cs |  149 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 149 insertions(+), 0 deletions(-)

diff --git a/LB_VisionProcesses/Processes/BarcodeReaderProcess.cs b/LB_VisionProcesses/Processes/BarcodeReaderProcess.cs
new file mode 100644
index 0000000..62cc669
--- /dev/null
+++ b/LB_VisionProcesses/Processes/BarcodeReaderProcess.cs
@@ -0,0 +1,149 @@
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using LB_VisionProcesses.BarcodeReaders;
+
+namespace LB_VisionProcesses.Processes
+{
+    public class BarcodeReaderProcess : IProcess
+    {
+        /// <summary>
+        /// 璇荤爜鍣ㄥ疄渚嬮泦鍚� (鐢变富绋嬪簭绠$悊骞朵紶鍏�)
+        /// </summary>
+        [JsonIgnore]
+        public ConcurrentDictionary<string, BarcodeReaderBase> dicBarcodeReaders { get; set; }
+
+        /// <summary>
+        /// 褰撳墠鍏宠仈鐨勮鐮佸櫒
+        /// </summary>
+        [JsonIgnore]
+        public BarcodeReaderBase Reader { get; set; }
+
+        public BarcodeReaderProcess()
+        {
+            strProcessName = "璇荤爜宸ュ叿";
+            strProcessClass = "LB_VisionProcesses.Processes.BarcodeReaderProcess";
+
+            Params.Inputs.Add("璁惧鍝佺墝", "Huayray");
+            Params.Inputs.Add("璁惧SN", "");
+            Params.Inputs.Add("瑙﹀彂妯″紡", "杞Е鍙�"); 
+            Params.Inputs.Add("瓒呮椂鏃堕棿", 2000);
+            
+            Params.Outputs.Add("鏉$爜缁撴灉", "");
+            Params.Outputs.Add("鐮佹暟閲�", 0);
+        }
+
+        public override void InitRunParams()
+        {
+            Result = true;
+            Msg = "鍑嗗杩愯";
+            bCompleted = false;
+        }
+
+        public override bool Run()
+        {
+            DateTime StartTime = DateTime.Now;
+            try
+            {
+                InitRunParams();
+
+                string sn = Params.Inputs["璁惧SN"]?.ToString();
+                if (string.IsNullOrEmpty(sn))
+                {
+                    Msg = "璁惧SN鏈厤缃�";
+                    Result = false;
+                    return false;
+                }
+
+                // 浠庡叏灞�鍙橀噺鎴栦紶鍏ュ瓧鍏歌幏鍙�
+                if (dicBarcodeReaders == null)
+                {
+                    // 灏濊瘯浠庡叏灞� dicGlobalVars 鑾峰彇 (鍋囪涓荤▼搴忓凡鏀惧叆)
+                    if (dicGlobalVars.ContainsKey("dicBarcodeReaders"))
+                    {
+                        dicBarcodeReaders = dicGlobalVars["dicBarcodeReaders"] as ConcurrentDictionary<string, BarcodeReaderBase>;
+                    }
+                }
+
+                if (dicBarcodeReaders != null && dicBarcodeReaders.ContainsKey(sn))
+                {
+                    Reader = dicBarcodeReaders[sn];
+                }
+
+                if (Reader == null)
+                {
+                    Msg = $"璇荤爜鍣╗{sn}]鏈垵濮嬪寲";
+                    Result = false;
+                    return false;
+                }
+
+                string triggerMode = Params.Inputs["瑙﹀彂妯″紡"]?.ToString();
+                if (triggerMode == "杞Е鍙�")
+                {
+                    bool success = Reader.SoftTrigger();
+                    Msg = success ? "瑙﹀彂鎴愬姛" : "瑙﹀彂澶辫触";
+                    Result = success;
+                }
+            }
+            catch (Exception ex)
+            {
+                Msg = "杩愯寮傚父: " + ex.Message;
+                Result = false;
+            }
+            finally
+            {
+                RunTime = (DateTime.Now - StartTime).TotalMilliseconds;
+                bCompleted = true;
+            }
+            return Result;
+        }
+
+        public override bool Load(string fullPath)
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(fullPath) || !File.Exists(fullPath)) return false;
+                string json = File.ReadAllText(fullPath, Encoding.UTF8);
+                Params = JsonConvert.DeserializeObject<ProcessParams>(json);
+                Params?.FixDeserializedData();
+                return true;
+            }
+            catch { return false; }
+        }
+
+        public override bool Save(string filePath)
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(filePath)) return false;
+                if (!Directory.Exists(filePath)) Directory.CreateDirectory(filePath);
+                string fullPath = Path.Combine(filePath, strProcessName + ".json");
+                string json = JsonConvert.SerializeObject(Params, Formatting.Indented);
+                File.WriteAllText(fullPath, json, Encoding.UTF8);
+                return true;
+            }
+            catch { return false; }
+        }
+
+        public override object Clone()
+        {
+            try
+            {
+                var obj = (BarcodeReaderProcess)MemberwiseClone();
+                string json = JsonConvert.SerializeObject(this.Params);
+                obj.Params = JsonConvert.DeserializeObject<ProcessParams>(json);
+                return obj;
+            }
+            catch { return (BarcodeReaderProcess)MemberwiseClone(); }
+        }
+
+        public override void Dispose() { }
+    }
+}

--
Gitblit v1.9.3