From 98c0775fe3b61a37d90dd5756287f385a311adf0 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期三, 15 四月 2026 20:09:49 +0800
Subject: [PATCH] 验证3D相机亮度图无法获取

---
 LB_SmartVision/VisionForm.cs | 1260 ++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 978 insertions(+), 282 deletions(-)

diff --git a/LB_SmartVision/VisionForm.cs b/LB_SmartVision/VisionForm.cs
index 77e0d8f..be74509 100644
--- a/LB_SmartVision/VisionForm.cs
+++ b/LB_SmartVision/VisionForm.cs
@@ -14,6 +14,7 @@
 using LB_SmartVision.ProcessRun;
 using LB_SmartVision.SQL;
 using LB_SmartVision.Tool;
+using LB_SmartVisionCameraDevice.PHM6000;
 using LB_SmartVisionCommon;
 using LB_SmartVisionLoginUI;
 using LB_VisionProcesses;
@@ -755,6 +756,15 @@
             LB_SmartVision.Tool.Tool.ReadStringConfig("User ID", out string User_ID);
             LB_SmartVision.Tool.Tool.ReadStringConfig("Password", out string Password);
             GlobalVar.strProductName = DateBaseName;
+            //鍔犺浇LB鐩告満鍙傛暟
+            if (LoadAllLBCameras(GlobalVar.allCamerasLBPath))
+            {
+                LogInfo("LB3D鐩告満閰嶇疆鏂囦欢鍔犺浇鎴愬姛锛�", LogInfoType.PASS);
+            }
+            else
+            {
+                LogInfo("LB3D鐩告満閰嶇疆鏂囦欢鍔犺浇澶辫触", LogInfoType.ERROR);
+            }
             //鍔犺浇閫氳
             foreach (BaseCommunicator com in GlobalVar.dicCommunicators.Values)
             {
@@ -1218,7 +1228,13 @@
                         camera.isGrabbing = false;
                     }
                 }
-
+                if (camera is LBCamera phmCamera)
+                {
+                    if (GlobalVar.allLBCameras.ContainsKey(camera.SN) && phmCamera._isConnected)
+                    {
+                        phmCamera.UpdateSensorConfig(GlobalVar.allLBCameras[camera.SN]);
+                    }
+                }
                 GlobalVar.dicCameras.TryAdd(CameraConnectionString.Key, camera);
             }
 
@@ -1557,6 +1573,47 @@
             catch { return false; }
         }
 
