From 4d0e6429436835ab65ffe70c73afe47dc1a531f7 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期一, 19 一月 2026 08:39:47 +0800
Subject: [PATCH] 在运动控制界面添加可配置的PLC相关参数修复工具图像输入bug添加项目文件。在运动控制界面添加可配置的PLC相关参数。

---
 LB_SmartVision/VisionForm.cs |   78 +++++++++++++++++++++++++++++++++------
 1 files changed, 66 insertions(+), 12 deletions(-)

diff --git a/LB_SmartVision/VisionForm.cs b/LB_SmartVision/VisionForm.cs
index 98bf6a7..31f11a8 100644
--- a/LB_SmartVision/VisionForm.cs
+++ b/LB_SmartVision/VisionForm.cs
@@ -16,6 +16,7 @@
 using LB_VisionProcesses;
 using LB_VisionProcesses.Cameras;
 using LB_VisionProcesses.Cameras.HRCameras;
+using LB_VisionProcesses.Cameras.LBCameras;
 using LB_VisionProcesses.Communicators;
 using LB_VisionProcesses.Communicators.SiemensS7;
 using LB_VisionProcesses.Communicators.TCom;
@@ -65,6 +66,7 @@
             Assembly_LB_VisionProcessesDll = Assembly.Load(Assembly_LB_VisionProcessesBytes);
 
             GlobalVar.dicCommunicators.DictionaryChanged += CommunicatorsChanged;
+            GlobalVar.dicCameras.DictionaryChanged += CamerasChanged;
             GlobalVar.dicProcesses.DictionaryChanged += ProcessRunBllChanged;
 
             //鏈�寮�濮嬪氨娓呯┖鎵�鏈塗ab椤�
@@ -238,7 +240,30 @@
 
         private void CommunicatorsChanged(object? sender, DictionaryChangedEventArgs<string, BaseCommunicator> e)
         {
-
+            try
+            {
+                switch (e.ChangeType)
+                {
+                    case DictionaryChangeType.Added:
+                        e.NewValue.TriggerRunMessageReceived += TriggerRunMessageReceived;
+                        LogInfo($"閫氳鍙{e.NewValue.CommunicatorName}]鍔犺浇瑙﹀彂閫氳", LogInfoType.INFO);
+                        e.NewValue.CommunicatorName = e.NewKey;
+                        break;
+                    case DictionaryChangeType.Renamed:
+                        string OldCommunicatorName = e.OldKey;
+                        string NewCommunicatorName = e.NewKey;
+                        LogInfo(string.Format("閲嶅懡鍚嶉�氳鍙e悕[{0}]淇敼涓篬{1}]", OldCommunicatorName, NewCommunicatorName), LogInfoType.INFO);
+                        e.NewValue.CommunicatorName = NewCommunicatorName;
+                        break;
+                    case DictionaryChangeType.Removed:
+                        if (e.OldValue != null && e.OldValue is BaseCommunicator)
+                            e.OldValue.Disconnect();
+                        e.OldValue.TriggerRunMessageReceived -= TriggerRunMessageReceived;
+                        LogInfo($"閫氳鍙{e.OldValue.CommunicatorName}]绉婚櫎瑙﹀彂閫氳", LogInfoType.INFO);
+                        break;
+                }
+            }
+            catch { }
         }
 
         private void LogInfo(string strLog, LogInfoType infoType)
@@ -525,6 +550,28 @@
             }
         }
 
+        private void CamerasChanged(object sender, DictionaryChangedEventArgs<string, BaseCamera> e)
+        {
+            try
+            {
+                switch (e.ChangeType)
+                {
+                    case DictionaryChangeType.Added:
+                        e.NewValue.TriggerRunMessageReceived += TriggerRunMessageReceived;
+                        LogInfo($"鐩告満[{e.NewValue.SN}]鍔犺浇瑙﹀彂閫氳", LogInfoType.INFO);
+                        e.NewValue.SN = e.NewKey;
+                        break;
+                    case DictionaryChangeType.Removed:
+                        if (e.OldValue != null && e.OldValue is BaseCommunicator)
+                            e.OldValue.CloseDevice();
+                        e.OldValue.TriggerRunMessageReceived -= TriggerRunMessageReceived;
+                        LogInfo($"鐩告満[{e.OldValue.SN}]绉婚櫎瑙﹀彂閫氳", LogInfoType.INFO);
+                        break;
+                }
+            }
+            catch { }
+        }
+
         private void VisionForm_Load(object sender, EventArgs e)
         {
             XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
@@ -688,7 +735,7 @@
                         }
                     case CameraBrand.LBCamera:
                         {
-                            //camera = new LBCamera();
+                            camera = new LBCamera();
                             break;
                         }
                     default:
@@ -698,7 +745,7 @@
                         }
                 }
                 camera.SN = CameraConnectionString.Key;
