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 |  754 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 530 insertions(+), 224 deletions(-)

diff --git a/LB_SmartVision/VisionForm.cs b/LB_SmartVision/VisionForm.cs
index 15eca14..be74509 100644
--- a/LB_SmartVision/VisionForm.cs
+++ b/LB_SmartVision/VisionForm.cs
@@ -1945,6 +1945,8 @@
             }
 
         }
+        bool is3D = false;
+        bool is2D = false;
 
         private void TriggerRunMessageReceived(string name, string msg)
         {
@@ -2064,294 +2066,598 @@
             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(() =>
             //{

--
Gitblit v1.9.3