+        public bool LoadAllLBCameras(string allLBCamerasPath)
+        {
+            try
+            {
+                if (!File.Exists(allLBCamerasPath))
+                {
+                    Debug.WriteLine("鏂囦欢涓嶅瓨鍦ㄥ垱寤虹┖鏂囦欢");
+                    // 鑾峰彇涓嶅甫鏂囦欢鍚嶇殑鐩綍璺緞
+                    string directoryPath = Path.GetDirectoryName(allLBCamerasPath);
+                    SaveAllLBCameras();
+                    return true;
+                }
+                GlobalVar.allLBCameras = ConfigManager<ConcurrentDictionary<string, PHM6000SensorConfig>>.LoadConfig<ConcurrentDictionary<string, PHM6000SensorConfig>>(GlobalVar.allCamerasLBPath);
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
+
+        public bool SaveAllLBCameras()
+        {
+            try
+            {
+                if (GlobalVar.allLBCameras.Count >= 0)
+                {
+                    ConfigManager<ConcurrentDictionary<string, PHM6000SensorConfig>>.SaveConfig<ConcurrentDictionary<string, PHM6000SensorConfig>>(GlobalVar.allLBCameras, GlobalVar.allCamerasLBPath);
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
+
         public bool LoadAllProcess(string allProcessConnectionStringPath)
         {
             try
@@ -1888,6 +1945,8 @@
             }
 
         }
+        bool is3D = false;
+        bool is2D = false;
 
         private void TriggerRunMessageReceived(string name, string msg)
         {
@@ -1962,6 +2021,7 @@
                     }
             }
 
+
             var matchedItems = GlobalVar.dicProcessSetting
                 .Where(item =>
                 {
@@ -1977,6 +2037,23 @@
 
             if (matchedItems.Count <= 0)
             {
+                matchedItems = GlobalVar.dicProcessSetting
+                            .Where(item =>
+                            {
+                                var value = item.Value;
+                                var triggerComm = value["瑙﹀彂閫氳"];
+                                var triggerChar = value["瑙﹀彂瀛楃"];
+                                return triggerComm != null && !triggerComm.Equals("鏃�");
+                                //return triggerComm != null && triggerComm.Equals(name) &&
+                                //       (string.IsNullOrEmpty(triggerChar?.ToString()) ||
+                                //        msg.StartsWith(triggerChar.ToString()));
+                            })
+                            .ToList(); // 閬垮厤閲嶅瀛楀吀璁块棶鍜岃绠辨搷浣�
+            }
+
+
+            if (matchedItems.Count <= 0)
+            {
                 return;
             }
 
@@ -1988,294 +2065,888 @@
 
             GlobalVar.dicProcesses.Values.AsParallel().ForAll(v => v.bCompleted = false);
             LogInfo(string.Format($"妫�鏌ュ埌鍙瑙﹀彂鐨勬祦绋�,娓呯┖鎵�鏈夋祦绋嬭繍琛屽畬鎴愭爣璁颁綅!"), LogInfoType.INFO);
-            Task.Factory.StartNew(() =>
+
+            if (!is3D && name.Contains("L"))
             {
-                Parallel.ForEach(matchedItems, item =>
+                Task.Factory.StartNew(() =>
                 {
-                    string ProcessName = item.Value["娴佺▼鍚�"];
-                    LogInfo($"娴佺▼[{ProcessName}]寮�濮嬭繍琛�", LogInfoType.INFO);
-
-                    if (!GlobalVar.dicProcesses.ContainsKey(ProcessName))
+                    if (name.Contains("L"))
                     {
-                        LogInfo(string.Format("娴佺▼[{0}]涓嶅瓨鍦�,璇锋鏌ユ祦绋嬭缃�", ProcessName), LogInfoType.ERROR);
-                        return;
+                        is3D = true;
                     }
-
-                    ProcessRunBll RunBll = GlobalVar.dicProcesses[ProcessName];
-                    if (RunBll == null || RunBll.bRuning)
+                    Parallel.ForEach(matchedItems, item =>
                     {
-                        LogInfo(string.Format("娴佺▼[{0}]涓婃鏈繍琛屽畬鎴�,瑙﹀彂澶辫触", ProcessName)
-                            , LogInfoType.ERROR);
-                        return;
-                    }
+                        string ProcessName = item.Value["娴佺▼鍚�"];
+                        LogInfo($"娴佺▼[{ProcessName}]寮�濮嬭繍琛�", LogInfoType.INFO);
 
-                    try
-                    {
-                        bool result = false;
-                        string msg = string.Empty;
-                        int times = Convert.ToInt32(item.Value["閲嶆祴娆℃暟"].ToString());
-                        string ConnecResult = item.Value["鍏宠仈缁撴灉"];
-
-                        if (times < 0)
+                        if (!GlobalVar.dicProcesses.ContainsKey(ProcessName))
                         {
-                            result = RunBll.Run();
-                            msg = RunBll.Msg;
-
-                            if (!(string.IsNullOrEmpty(ConnecResult) || ConnecResult.Trim() == "鏈叧鑱�"))
-                            {
-                                if (!result)
-                                {
-                                    LogInfo(string.Format("娴佺▼[{0}]杩愯缁撴灉澶辫触,鍘熷洜鏄痆{1}]", ProcessName, msg), LogInfoType.NOSHOW);
-                                }
-                                RunBll.GetBooleanOutput(ConnecResult, out result);
-                                RunBll.Result = result;
-                            }
-
-                            if (!result)
-                            {
-                                LogInfo($"娴佺▼[{ProcessName}]琚己鍒惰繍琛屾垚鍔�", LogInfoType.WARN);
-                                RunBll.Result = true;
-                                result = true;
-                            }
+                            LogInfo(string.Format("娴佺▼[{0}]涓嶅瓨鍦�,璇锋鏌ユ祦绋嬭缃�", ProcessName), LogInfoType.ERROR);
+                            return;
                         }
-                        else
+
+                        ProcessRunBll RunBll = GlobalVar.dicProcesses[ProcessName];
+                        if (RunBll == null || RunBll.bRuning)
                         {
-                            while (times >= 0)
+                            LogInfo(string.Format("娴佺▼[{0}]涓婃鏈繍琛屽畬鎴�,瑙﹀彂澶辫触", ProcessName)
+                                , LogInfoType.ERROR);
+                            return;
+                        }
+
+                        try
+                        {
+                            bool result = false;
+                            string msg = string.Empty;
+                            int times = Convert.ToInt32(item.Value["閲嶆祴娆℃暟"].ToString());
+                            string ConnecResult = item.Value["鍏宠仈缁撴灉"];
+
+                            if (times < 0)
                             {
                                 result = RunBll.Run();
                                 msg = RunBll.Msg;
+
                                 if (!(string.IsNullOrEmpty(ConnecResult) || ConnecResult.Trim() == "鏈叧鑱�"))
                                 {
                                     if (!result)
                                     {
                                         LogInfo(string.Format("娴佺▼[{0}]杩愯缁撴灉澶辫触,鍘熷洜鏄痆{1}]", ProcessName, msg), LogInfoType.NOSHOW);
                                     }
-
                                     RunBll.GetBooleanOutput(ConnecResult, out result);
                                     RunBll.Result = result;
                                 }
 
-                                if (result)
+                                if (!result)
                                 {
-                                    break;
+                                    LogInfo($"娴佺▼[{ProcessName}]琚己鍒惰繍琛屾垚鍔�", LogInfoType.WARN);
+                                    RunBll.Result = true;
+                                    result = true;
                                 }
-                                else if (!result && times > 0)
-                                {
-                                    LogInfo(string.Format("娴佺▼[{0}]杩愯澶辫触閲嶆柊娴嬭瘯,鍓╀綑娆℃暟[{1}]", ProcessName, times), LogInfoType.WARN);
-                                }
-
-                                times--;
-                            }
-                        }
-
-                        string ConnectProcess = item.Value["鍏宠仈娴佺▼"];
-                        if (!(ConnectProcess == null || string.IsNullOrEmpty(ConnectProcess) || ConnectProcess.Trim() == ""))
-                        {
-                            //鐢ㄩ�楀彿鎴栬�呭垎鍙峰幓闂撮殧鍏宠仈娴佺▼
-                            string[] arrConnectProcess;
-                            if (ConnectProcess.Split(';').Length >= ConnectProcess.Split(',').Length)
-                            {
-                                arrConnectProcess = ConnectProcess.Split(';');
                             }
                             else
                             {
-                                arrConnectProcess = ConnectProcess.Split(',');
-                            }
-
-                            foreach (string strConnectProcess in arrConnectProcess)
-                            {
-                                if (GlobalVar.dicProcesses.ContainsKey(strConnectProcess))
+                                while (times >= 0)
                                 {
-                                    ProcessRunBll ConnectRunBll = GlobalVar.dicProcesses[strConnectProcess];
-
-                                    int waitTime = 10;
-                                    DateTime startTime = DateTime.Now;
-                                    while ((DateTime.Now - startTime).TotalSeconds < waitTime
-                                    && (ConnectRunBll.bRuning || !ConnectRunBll.bCompleted))
+                                    result = RunBll.Run();
+                                    msg = RunBll.Msg;
+                                    if (!(string.IsNullOrEmpty(ConnecResult) || ConnecResult.Trim() == "鏈叧鑱�"))
                                     {
-                                        LogInfo(string.Format("鍏宠仈娴佺▼[{0}]鏈繍琛屽畬鎴�,鍓╀綑绛夊緟[{1}]s", strConnectProcess, (waitTime - ((DateTime.Now - startTime).TotalSeconds)))
-                                            , LogInfoType.NOSHOW);
-                                        Thread.Sleep(1000);
-                                        continue;
+                                        if (!result)
+                                        {
+                                            LogInfo(string.Format("娴佺▼[{0}]杩愯缁撴灉澶辫触,鍘熷洜鏄痆{1}]", ProcessName, msg), LogInfoType.NOSHOW);
+                                        }
+
+                                        RunBll.GetBooleanOutput(ConnecResult, out result);
+                                        RunBll.Result = result;
                                     }
 
-                                    if (ConnectRunBll.bRuning || !ConnectRunBll.bCompleted)
+                                    if (result)
                                     {
-                                        GlobalVar.dicProcesses[ProcessName].Msg = string.Format("娴佺▼[{0}]鏈繍琛屽畬鎴�", ProcessName);
-                                        LogInfo(string.Format("鍏宠仈娴佺▼[{0}]鏈繍琛屽畬鎴�", strConnectProcess), LogInfoType.ERROR);
-                                        result = false;
                                         break;
                                     }
-                                    else if (!ConnectRunBll.bRuning && ConnectRunBll.bCompleted)
+                                    else if (!result && times > 0)
                                     {
-                                        LogInfo(string.Format("鍏宠仈娴佺▼[{0}]杩愯瀹屾垚", strConnectProcess), LogInfoType.INFO);
+                                        LogInfo(string.Format("娴佺▼[{0}]杩愯澶辫触閲嶆柊娴嬭瘯,鍓╀綑娆℃暟[{1}]", ProcessName, times), LogInfoType.WARN);
                                     }
 
-                                    result &= ConnectRunBll.Result;
-                                    if (!ConnectRunBll.Result)
+                                    times--;
+                                }
+                            }
+
+                            string ConnectProcess = item.Value["鍏宠仈娴佺▼"];
+                            if (!(ConnectProcess == null || string.IsNullOrEmpty(ConnectProcess) || ConnectProcess.Trim() == ""))
+                            {
+                                //鐢ㄩ�楀彿鎴栬�呭垎鍙峰幓闂撮殧鍏宠仈娴佺▼
+                                string[] arrConnectProcess;
+                                if (ConnectProcess.Split(';').Length >= ConnectProcess.Split(',').Length)
+                                {
+                                    arrConnectProcess = ConnectProcess.Split(';');
+                                }
+                                else
+                                {
+                                    arrConnectProcess = ConnectProcess.Split(',');
+                                }
+
+                                foreach (string strConnectProcess in arrConnectProcess)
+                                {
+                                    if (GlobalVar.dicProcesses.ContainsKey(strConnectProcess))
                                     {
-                                        LogInfo($"娴佺▼[{ProcessName}]鐨勫叧鑱旀祦绋媅{strConnectProcess}]杩愯澶辫触", LogInfoType.ERROR);
-                                        msg = $"鍏宠仈娴佺▼[{strConnectProcess}]杩愯澶辫触";
+                                        ProcessRunBll ConnectRunBll = GlobalVar.dicProcesses[strConnectProcess];
+
+                                        int waitTime = 10;
+                                        DateTime startTime = DateTime.Now;
+                                        while ((DateTime.Now - startTime).TotalSeconds < waitTime
+                                        && (ConnectRunBll.bRuning || !ConnectRunBll.bCompleted))
+                                        {
+                                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]鏈繍琛屽畬鎴�,鍓╀綑绛夊緟[{1}]s", strConnectProcess, (waitTime - ((DateTime.Now - startTime).TotalSeconds)))
+                                                , LogInfoType.NOSHOW);
+                                            Thread.Sleep(1000);
+                                            continue;
+                                        }
+
+                                        if (ConnectRunBll.bRuning || !ConnectRunBll.bCompleted)
+                                        {
+                                            GlobalVar.dicProcesses[ProcessName].Msg = string.Format("娴佺▼[{0}]鏈繍琛屽畬鎴�", ProcessName);
+                                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]鏈繍琛屽畬鎴�", strConnectProcess), LogInfoType.ERROR);
+                                            result = false;
+                                            break;
+                                        }
+                                        else if (!ConnectRunBll.bRuning && ConnectRunBll.bCompleted)
+                                        {
+                                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]杩愯瀹屾垚", strConnectProcess), LogInfoType.INFO);
+                                        }
+
+                                        result &= ConnectRunBll.Result;
+                                        if (!ConnectRunBll.Result)
+                                        {
+                                            LogInfo($"娴佺▼[{ProcessName}]鐨勫叧鑱旀祦绋媅{strConnectProcess}]杩愯澶辫触", LogInfoType.ERROR);
+                                            msg = $"鍏宠仈娴佺▼[{strConnectProcess}]杩愯澶辫触";
+                                        }
                                     }
                                 }
                             }
-                        }
 
-                        LogInfo(result ? $"娴佺▼[{ProcessName}]杩愯鎴愬姛" : $"娴佺▼[{ProcessName}]杩愯澶辫触,鍘熷洜鏄瘂msg}", result ? LogInfoType.PASS : LogInfoType.ERROR);
+                            LogInfo(result ? $"娴佺▼[{ProcessName}]杩愯鎴愬姛" : $"娴佺▼[{ProcessName}]杩愯澶辫触,鍘熷洜鏄瘂msg}", result ? LogInfoType.PASS : LogInfoType.ERROR);
 
-                        string SendComName = result ? item.Value["鎴愬姛閫氳"] : item.Value["澶辫触閫氳"];
-                        string SendMsg = result ? item.Value["鎴愬姛瀛楃"] : item.Value["澶辫触瀛楃"];
-                        if (GlobalVar.dicCommunicators.ContainsKey(SendComName) && (!string.IsNullOrEmpty(SendMsg) || SendMsg.Trim() != ""))
-                        {
-                            GlobalVar.dicCommunicators[SendComName].SendMessage(SendMsg);
-                            LogInfo(string.Format("鍙戦�佺粰[{0}]浜嗘秷鎭痋"{1}\"", SendComName, SendMsg), LogInfoType.INFO);
-                        }
-
-                    }
-                    catch (Exception ex)
-                    {
-                        LogInfo(string.Format("娴佺▼[{0}]杩愯鍙戠敓浜嗘剰澶�,鍘熷洜鏄�:{1}", ProcessName, ex.Message + $"銆恵ex.StackTrace}銆�"), LogInfoType.ERROR);
-
-                        RunBll.Result = false;
-                        RunBll.Msg = $"[鎰忓]{ex.Message}";
-                    }
-                    finally
-                    {
-                        #region 浠嶳unSettingPage鍜孡ayout涓幏鍙栨槸鍚︿繚瀛樺浘鐗�
-
-                        string strImageType = "jpeg";
-                        bool bSaveRunImage = false;
-                        bool bSaveResultImage = false;
-                        long lImageQuality = 100L;
-
-                        //ckbSaveRunImage
-                        if (GlobalVar.ControlStates.TryGetValue("ckbSaveRunImage_CheckBox", out object oSaveRunImage))
-                        {
-                            if (oSaveRunImage != null && oSaveRunImage is bool)
+                            string SendComName = result ? item.Value["鎴愬姛閫氳"] : item.Value["澶辫触閫氳"];
+                            string SendMsg = result ? item.Value["鎴愬姛瀛楃"] : item.Value["澶辫触瀛楃"];
+                            if (GlobalVar.dicCommunicators.ContainsKey(SendComName) && (!string.IsNullOrEmpty(SendMsg) || SendMsg.Trim() != ""))
                             {
-                                bSaveRunImage = (bool)oSaveRunImage;
+                                GlobalVar.dicCommunicators[SendComName].SendMessage(SendMsg);
+                                LogInfo(string.Format("鍙戦�佺粰[{0}]浜嗘秷鎭痋"{1}\"", SendComName, SendMsg), LogInfoType.INFO);
                             }
-                        }
 
-                        //ckbSaveResultImage
-                        if (GlobalVar.ControlStates.TryGetValue("ckbSaveResultImage_CheckBox", out object oSaveResultImage))
-                        {
-                            if (oSaveResultImage != null && oSaveResultImage is bool)
-                            {
-                                bSaveResultImage = (bool)oSaveResultImage;
-                            }
                         }
-
-                        //txtImageQuality
-                        if (GlobalVar.ControlStates.TryGetValue("txtImageQuality_TextBox", out object oImageQuality))
+                        catch (Exception ex)
                         {
-                            if (oImageQuality != null && oImageQuality is string)
-                            {
-                                lImageQuality = Convert.ToInt64((string)oImageQuality);
-                            }
+                            LogInfo(string.Format("娴佺▼[{0}]杩愯鍙戠敓浜嗘剰澶�,鍘熷洜鏄�:{1}", ProcessName, ex.Message + $"銆恵ex.StackTrace}銆�"), LogInfoType.ERROR);
+
+                            RunBll.Result = false;
+                            RunBll.Msg = $"[鎰忓]{ex.Message}";
                         }
-
-                        //cmbImageType
-                        if (GlobalVar.ControlStates.TryGetValue("cmbImageType_ComboBox", out object oImageType))
+                        finally
                         {
-                            try
+                            #region 浠嶳unSettingPage鍜孡ayout涓幏鍙栨槸鍚︿繚瀛樺浘鐗�
+
+                            string strImageType = "jpeg";
+                            bool bSaveRunImage = false;
+                            bool bSaveResultImage = false;
+                            long lImageQuality = 100L;
+
+                            //ckbSaveRunImage
+                            if (GlobalVar.ControlStates.TryGetValue("ckbSaveRunImage_CheckBox", out object oSaveRunImage))
                             {
-                                // 鍔ㄦ�佽В鏋怌omboBox鏁版嵁
-                                var json = JsonConvert.SerializeObject(oImageType);
-                                var comboData = JsonConvert.DeserializeAnonymousType(json, new
+                                if (oSaveRunImage != null && oSaveRunImage is bool)
                                 {
-                                    Items = new List<object>(),
-                                    SelectedIndex = 0
-                                });
-
-                                if (comboData != null && comboData.Items.Count > 0)
-                                {
-                                    strImageType = comboData.Items[comboData.SelectedIndex].ToString();
+                                    bSaveRunImage = (bool)oSaveRunImage;
                                 }
                             }
-                            catch { }
-                        }
 
-                        // 鐢熸垚鍥剧墖骞舵樉绀哄埌鎺т欢涓�
-                        HObject InputImage = null;
-                        HObject RecordImage = null;
-
-                        foreach (var layout in GlobalVar.dicLayout.Values
-                                    .Where(layout => layout.ProcessName == ProcessName)
-                                    .ToList())
-                        {
-                            string title = layout.Title;
-                            string strImagePath = layout.SaveImageDir;
-                            if (!AllProcessesPage.dicProcessControls.ContainsKey(title))
+                            //ckbSaveResultImage
+                            if (GlobalVar.ControlStates.TryGetValue("ckbSaveResultImage_CheckBox", out object oSaveResultImage))
                             {
-                                continue;
-                            }
-
-                            RunBll.GetImage(layout, out InputImage, out RecordImage);
-                            AllProcessesPage.dicProcessControls[title].ShowHoImage(RecordImage);
-
-                            if (!string.IsNullOrEmpty(layout.SaveImageDir))
-                            {
-                                string fileNameHead = layout.SaveImageHead;
-
-                                string result = Regex.Replace(fileNameHead, @"\{[^}]+\}", match =>
+                                if (oSaveResultImage != null && oSaveResultImage is bool)
                                 {
-                                    // 鍘婚櫎{}鍙繚鐣欐嫭鍙峰唴鐨勫唴瀹�
-                                    string content = match.Value;
-                                    content = content.Trim('{', '}'); // 鍘婚櫎棣栧熬鐨剓}
-
-                                    RunBll.GetStringOutput(content, out string str);
-                                    return str;
-                                });
-
-                                string fileName = $"{result}-[{DateTime.Now.ToString("HH.mm.ss.ffff")}]";
-
-                                // 浣跨敤姝e垯琛ㄨ揪寮忔浛鎹㈡墍鏈夐潪娉曞瓧绗�
-                                string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
-                                string pattern = $"[{invalidChars}]";
-                                fileName = Regex.Replace(fileName, pattern, "-");
-
-                                strImagePath = Regex.Replace(strImagePath, @"\{[^}]+\}", match =>
-                                {
-                                    // 鍘婚櫎{}鍙繚鐣欐嫭鍙峰唴鐨勫唴瀹�
-                                    string content = match.Value;
-                                    content = content.Trim('{', '}'); // 鍘婚櫎棣栧熬鐨剓}
-
-                                    RunBll.GetStringOutput(content, out string str);
-                                    return str;
-                                });
-
-                                if (bSaveRunImage)
-                                {
-                                    // 鏈�鍚庝竴绾х洰褰曞繀椤讳负骞存湀鏃�,浼氭牴鎹椂闂存潵鍒犻櫎鏃у浘鐗�
-                                    string directoryPath = Path.Combine(strImagePath, $"{ProcessName}\\鍘熷浘\\{RunBll.Result}\\{DateTime.Now.ToString("yyyyMMdd")}\\");
-                                    LB_SmartVision.Tool.Tool.AddRealImage(InputImage, directoryPath, fileName, strImageType, lImageQuality);
-                                }
-
-                                if (bSaveResultImage)
-                                {
-                                    // 鏈�鍚庝竴绾х洰褰曞繀椤讳负骞存湀鏃�,浼氭牴鎹椂闂存潵鍒犻櫎鏃у浘鐗�
-                                    string directoryPath = Path.Combine(strImagePath, $"{ProcessName}\\鎴浘\\{RunBll.Result}\\{DateTime.Now.ToString("yyyyMMdd")}\\");
-                                    LB_SmartVision.Tool.Tool.AddRealImage(RecordImage, directoryPath, fileName, "jpg", 50L);
+                                    bSaveResultImage = (bool)oSaveResultImage;
                                 }
                             }
-                        }
 
-                        foreach (var csv in GlobalVar.dicCsvSetting.Values
-                                    .Where(csv => csv.ProcessName == ProcessName)
-                                    .ToList())
-                        {
-                            if (RunBll.GetCsv(csv
-                                , out List<string> DataTitle, out Dictionary<string, object> ResultData))
+                            //txtImageQuality
+                            if (GlobalVar.ControlStates.TryGetValue("txtImageQuality_TextBox", out object oImageQuality))
                             {
-                                string filePath = Path.Combine(GlobalVar.strPathCsv, $"{ProcessName}.csv");
-                                LB_SmartVision.Tool.Tool.SaveData(filePath, DataTitle, ResultData);
+                                if (oImageQuality != null && oImageQuality is string)
+                                {
+                                    lImageQuality = Convert.ToInt64((string)oImageQuality);
+                                }
                             }
+
+                            //cmbImageType
+                            if (GlobalVar.ControlStates.TryGetValue("cmbImageType_ComboBox", out object oImageType))
+                            {
+                                try
+                                {
+                                    // 鍔ㄦ�佽В鏋怌omboBox鏁版嵁
+                                    var json = JsonConvert.SerializeObject(oImageType);
+                                    var comboData = JsonConvert.DeserializeAnonymousType(json, new
+                                    {
+                                        Items = new List<object>(),
+                                        SelectedIndex = 0
+                                    });
+
+                                    if (comboData != null && comboData.Items.Count > 0)
+                                    {
+                                        strImageType = comboData.Items[comboData.SelectedIndex].ToString();
+                                    }
+                                }
+                                catch { }
+                            }
+
+                            // 鐢熸垚鍥剧墖骞舵樉绀哄埌鎺т欢涓�
+                            HObject InputImage = null;
+                            HObject RecordImage = null;
+
+                            foreach (var layout in GlobalVar.dicLayout.Values
+                                        .Where(layout => layout.ProcessName == ProcessName)
+                                        .ToList())
+                            {
+                                string title = layout.Title;
+                                string strImagePath = layout.SaveImageDir;
+                                if (!AllProcessesPage.dicProcessControls.ContainsKey(title))
+                                {
+                                    continue;
+                                }
+
+                                RunBll.GetImage(layout, out InputImage, out RecordImage);
+                                AllProcessesPage.dicProcessControls[title].ShowHoImage(RecordImage);
+
+                                if (!string.IsNullOrEmpty(layout.SaveImageDir))
+                                {
+                                    string fileNameHead = layout.SaveImageHead;
+
+                                    string result = Regex.Replace(fileNameHead, @"\{[^}]+\}", match =>
+                                    {
+                                        // 鍘婚櫎{}鍙繚鐣欐嫭鍙峰唴鐨勫唴瀹�
+                                        string content = match.Value;
+                                        content = content.Trim('{', '}'); // 鍘婚櫎棣栧熬鐨剓}
+
+                                        RunBll.GetStringOutput(content, out string str);
+                                        return str;
+                                    });
+
+                                    string fileName = $"{result}-[{DateTime.Now.ToString("HH.mm.ss.ffff")}]";
+
+                                    // 浣跨敤姝e垯琛ㄨ揪寮忔浛鎹㈡墍鏈夐潪娉曞瓧绗�
+                                    string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
+                                    string pattern = $"[{invalidChars}]";
+                                    fileName = Regex.Replace(fileName, pattern, "-");
+
+                                    strImagePath = Regex.Replace(strImagePath, @"\{[^}]+\}", match =>
+                                    {
+                                        // 鍘婚櫎{}鍙繚鐣欐嫭鍙峰唴鐨勫唴瀹�
+                                        string content = match.Value;
+                                        content = content.Trim('{', '}'); // 鍘婚櫎棣栧熬鐨剓}
+
+                                        RunBll.GetStringOutput(content, out string str);
+                                        return str;
+                                    });
+
+                                    if (bSaveRunImage)
+                                    {
+                                        // 鏈�鍚庝竴绾х洰褰曞繀椤讳负骞存湀鏃�,浼氭牴鎹椂闂存潵鍒犻櫎鏃у浘鐗�
+                                        string directoryPath = Path.Combine(strImagePath, $"{ProcessName}\\鍘熷浘\\{RunBll.Result}\\{DateTime.Now.ToString("yyyyMMdd")}\\");
+                                        LB_SmartVision.Tool.Tool.AddRealImage(InputImage, directoryPath, fileName, strImageType, lImageQuality);
+                                    }
+
+                                    if (bSaveResultImage)
+                                    {
+                                        // 鏈�鍚庝竴绾х洰褰曞繀椤讳负骞存湀鏃�,浼氭牴鎹椂闂存潵鍒犻櫎鏃у浘鐗�
+                                        string directoryPath = Path.Combine(strImagePath, $"{ProcessName}\\鎴浘\\{RunBll.Result}\\{DateTime.Now.ToString("yyyyMMdd")}\\");
+                                        LB_SmartVision.Tool.Tool.AddRealImage(RecordImage, directoryPath, fileName, "jpg", 50L);
+                                    }
+                                }
+                            }
+
+                            foreach (var csv in GlobalVar.dicCsvSetting.Values
+                                        .Where(csv => csv.ProcessName == ProcessName)
+                                        .ToList())
+                            {
+                                if (RunBll.GetCsv(csv
+                                    , out List<string> DataTitle, out Dictionary<string, object> ResultData))
+                                {
+                                    string filePath = Path.Combine(GlobalVar.strPathCsv, $"{ProcessName}.csv");
+                                    LB_SmartVision.Tool.Tool.SaveData(filePath, DataTitle, ResultData);
+                                }
+                            }
+                            #endregion
                         }
-                        #endregion
-                    }
+                        is3D = false;
+                    });
                 });
-            });
+            }
+            else if (!is2D && !name.Contains("L"))
+            {
+                Task.Factory.StartNew(() =>
+                {
+                    if (!name.Contains("L"))
+                    {
+                        is2D = true;
+                    }
+                    Parallel.ForEach(matchedItems, item =>
+                    {
+                        string ProcessName = item.Value["娴佺▼鍚�"];
+                        LogInfo($"娴佺▼[{ProcessName}]寮�濮嬭繍琛�", LogInfoType.INFO);
+
+                        if (!GlobalVar.dicProcesses.ContainsKey(ProcessName))
+                        {
+                            LogInfo(string.Format("娴佺▼[{0}]涓嶅瓨鍦�,璇锋鏌ユ祦绋嬭缃�", ProcessName), LogInfoType.ERROR);
+                            return;
+                        }
+
+                        ProcessRunBll RunBll = GlobalVar.dicProcesses[ProcessName];
+                        if (RunBll == null || RunBll.bRuning)
+                        {
+                            LogInfo(string.Format("娴佺▼[{0}]涓婃鏈繍琛屽畬鎴�,瑙﹀彂澶辫触", ProcessName)
+                                , LogInfoType.ERROR);
+                            return;
+                        }
+
+                        try
+                        {
+                            bool result = false;
+                            string msg = string.Empty;
+                            int times = Convert.ToInt32(item.Value["閲嶆祴娆℃暟"].ToString());
+                            string ConnecResult = item.Value["鍏宠仈缁撴灉"];
+
+                            if (times < 0)
+                            {
+                                result = RunBll.Run();
+                                msg = RunBll.Msg;
+
+                                if (!(string.IsNullOrEmpty(ConnecResult) || ConnecResult.Trim() == "鏈叧鑱�"))
+                                {
+                                    if (!result)
+                                    {
+                                        LogInfo(string.Format("娴佺▼[{0}]杩愯缁撴灉澶辫触,鍘熷洜鏄痆{1}]", ProcessName, msg), LogInfoType.NOSHOW);
+                                    }
+                                    RunBll.GetBooleanOutput(ConnecResult, out result);
+                                    RunBll.Result = result;
+                                }
+
+                                if (!result)
+                                {
+                                    LogInfo($"娴佺▼[{ProcessName}]琚己鍒惰繍琛屾垚鍔�", LogInfoType.WARN);
+                                    RunBll.Result = true;
+                                    result = true;
+                                }
+                            }
+                            else
+                            {
+                                while (times >= 0)
+                                {
+                                    result = RunBll.Run();
+                                    msg = RunBll.Msg;
+                                    if (!(string.IsNullOrEmpty(ConnecResult) || ConnecResult.Trim() == "鏈叧鑱�"))
+                                    {
+                                        if (!result)
+                                        {
+                                            LogInfo(string.Format("娴佺▼[{0}]杩愯缁撴灉澶辫触,鍘熷洜鏄痆{1}]", ProcessName, msg), LogInfoType.NOSHOW);
+                                        }
+
+                                        RunBll.GetBooleanOutput(ConnecResult, out result);
+                                        RunBll.Result = result;
+                                    }
+
+                                    if (result)
+                                    {
+                                        break;
+                                    }
+                                    else if (!result && times > 0)
+                                    {
+                                        LogInfo(string.Format("娴佺▼[{0}]杩愯澶辫触閲嶆柊娴嬭瘯,鍓╀綑娆℃暟[{1}]", ProcessName, times), LogInfoType.WARN);
+                                    }
+
+                                    times--;
+                                }
+                            }
+
+                            string ConnectProcess = item.Value["鍏宠仈娴佺▼"];
+                            if (!(ConnectProcess == null || string.IsNullOrEmpty(ConnectProcess) || ConnectProcess.Trim() == ""))
+                            {
+                                //鐢ㄩ�楀彿鎴栬�呭垎鍙峰幓闂撮殧鍏宠仈娴佺▼
+                                string[] arrConnectProcess;
+                                if (ConnectProcess.Split(';').Length >= ConnectProcess.Split(',').Length)
+                                {
+                                    arrConnectProcess = ConnectProcess.Split(';');
+                                }
+                                else
+                                {
+                                    arrConnectProcess = ConnectProcess.Split(',');
+                                }
+
+                                foreach (string strConnectProcess in arrConnectProcess)
+                                {
+                                    if (GlobalVar.dicProcesses.ContainsKey(strConnectProcess))
+                                    {
+                                        ProcessRunBll ConnectRunBll = GlobalVar.dicProcesses[strConnectProcess];
+
+                                        int waitTime = 10;
+                                        DateTime startTime = DateTime.Now;
+                                        while ((DateTime.Now - startTime).TotalSeconds < waitTime
+                                        && (ConnectRunBll.bRuning || !ConnectRunBll.bCompleted))
+                                        {
+                                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]鏈繍琛屽畬鎴�,鍓╀綑绛夊緟[{1}]s", strConnectProcess, (waitTime - ((DateTime.Now - startTime).TotalSeconds)))
+                                                , LogInfoType.NOSHOW);
+                                            Thread.Sleep(1000);
+                                            continue;
+                                        }
+
+                                        if (ConnectRunBll.bRuning || !ConnectRunBll.bCompleted)
+                                        {
+                                            GlobalVar.dicProcesses[ProcessName].Msg = string.Format("娴佺▼[{0}]鏈繍琛屽畬鎴�", ProcessName);
+                                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]鏈繍琛屽畬鎴�", strConnectProcess), LogInfoType.ERROR);
+                                            result = false;
+                                            break;
+                                        }
+                                        else if (!ConnectRunBll.bRuning && ConnectRunBll.bCompleted)
+                                        {
+                                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]杩愯瀹屾垚", strConnectProcess), LogInfoType.INFO);
+                                        }
+
+                                        result &= ConnectRunBll.Result;
+                                        if (!ConnectRunBll.Result)
+                                        {
+                                            LogInfo($"娴佺▼[{ProcessName}]鐨勫叧鑱旀祦绋媅{strConnectProcess}]杩愯澶辫触", LogInfoType.ERROR);
+                                            msg = $"鍏宠仈娴佺▼[{strConnectProcess}]杩愯澶辫触";
+                                        }
+                                    }
+                                }
+                            }
+
+                            LogInfo(result ? $"娴佺▼[{ProcessName}]杩愯鎴愬姛" : $"娴佺▼[{ProcessName}]杩愯澶辫触,鍘熷洜鏄瘂msg}", result ? LogInfoType.PASS : LogInfoType.ERROR);
+
+                            string SendComName = result ? item.Value["鎴愬姛閫氳"] : item.Value["澶辫触閫氳"];
+                            string SendMsg = result ? item.Value["鎴愬姛瀛楃"] : item.Value["澶辫触瀛楃"];
+                            if (GlobalVar.dicCommunicators.ContainsKey(SendComName) && (!string.IsNullOrEmpty(SendMsg) || SendMsg.Trim() != ""))
+                            {
+                                GlobalVar.dicCommunicators[SendComName].SendMessage(SendMsg);
+                                LogInfo(string.Format("鍙戦�佺粰[{0}]浜嗘秷鎭痋"{1}\"", SendComName, SendMsg), LogInfoType.INFO);
+                            }
+
+                        }
+                        catch (Exception ex)
+                        {
+                            LogInfo(string.Format("娴佺▼[{0}]杩愯鍙戠敓浜嗘剰澶�,鍘熷洜鏄�:{1}", ProcessName, ex.Message + $"銆恵ex.StackTrace}銆�"), LogInfoType.ERROR);
+
+                            RunBll.Result = false;
+                            RunBll.Msg = $"[鎰忓]{ex.Message}";
+                        }
+                        finally
+                        {
+                            #region 浠嶳unSettingPage鍜孡ayout涓幏鍙栨槸鍚︿繚瀛樺浘鐗�
+
+                            string strImageType = "jpeg";
+                            bool bSaveRunImage = false;
+                            bool bSaveResultImage = false;
+                            long lImageQuality = 100L;
+
+                            //ckbSaveRunImage
+                            if (GlobalVar.ControlStates.TryGetValue("ckbSaveRunImage_CheckBox", out object oSaveRunImage))
+                            {
+                                if (oSaveRunImage != null && oSaveRunImage is bool)
+                                {
+                                    bSaveRunImage = (bool)oSaveRunImage;
+                                }
+                            }
+
+                            //ckbSaveResultImage
+                            if (GlobalVar.ControlStates.TryGetValue("ckbSaveResultImage_CheckBox", out object oSaveResultImage))
+                            {
+                                if (oSaveResultImage != null && oSaveResultImage is bool)
+                                {
+                                    bSaveResultImage = (bool)oSaveResultImage;
+                                }
+                            }
+
+                            //txtImageQuality
+                            if (GlobalVar.ControlStates.TryGetValue("txtImageQuality_TextBox", out object oImageQuality))
+                            {
+                                if (oImageQuality != null && oImageQuality is string)
+                                {
+                                    lImageQuality = Convert.ToInt64((string)oImageQuality);
+                                }
+                            }
+
+                            //cmbImageType
+                            if (GlobalVar.ControlStates.TryGetValue("cmbImageType_ComboBox", out object oImageType))
+                            {
+                                try
+                                {
+                                    // 鍔ㄦ�佽В鏋怌omboBox鏁版嵁
+                                    var json = JsonConvert.SerializeObject(oImageType);
+                                    var comboData = JsonConvert.DeserializeAnonymousType(json, new
+                                    {
+                                        Items = new List<object>(),
+                                        SelectedIndex = 0
+                                    });
+
+                                    if (comboData != null && comboData.Items.Count > 0)
+                                    {
+                                        strImageType = comboData.Items[comboData.SelectedIndex].ToString();
+                                    }
+                                }
+                                catch { }
+                            }
+
+                            // 鐢熸垚鍥剧墖骞舵樉绀哄埌鎺т欢涓�
+                            HObject InputImage = null;
+                            HObject RecordImage = null;
+
+                            foreach (var layout in GlobalVar.dicLayout.Values
+                                        .Where(layout => layout.ProcessName == ProcessName)
+                                        .ToList())
+                            {
+                                string title = layout.Title;
+                                string strImagePath = layout.SaveImageDir;
+                                if (!AllProcessesPage.dicProcessControls.ContainsKey(title))
+                                {
+                                    continue;
+                                }
+
+                                RunBll.GetImage(layout, out InputImage, out RecordImage);
+                                AllProcessesPage.dicProcessControls[title].ShowHoImage(RecordImage);
+
+                                if (!string.IsNullOrEmpty(layout.SaveImageDir))
+                                {
+                                    string fileNameHead = layout.SaveImageHead;
+
+                                    string result = Regex.Replace(fileNameHead, @"\{[^}]+\}", match =>
+                                    {
+                                        // 鍘婚櫎{}鍙繚鐣欐嫭鍙峰唴鐨勫唴瀹�
+                                        string content = match.Value;
+                                        content = content.Trim('{', '}'); // 鍘婚櫎棣栧熬鐨剓}
+
+                                        RunBll.GetStringOutput(content, out string str);
+                                        return str;
+                                    });
+
+                                    string fileName = $"{result}-[{DateTime.Now.ToString("HH.mm.ss.ffff")}]";
+
+                                    // 浣跨敤姝e垯琛ㄨ揪寮忔浛鎹㈡墍鏈夐潪娉曞瓧绗�
+                                    string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
+                                    string pattern = $"[{invalidChars}]";
+                                    fileName = Regex.Replace(fileName, pattern, "-");
+
+                                    strImagePath = Regex.Replace(strImagePath, @"\{[^}]+\}", match =>
+                                    {
+                                        // 鍘婚櫎{}鍙繚鐣欐嫭鍙峰唴鐨勫唴瀹�
+                                        string content = match.Value;
+                                        content = content.Trim('{', '}'); // 鍘婚櫎棣栧熬鐨剓}
+
+                                        RunBll.GetStringOutput(content, out string str);
+                                        return str;
+                                    });
+
+                                    if (bSaveRunImage)
+                                    {
+                                        // 鏈�鍚庝竴绾х洰褰曞繀椤讳负骞存湀鏃�,浼氭牴鎹椂闂存潵鍒犻櫎鏃у浘鐗�
+                                        string directoryPath = Path.Combine(strImagePath, $"{ProcessName}\\鍘熷浘\\{RunBll.Result}\\{DateTime.Now.ToString("yyyyMMdd")}\\");
+                                        LB_SmartVision.Tool.Tool.AddRealImage(InputImage, directoryPath, fileName, strImageType, lImageQuality);
+                                    }
+
+                                    if (bSaveResultImage)
+                                    {
+                                        // 鏈�鍚庝竴绾х洰褰曞繀椤讳负骞存湀鏃�,浼氭牴鎹椂闂存潵鍒犻櫎鏃у浘鐗�
+                                        string directoryPath = Path.Combine(strImagePath, $"{ProcessName}\\鎴浘\\{RunBll.Result}\\{DateTime.Now.ToString("yyyyMMdd")}\\");
+                                        LB_SmartVision.Tool.Tool.AddRealImage(RecordImage, directoryPath, fileName, "jpg", 50L);
+                                    }
+                                }
+                            }
+
+                            foreach (var csv in GlobalVar.dicCsvSetting.Values
+                                        .Where(csv => csv.ProcessName == ProcessName)
+                                        .ToList())
+                            {
+                                if (RunBll.GetCsv(csv
+                                    , out List<string> DataTitle, out Dictionary<string, object> ResultData))
+                                {
+                                    string filePath = Path.Combine(GlobalVar.strPathCsv, $"{ProcessName}.csv");
+                                    LB_SmartVision.Tool.Tool.SaveData(filePath, DataTitle, ResultData);
+                                }
+                            }
+                            #endregion
+                        }
+                        is2D = false;
+                    });
+                });
+            }
+
+            //Task.Factory.StartNew(() =>
+            //{
+            //    Parallel.ForEach(matchedItems, item =>
+            //    {
+            //        string ProcessName = item.Value["娴佺▼鍚�"];
+            //        LogInfo($"娴佺▼[{ProcessName}]寮�濮嬭繍琛�", LogInfoType.INFO);
+
+            //        if (!GlobalVar.dicProcesses.ContainsKey(ProcessName))
+            //        {
+            //            LogInfo(string.Format("娴佺▼[{0}]涓嶅瓨鍦�,璇锋鏌ユ祦绋嬭缃�", ProcessName), LogInfoType.ERROR);
+            //            return;
+            //        }
+
+            //        ProcessRunBll RunBll = GlobalVar.dicProcesses[ProcessName];
+            //        if (RunBll == null || RunBll.bRuning)
+            //        {
+            //            LogInfo(string.Format("娴佺▼[{0}]涓婃鏈繍琛屽畬鎴�,瑙﹀彂澶辫触", ProcessName)
+            //                , LogInfoType.ERROR);
+            //            return;
+            //        }
+
+            //        try
+            //        {
+            //            bool result = false;
+            //            string msg = string.Empty;
+            //            int times = Convert.ToInt32(item.Value["閲嶆祴娆℃暟"].ToString());
+            //            string ConnecResult = item.Value["鍏宠仈缁撴灉"];
+
+            //            if (times < 0)
+            //            {
+            //                result = RunBll.Run();
+            //                msg = RunBll.Msg;
+
+            //                if (!(string.IsNullOrEmpty(ConnecResult) || ConnecResult.Trim() == "鏈叧鑱�"))
+            //                {
+            //                    if (!result)
+            //                    {
+            //                        LogInfo(string.Format("娴佺▼[{0}]杩愯缁撴灉澶辫触,鍘熷洜鏄痆{1}]", ProcessName, msg), LogInfoType.NOSHOW);
+            //                    }
+            //                    RunBll.GetBooleanOutput(ConnecResult, out result);
+            //                    RunBll.Result = result;
+            //                }
+
+            //                if (!result)
+            //                {
+            //                    LogInfo($"娴佺▼[{ProcessName}]琚己鍒惰繍琛屾垚鍔�", LogInfoType.WARN);
+            //                    RunBll.Result = true;
+            //                    result = true;
+            //                }
+            //            }
+            //            else
+            //            {
+            //                while (times >= 0)
+            //                {
+            //                    result = RunBll.Run();
+            //                    msg = RunBll.Msg;
+            //                    if (!(string.IsNullOrEmpty(ConnecResult) || ConnecResult.Trim() == "鏈叧鑱�"))
+            //                    {
+            //                        if (!result)
+            //                        {
+            //                            LogInfo(string.Format("娴佺▼[{0}]杩愯缁撴灉澶辫触,鍘熷洜鏄痆{1}]", ProcessName, msg), LogInfoType.NOSHOW);
+            //                        }
+
+            //                        RunBll.GetBooleanOutput(ConnecResult, out result);
+            //                        RunBll.Result = result;
+            //                    }
+
+            //                    if (result)
+            //                    {
+            //                        break;
+            //                    }
+            //                    else if (!result && times > 0)
+            //                    {
+            //                        LogInfo(string.Format("娴佺▼[{0}]杩愯澶辫触閲嶆柊娴嬭瘯,鍓╀綑娆℃暟[{1}]", ProcessName, times), LogInfoType.WARN);
+            //                    }
+
+            //                    times--;
+            //                }
+            //            }
+
+            //            string ConnectProcess = item.Value["鍏宠仈娴佺▼"];
+            //            if (!(ConnectProcess == null || string.IsNullOrEmpty(ConnectProcess) || ConnectProcess.Trim() == ""))
+            //            {
+            //                //鐢ㄩ�楀彿鎴栬�呭垎鍙峰幓闂撮殧鍏宠仈娴佺▼
+            //                string[] arrConnectProcess;
+            //                if (ConnectProcess.Split(';').Length >= ConnectProcess.Split(',').Length)
+            //                {
+            //                    arrConnectProcess = ConnectProcess.Split(';');
+            //                }
+            //                else
+            //                {
+            //                    arrConnectProcess = ConnectProcess.Split(',');
+            //                }
+
+            //                foreach (string strConnectProcess in arrConnectProcess)
+            //                {
+            //                    if (GlobalVar.dicProcesses.ContainsKey(strConnectProcess))
+            //                    {
+            //                        ProcessRunBll ConnectRunBll = GlobalVar.dicProcesses[strConnectProcess];
+
+            //                        int waitTime = 10;
+            //                        DateTime startTime = DateTime.Now;
+            //                        while ((DateTime.Now - startTime).TotalSeconds < waitTime
+            //                        && (ConnectRunBll.bRuning || !ConnectRunBll.bCompleted))
+            //                        {
+            //                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]鏈繍琛屽畬鎴�,鍓╀綑绛夊緟[{1}]s", strConnectProcess, (waitTime - ((DateTime.Now - startTime).TotalSeconds)))
+            //                                , LogInfoType.NOSHOW);
+            //                            Thread.Sleep(1000);
+            //                            continue;
+            //                        }
+
+            //                        if (ConnectRunBll.bRuning || !ConnectRunBll.bCompleted)
+            //                        {
+            //                            GlobalVar.dicProcesses[ProcessName].Msg = string.Format("娴佺▼[{0}]鏈繍琛屽畬鎴�", ProcessName);
+            //                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]鏈繍琛屽畬鎴�", strConnectProcess), LogInfoType.ERROR);
+            //                            result = false;
+            //                            break;
+            //                        }
+            //                        else if (!ConnectRunBll.bRuning && ConnectRunBll.bCompleted)
+            //                        {
+            //                            LogInfo(string.Format("鍏宠仈娴佺▼[{0}]杩愯瀹屾垚", strConnectProcess), LogInfoType.INFO);
+            //                        }
+
+            //                        result &= ConnectRunBll.Result;
+            //                        if (!ConnectRunBll.Result)
+            //                        {
+            //                            LogInfo($"娴佺▼[{ProcessName}]鐨勫叧鑱旀祦绋媅{strConnectProcess}]杩愯澶辫触", LogInfoType.ERROR);
+            //                            msg = $"鍏宠仈娴佺▼[{strConnectProcess}]杩愯澶辫触";
+            //                        }
+            //                    }
+            //                }
+            //            }
+
+            //            LogInfo(result ? $"娴佺▼[{ProcessName}]杩愯鎴愬姛" : $"娴佺▼[{ProcessName}]杩愯澶辫触,鍘熷洜鏄瘂msg}", result ? LogInfoType.PASS : LogInfoType.ERROR);
+
+            //            string SendComName = result ? item.Value["鎴愬姛閫氳"] : item.Value["澶辫触閫氳"];
+            //            string SendMsg = result ? item.Value["鎴愬姛瀛楃"] : item.Value["澶辫触瀛楃"];
+            //            if (GlobalVar.dicCommunicators.ContainsKey(SendComName) && (!string.IsNullOrEmpty(SendMsg) || SendMsg.Trim() != ""))
+            //            {
+            //                GlobalVar.dicCommunicators[SendComName].SendMessage(SendMsg);
+            //                LogInfo(string.Format("鍙戦�佺粰[{0}]浜嗘秷鎭痋"{1}\"", SendComName, SendMsg), LogInfoType.INFO);
+            //            }
+
+            //        }
+            //        catch (Exception ex)
+            //        {
+            //            LogInfo(string.Format("娴佺▼[{0}]杩愯鍙戠敓浜嗘剰澶�,鍘熷洜鏄�:{1}", ProcessName, ex.Message + $"銆恵ex.StackTrace}銆�"), LogInfoType.ERROR);
+
+            //            RunBll.Result = false;
+            //            RunBll.Msg = $"[鎰忓]{ex.Message}";
+            //        }
+            //        finally
+            //        {
+            //            #region 浠嶳unSettingPage鍜孡ayout涓幏鍙栨槸鍚︿繚瀛樺浘鐗�
+
+            //            string strImageType = "jpeg";
+            //            bool bSaveRunImage = false;
+            //            bool bSaveResultImage = false;
+            //            long lImageQuality = 100L;
+
+            //            //ckbSaveRunImage
+            //            if (GlobalVar.ControlStates.TryGetValue("ckbSaveRunImage_CheckBox", out object oSaveRunImage))
+            //            {
+            //                if (oSaveRunImage != null && oSaveRunImage is bool)
+            //                {
+            //                    bSaveRunImage = (bool)oSaveRunImage;
+            //                }
+            //            }
+
+            //            //ckbSaveResultImage
+            //            if (GlobalVar.ControlStates.TryGetValue("ckbSaveResultImage_CheckBox", out object oSaveResultImage))
+            //            {
+            //                if (oSaveResultImage != null && oSaveResultImage is bool)
+            //                {
+            //                    bSaveResultImage = (bool)oSaveResultImage;
+            //                }
+            //            }
+
+            //            //txtImageQuality
+            //            if (GlobalVar.ControlStates.TryGetValue("txtImageQuality_TextBox", out object oImageQuality))
+            //            {
+            //                if (oImageQuality != null && oImageQuality is string)
+            //                {
+            //                    lImageQuality = Convert.ToInt64((string)oImageQuality);
+            //                }
+            //            }
+
+            //            //cmbImageType
+            //            if (GlobalVar.ControlStates.TryGetValue("cmbImageType_ComboBox", out object oImageType))
+            //            {
+            //                try
+            //                {
+            //                    // 鍔ㄦ�佽В鏋怌omboBox鏁版嵁
+            //                    var json = JsonConvert.SerializeObject(oImageType);
+            //                    var comboData = JsonConvert.DeserializeAnonymousType(json, new
+            //                    {
+            //                        Items = new List<object>(),
+            //                        SelectedIndex = 0
+            //                    });
+
+            //                    if (comboData != null && comboData.Items.Count > 0)
+            //                    {
+            //                        strImageType = comboData.Items[comboData.SelectedIndex].ToString();
+            //                    }
+            //                }
+            //                catch { }
+            //            }
+
+            //            // 鐢熸垚鍥剧墖骞舵樉绀哄埌鎺т欢涓�
+            //            HObject InputImage = null;
+            //            HObject RecordImage = null;
+
+            //            foreach (var layout in GlobalVar.dicLayout.Values
+            //                        .Where(layout => layout.ProcessName == ProcessName)
+            //                        .ToList())
+            //            {
+            //                string title = layout.Title;
+            //                string strImagePath = layout.SaveImageDir;
+            //                if (!AllProcessesPage.dicProcessControls.ContainsKey(title))
+            //                {
+            //                    continue;
+            //                }
+
+            //                RunBll.GetImage(layout, out InputImage, out RecordImage);
+            //                AllProcessesPage.dicProcessControls[title].ShowHoImage(RecordImage);
+
+            //                if (!string.IsNullOrEmpty(layout.SaveImageDir))
+            //                {
+            //                    string fileNameHead = layout.SaveImageHead;
+
+            //                    string result = Regex.Replace(fileNameHead, @"\{[^}]+\}", match =>
+            //                    {
+            //                        // 鍘婚櫎{}鍙繚鐣欐嫭鍙峰唴鐨勫唴瀹�
+            //                        string content = match.Value;
+            //                        content = content.Trim('{', '}'); // 鍘婚櫎棣栧熬鐨剓}
+
+            //                        RunBll.GetStringOutput(content, out string str);
+            //                        return str;
+            //                    });
+
+            //                    string fileName = $"{result}-[{DateTime.Now.ToString("HH.mm.ss.ffff")}]";
+
+            //                    // 浣跨敤姝e垯琛ㄨ揪寮忔浛鎹㈡墍鏈夐潪娉曞瓧绗�
+            //                    string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
+            //                    string pattern = $"[{invalidChars}]";
+            //                    fileName = Regex.Replace(fileName, pattern, "-");
+
+            //                    strImagePath = Regex.Replace(strImagePath, @"\{[^}]+\}", match =>
+            //                    {
+            //                        // 鍘婚櫎{}鍙繚鐣欐嫭鍙峰唴鐨勫唴瀹�
+            //                        string content = match.Value;
+            //                        content = content.Trim('{', '}'); // 鍘婚櫎棣栧熬鐨剓}
+
+            //                        RunBll.GetStringOutput(content, out string str);
+            //                        return str;
+            //                    });
+
+            //                    if (bSaveRunImage)
+            //                    {
+            //                        // 鏈�鍚庝竴绾х洰褰曞繀椤讳负骞存湀鏃�,浼氭牴鎹椂闂存潵鍒犻櫎鏃у浘鐗�
+            //                        string directoryPath = Path.Combine(strImagePath, $"{ProcessName}\\鍘熷浘\\{RunBll.Result}\\{DateTime.Now.ToString("yyyyMMdd")}\\");
+            //                        LB_SmartVision.Tool.Tool.AddRealImage(InputImage, directoryPath, fileName, strImageType, lImageQuality);
+            //                    }
+
+            //                    if (bSaveResultImage)
+            //                    {
+            //                        // 鏈�鍚庝竴绾х洰褰曞繀椤讳负骞存湀鏃�,浼氭牴鎹椂闂存潵鍒犻櫎鏃у浘鐗�
+            //                        string directoryPath = Path.Combine(strImagePath, $"{ProcessName}\\鎴浘\\{RunBll.Result}\\{DateTime.Now.ToString("yyyyMMdd")}\\");
+            //                        LB_SmartVision.Tool.Tool.AddRealImage(RecordImage, directoryPath, fileName, "jpg", 50L);
+            //                    }
+            //                }
+            //            }
+
+            //            foreach (var csv in GlobalVar.dicCsvSetting.Values
+            //                        .Where(csv => csv.ProcessName == ProcessName)
+            //                        .ToList())
+            //            {
+            //                if (RunBll.GetCsv(csv
+            //                    , out List<string> DataTitle, out Dictionary<string, object> ResultData))
+            //                {
+            //                    string filePath = Path.Combine(GlobalVar.strPathCsv, $"{ProcessName}.csv");
+            //                    LB_SmartVision.Tool.Tool.SaveData(filePath, DataTitle, ResultData);
+            //                }
+            //            }
+            //            #endregion
+            //        }
+            //    });
+            //});
         }
 
         private void VisionForm_FormClosing(object sender, FormClosingEventArgs e)