-                if (!camera.InitDevice(CameraConnectionString.Key, this.Handle))
+                if (!camera.InitDevice(CameraConnectionString.Key, IntPtr.Zero))
                 {
                     LogInfo($"鍒濆鍖栫浉鏈篬{CameraConnectionString.Key}]澶辫触", LogInfoType.ERROR);
                     if (camera != null)
@@ -794,12 +841,8 @@
                     if (!string.IsNullOrEmpty(CommunicatorAddress) && CommunicatorAddress.Contains("SiemensLBS7"))
                     {
                         // 瀹氫箟姝e垯琛ㄨ揪寮忎互鎻愬彇鍗忚銆両P 鍦板潃鍜岀鍙�
-                        //1.    \((.*?)\)锛歕(鍜� \) 鏄敤浜庡尮閰嶆嫭鍙风殑杞箟瀛楃銆�
-                        //      (.*?) 鏄竴涓潪璐┆鐨勫尮閰嶏紝鐢ㄦ潵鍖归厤绫诲悕锛圡yProcesses.Communicators.TCPServer 鎴� MyProcesses.Communicators.UARTPort锛夈��
-                        //2.    ([^:] +)锛氬尮閰嶅啋鍙蜂箣鍓嶇殑閮ㄥ垎锛屽嵆鍦板潃锛�127.0.0.1 鎴� COM5锛夈�傝繖閲屼娇鐢ㄤ簡[^:] 鏉ュ尮閰嶉櫎浜嗗啋鍙蜂箣澶栫殑浠绘剰瀛楃銆�
-                        //3.    (\d +) 锛氬尮閰嶇鍙e彿锛岀‘淇濆畠鍖归厤涓�涓垨澶氫釜鏁板瓧銆�
-
-                        string pattern = @"^\((?<ClassName>[^)]+)\)\[(?<IP>[^]]+)\]\[(?<Slot>[^]]+)\]\[(?<CpuType>[^]]+)\]\[(?<PlcAddress>[^]]+)\]$";
+                        // 鏇存柊姝e垯浠ユ敮鎸佸彲閫夌殑鏁版嵁绫诲瀷瀛楁
+                        string pattern = @"^\((?<ClassName>[^)]+)\)\[(?<IP>[^]]+)\]\[(?<Slot>[^]]+)\]\[(?<CpuType>[^]]+)\]\[(?<PlcAddress>[^]]+)\](?:\[(?<DataType>[^]]+)\])?$";
                         Match match = Regex.Match(CommunicatorAddress, pattern);
 
                         if (match.Success)
@@ -807,8 +850,10 @@
                             string ClassName = match.Groups["ClassName"].Value;   // "TCP"
                             string IP = match.Groups["IP"].Value;          // "127.0.0.1"
                             string Slot = match.Groups["Slot"].Value;        // "1111"
-                            string CpuType= match.Groups["CpuType"].Value;
+                            string CpuType = match.Groups["CpuType"].Value;
                             string PlcAddress = match.Groups["PlcAddress"].Value;
+                            string DataType = match.Groups["DataType"].Success ? match.Groups["DataType"].Value : "String";
+
                             if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(Slot) || string.IsNullOrEmpty(CpuType) || string.IsNullOrEmpty(PlcAddress))
                                 break;
 
@@ -831,6 +876,7 @@
                             Communicator.CommunicatorConnections.Add("绔彛", Slot);
                             Communicator.CommunicatorConnections.Add("鍨嬪彿", CpuType);
                             Communicator.CommunicatorConnections.Add("鍙橀噺鍦板潃", PlcAddress);
+                            Communicator.CommunicatorConnections.Add("鏁版嵁绫诲瀷", DataType);
                             Communicator.CommunicatorName = CommunicatorName;
                             if (!Communicator.Connect())
                             {
@@ -981,7 +1027,6 @@
             {
                 string strJson = string.Empty;
                 GlobalVar.allCommunicatorsConnectionString = new ConcurrentDictionary<string, string>();
-
                 foreach (var item in GlobalVar.dicCommunicators)
                 {
                     string ClassName = item.Value.GetType().FullName;// "TCP"
@@ -991,11 +1036,14 @@
                     {
                         string CpuType = item.Value.CommunicatorConnections["鍨嬪彿"].ToString();
                         string PlcAddress = item.Value.CommunicatorConnections["鍙橀噺鍦板潃"].ToString();
+                        string DataType = item.Value.CommunicatorConnections.Contains("鏁版嵁绫诲瀷") ?
+                                          item.Value.CommunicatorConnections["鏁版嵁绫诲瀷"].ToString() : "String";
+
                         if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT) || string.IsNullOrEmpty(CpuType) || string.IsNullOrEmpty(PlcAddress))
                         {
                             break;
                         }
-                        string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}][{CpuType}][{PlcAddress}]";
+                        string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}][{CpuType}][{PlcAddress}][{DataType}]";
                         GlobalVar.allCommunicatorsConnectionString.TryAdd(item.Key, CommunicatorConnectionString);
                     }
                     else
@@ -1007,6 +1055,7 @@
                         string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}]";
                         GlobalVar.allCommunicatorsConnectionString.TryAdd(item.Key, CommunicatorConnectionString);
                     }
+                    GlobalVar.dicCommunicators[item.Key].ClassName = ClassName;
                 }
                 var settings = new JsonSerializerSettings
                 {
@@ -1031,6 +1080,11 @@
                     { }
                 }
                 File.WriteAllText(GlobalVar.allCommunicatorsConnectionStringPath, strJson, Encoding.UTF8);
+                foreach (var item in GlobalVar.dicCommunicators)
+                {
+                    string ClassName = item.Value.GetType().FullName;// "TCP"
+                }
+                ConfigManager<ObservableConcurrentDictionary<string, BaseCommunicator>>.SaveConfig<ObservableConcurrentDictionary<string, BaseCommunicator>>(GlobalVar.dicCommunicators, GlobalVar.strApplicationPath + "\\鎵�鏈変骇鍝乗\" + GlobalVar.strProductName + "\\dicCommunicators.json");
                 return true;
             }
             catch { return false; }

--
Gitblit v1.9.3