@@ -2365,76 +3036,101 @@
 
         private void btn_Run_Click(object sender, EventArgs e)
         {
-            var matchedItems = GlobalVar.dicProcessSetting
-                                        .Where(item =>
-                                        {
-                                            var value = item.Value;
-                                            var triggerComm = value["瑙﹀彂閫氳"];
-                                            var triggerChar = value["瑙﹀彂瀛楃"];
-                                            return triggerComm != null;
-                                            //return triggerComm != null && triggerComm.Equals(name) &&
-                                            //       (string.IsNullOrEmpty(triggerChar?.ToString()) ||
-                                            //        msg.StartsWith(triggerChar.ToString()));
-                                        })
-                                        .ToList(); // 閬垮厤閲嶅瀛楀吀璁块棶鍜岃绠辨搷浣�
-            if (matchedItems.Count <= 0)
+            //var matchedItems = GlobalVar.dicProcessSetting
+            //                            .Where(item =>
+            //                            {
+            //                                var value = item.Value;
+            //                                var triggerComm = value["瑙﹀彂閫氳"];
+            //                                var triggerChar = value["瑙﹀彂瀛楃"];
+            //                                return triggerComm != null && !triggerComm.Equals("鏃�");
+            //                                //return triggerComm != null && triggerComm.Equals(name) &&
+            //                                //       (string.IsNullOrEmpty(triggerChar?.ToString()) ||
+            //                                //        msg.StartsWith(triggerChar.ToString()));
+            //                            })
+            //                            .ToList(); // 閬垮厤閲嶅瀛楀吀璁块棶鍜岃绠辨搷浣�
+            //if (matchedItems.Count <= 0)
+            //{
+            //    return;
+            //}
+            //foreach (var item in matchedItems)
+            //{
+            //    Task.Factory.StartNew(() =>
+            //    {
+            //        TriggerRunMessageReceived(item.Value["瑙﹀彂閫氳"], item.Value["瑙﹀彂瀛楃"]);
+            //    });
+            //}
+            foreach (var item in GlobalVar.dicCameras.Keys)
             {
-                return;
+                GlobalVar.dicCameras[item].StartSingleGrab();
             }
-            TriggerRunMessageReceived(matchedItems[0].Value["瑙﹀彂閫氳"], matchedItems[0].Value["瑙﹀彂瀛楃"]);
         }
 
         private void btn_RunContinuously_Click(object sender, EventArgs e)
         {
-            if (btn_RunContinuously.Text.Equals("杩炵画杩愯"))
+            if (this.ckbAllowRun.Checked)
             {
-                _isTabSwitchAllowed = false;
-                btn_RunContinuously.Text = "鏆傚仠杩愯";
-                // 鍏抽棴浣胯兘
-                SelectMainPage();
-                btn_GlobalVar.Enabled = false;
-                btn_Login.Enabled = false;
-                btn_SingleRun.Enabled = false;
-                ckbAllowRun.Enabled = false;
-                Task.Factory.StartNew(() =>
+                if (btn_RunContinuously.Text.Equals("杩炵画杩愯"))
                 {
-                    var matchedItems = GlobalVar.dicProcessSetting
-                                                .Where(item =>
-                                                {
-                                                    var value = item.Value;
-                                                    var triggerComm = value["瑙﹀彂閫氳"];
-                                                    var triggerChar = value["瑙﹀彂瀛楃"];
-                                                    return triggerComm != null;
-                                                    //return triggerComm != null && triggerComm.Equals(name) &&
-                                                    //       (string.IsNullOrEmpty(triggerChar?.ToString()) ||
-                                                    //        msg.StartsWith(triggerChar.ToString()));
-                                                })
-                                                .ToList(); // 閬垮厤閲嶅瀛楀吀璁块棶鍜岃绠辨搷浣�
-                    while (btn_RunContinuously.Text.Equals("鏆傚仠杩愯"))
+                    _isTabSwitchAllowed = false;
+                    btn_RunContinuously.Text = "鏆傚仠杩愯";
+                    // 鍏抽棴浣胯兘
+                    SelectMainPage();
+                    btn_GlobalVar.Enabled = false;
+                    btn_Login.Enabled = false;
+                    btn_SingleRun.Enabled = false;
+                    ckbAllowRun.Enabled = false;
+                    foreach (var item in GlobalVar.dicCameras.Keys)
                     {
-
-                        TriggerRunMessageReceived(matchedItems[0].Value["瑙﹀彂閫氳"], matchedItems[0].Value["瑙﹀彂瀛楃"]);
-                        Thread.Sleep(3500);
+                        GlobalVar.dicCameras[item].StartContinuousGrab();
                     }
-                    //this.Invoke(() =>
+                    //Task.Factory.StartNew(() =>
                     //{
+                    //    var matchedItems = GlobalVar.dicProcessSetting
+                    //                                .Where(item =>
+                    //                                {
+                    //                                    var value = item.Value;
+                    //                                    var triggerComm = value["瑙﹀彂閫氳"];
+                    //                                    var triggerChar = value["瑙﹀彂瀛楃"];
+                    //                                    return triggerComm != null && !triggerComm.Equals("鏃�");
+                    //                                    //return triggerComm != null && triggerComm.Equals(name) &&
+                    //                                    //       (string.IsNullOrEmpty(triggerChar?.ToString()) ||
+                    //                                    //        msg.StartsWith(triggerChar.ToString()));
+                    //                                })
+                    //                                .ToList(); // 閬垮厤閲嶅瀛楀吀璁块棶鍜岃绠辨搷浣�
+                    //    while (btn_RunContinuously.Text.Equals("鏆傚仠杩愯"))
+                    //    {
+                    //        foreach (var item in matchedItems)
+                    //        {
+                    //            Task.Factory.StartNew(() =>
+                    //            {
+                    //                TriggerRunMessageReceived(item.Value["瑙﹀彂閫氳"], item.Value["瑙﹀彂瀛楃"]);
+                    //            });
+                    //        }
+                    //        //TriggerRunMessageReceived(matchedItems[0].Value["瑙﹀彂閫氳"], matchedItems[0].Value["瑙﹀彂瀛楃"]);
+                    //        Thread.Sleep(3500);
+                    //    }
+                    //    //this.Invoke(() =>
+                    //    //{
+                    //    //});
                     //});
-                });
+                }
+                else if (btn_RunContinuously.Text.Equals("鏆傚仠杩愯"))
+                {
+                    btn_RunContinuously.Text = "杩炵画杩愯";
+                    foreach (var item in GlobalVar.dicCameras.Keys)
+                    {
+                        GlobalVar.dicCameras[item].StopGrabbing();
+                    }
+                    // 鍚姩浣胯兘
+                    UnSelectMainPage();
+                    btn_GlobalVar.Enabled = true;
+                    btn_Login.Enabled = true;
+                    btn_SingleRun.Enabled = true;
+                    ckbAllowRun.Enabled = true;
+                    Thread.Sleep(100);
+                    _isTabSwitchAllowed = true;
+                }
             }
-            else if (btn_RunContinuously.Text.Equals("鏆傚仠杩愯"))
-            {
-                btn_RunContinuously.Text = "杩炵画杩愯";
-
-                // 鍚姩浣胯兘
-                UnSelectMainPage();
-                btn_GlobalVar.Enabled = true;
-                btn_Login.Enabled = true;
-                btn_SingleRun.Enabled = true;
-                ckbAllowRun.Enabled = true;
-                Thread.Sleep(100);
-                _isTabSwitchAllowed = true;
-            }
-
         }
 
         private void cmbProduct_SelectedValueChanged(object sender, EventArgs e)

--
Gitblit v1.9.3