| LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.Designer.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorsEditPage.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_SmartVision/Forms/Pages/CommunicatorPage/CreateCommunicatorForm.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_SmartVision/ProcessRun/ProcessContext.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_SmartVision/VisionForm.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionFlowNode/IFlowContext.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Communicators/CommunicatorConfig.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Communicators/CommunicatorForm.Designer.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Communicators/CommunicatorForm.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/Communicators/CommunicatorForm.resx | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.Designer.cs
@@ -150,6 +150,7 @@ txtAddress.Name = "txtAddress"; txtAddress.Size = new Size(100, 21); txtAddress.TabIndex = 9; txtAddress.TextChanged += txtAddress_TextChanged; // // cmbType // LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.cs
@@ -3,13 +3,26 @@ using LB_VisionProcesses.Communicators.TCom; using ReaLTaiizor.Forms; using RJCP.IO.Ports; using S7.Net; using System.Diagnostics; using System.Linq; namespace LB_SmartVision.Forms.Pages.CommunicatorPage { public delegate void CommunicatorChange(BaseCommunicator communicator); public partial class CommunicatorForm : Form { BaseCommunicator communicator { get; set; } public event CommunicatorChange CommunicatorChanged; private void communicatorChanged(BaseCommunicator communicator) { if (CommunicatorChanged != null) { CommunicatorChanged(communicator); } } public CommunicatorForm() { @@ -54,6 +67,9 @@ txtIP.Visible = false; cmbIP.Visible = true; this.btnRuleSend.Visible = true; lblType.Visible = false; lblAddress.Visible = false; cmbType.Visible = false; @@ -68,6 +84,9 @@ txtPort.SelectedText = communicator.CommunicatorConnections["端口"]?.ToString(); txtIP.Visible = true; cmbIP.Visible = false; this.btnRuleSend.Visible = false; lblType.Visible = false; lblAddress.Visible = false; @@ -86,10 +105,15 @@ if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["型号"]?.ToString())) { cmbType.Items.Add(communicator.CommunicatorConnections["型号"]?.ToString()); cmbType.Text = communicator.CommunicatorConnections["型号"]?.ToString(); } cmbType.Text = communicator.CommunicatorConnections["型号"]?.ToString(); if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["变量地址"]?.ToString())) { txtAddress.Text = communicator.CommunicatorConnections["变量地址"]?.ToString(); } txtIP.Visible = true; cmbIP.Visible = false; this.btnRuleSend.Visible = false; lblType.Visible = true; lblAddress.Visible = true; @@ -115,6 +139,14 @@ return; //取消回调函数 communicator.MessageReceived -= ShowReceiveMsg; if (communicator != null) { communicatorChanged(communicator); if (GlobalVar.dicCommunicators != null && GlobalVar.dicCommunicators.Keys.Count > 0 && GlobalVar.dicCommunicators.Keys.Contains(communicator.CommunicatorName)) { GlobalVar.dicCommunicators[communicator.CommunicatorName] = communicator; } } } catch (Exception ex) { @@ -222,5 +254,18 @@ if (communicator.SendMessage(SendMsg)) ShowSendMsg(SendMsg); } private void txtAddress_TextChanged(object sender, EventArgs e) { if (communicator != null && !communicator.CommunicatorConnections.Contains("变量地址")) { communicator.CommunicatorConnections.Add("变量地址", txtAddress.Text); } else if (communicator != null) { communicator.CommunicatorConnections["变量地址"] = txtAddress.Text; communicatorChanged(communicator); } } } } LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorsEditPage.cs
@@ -126,12 +126,18 @@ if (GlobalVar.dicCommunicators.ContainsKey(name)) { CommunicatorForm cameraForm = new CommunicatorForm(GlobalVar.dicCommunicators[name], name); cameraForm.Show(); CommunicatorForm communicatorFForm = new CommunicatorForm(GlobalVar.dicCommunicators[name], name); communicatorFForm.CommunicatorChanged += CommunicatorFForm_CommunicatorChanged; communicatorFForm.Show(); } } } private void CommunicatorFForm_CommunicatorChanged(BaseCommunicator communicator) { } // 移除通讯口 private void DeleteEvent(string Name, string Text) { LB_SmartVision/Forms/Pages/CommunicatorPage/CreateCommunicatorForm.cs
@@ -131,7 +131,7 @@ MessageBox.Show("未选择通讯类型!", "异常"); return; } if (!communicator.Connect()) if (communicator.Connect()) { uiButtonCreate.Enabled = true; communicator.Disconnect(); @@ -146,7 +146,7 @@ private void uiButtonCreate_Click(object sender, EventArgs e) { if (!communicator.Connect()) if (communicator.Connect()) { bCreate = true; this.Close(); LB_SmartVision/ProcessRun/ProcessContext.cs
@@ -573,6 +573,8 @@ [Node("Halcon2D斑点工具", "Haclon2D工具", "Basic", "Halcon2D斑点工具")] public void Halcon2D斑点工具(FlowNode node) { RunNodeAsync(node); } [Node("通讯模块", "通讯工具", "Basic", "通讯模块")] public void 通讯模块(FlowNode node) { RunNodeAsync(node); } #endregion LB_SmartVision/VisionForm.cs
@@ -17,6 +17,7 @@ using LB_VisionProcesses.Cameras; using LB_VisionProcesses.Cameras.HRCameras; using LB_VisionProcesses.Communicators; using LB_VisionProcesses.Communicators.SiemensS7; using LB_VisionProcesses.Communicators.TCom; using LB_VisionProcesses.Forms; using log4net.Config; @@ -43,7 +44,7 @@ { AllProcessesPage AllProcessesPages = new AllProcessesPage(); CamerasEditPage CamerasEditPage = new CamerasEditPage(); HistoricalDataEditPage HistoricalDataEditPage = new HistoricalDataEditPage(); HistoricalDataEditPage HistoricalDataEditPage = new HistoricalDataEditPage(); CommunicatorsEditPage CommunicatorsEditPage = new CommunicatorsEditPage(); SettingEditPage SettingEditPage = new SettingEditPage(); MESEditPage MESEditPage = new MESEditPage(); @@ -790,65 +791,122 @@ { string CommunicatorName = CommunicatorConnectionString.Key; string CommunicatorAddress = CommunicatorConnectionString.Value; // 定义正则表达式以提取协议、IP 地址和端口 //1. \((.*?)\):\(和 \) 是用于匹配括号的转义字符。 // (.*?) 是一个非贪婪的匹配,用来匹配类名(MyProcesses.Communicators.TCPServer 或 MyProcesses.Communicators.UARTPort)。 //2. ([^:] +):匹配冒号之前的部分,即地址(127.0.0.1 或 COM5)。这里使用了[^:] 来匹配除了冒号之外的任意字符。 //3. (\d +) :匹配端口号,确保它匹配一个或多个数字。 string pattern = @"^\((?<ClassName>[^)]+)\)\[(?<IP>[^]]+)\]\[(?<PORT>[^]]+)\]$"; Match match = Regex.Match(CommunicatorAddress, pattern); if (match.Success) if (!string.IsNullOrEmpty(CommunicatorAddress) && CommunicatorAddress.Contains("SiemensLBS7")) { string ClassName = match.Groups["ClassName"].Value; // "TCP" string IP = match.Groups["IP"].Value; // "127.0.0.1" string PORT = match.Groups["PORT"].Value; // "1111" // 定义正则表达式以提取协议、IP 地址和端口 //1. \((.*?)\):\(和 \) 是用于匹配括号的转义字符。 // (.*?) 是一个非贪婪的匹配,用来匹配类名(MyProcesses.Communicators.TCPServer 或 MyProcesses.Communicators.UARTPort)。 //2. ([^:] +):匹配冒号之前的部分,即地址(127.0.0.1 或 COM5)。这里使用了[^:] 来匹配除了冒号之外的任意字符。 //3. (\d +) :匹配端口号,确保它匹配一个或多个数字。 if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT)) break; string pattern = @"^\((?<ClassName>[^)]+)\)\[(?<IP>[^]]+)\]\[(?<Slot>[^]]+)\]\[(?<CpuType>[^]]+)\]\[(?<PlcAddress>[^]]+)\]$"; Match match = Regex.Match(CommunicatorAddress, pattern); //利用反射创建实例 Type type = IProcess.GetExecutingAssembly().GetType(ClassName); if (type == null) if (match.Success) { Debug.WriteLine("Class not found."); return false; } var Communicator = Activator.CreateInstance(type, CommunicatorName) as BaseCommunicator; 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 PlcAddress = match.Groups["PlcAddress"].Value; if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(Slot) || string.IsNullOrEmpty(CpuType) || string.IsNullOrEmpty(PlcAddress)) break; if (Communicator == null) { Debug.WriteLine("BaseCommunicator not found."); return false; } //利用反射创建实例 Type type = IProcess.GetExecutingAssembly().GetType(ClassName); if (type == null) { Debug.WriteLine("Class not found."); return false; } var Communicator = Activator.CreateInstance(type, CommunicatorName) as BaseCommunicator; //TCP客户端最后再连接 if (Communicator is TCPClient) { clientsCommunicatorsConnectionString.TryAdd(CommunicatorConnectionString.Key, CommunicatorConnectionString.Value); continue; } if (Communicator == null) { Debug.WriteLine("BaseCommunicator not found."); return false; } Communicator.CommunicatorConnections.Add("地址", IP); Communicator.CommunicatorConnections.Add("端口", PORT); Communicator.CommunicatorName = CommunicatorName; if (!Communicator.Connect()) { LogInfo($"初始化通讯口[{CommunicatorName}]失败,原因是{Communicator.Msg}", LogInfoType.ERROR); Communicator.CommunicatorConnections.Add("地址", IP); Communicator.CommunicatorConnections.Add("端口", Slot); Communicator.CommunicatorConnections.Add("型号", CpuType); Communicator.CommunicatorConnections.Add("变量地址", PlcAddress); Communicator.CommunicatorName = CommunicatorName; if (!Communicator.Connect()) { LogInfo($"初始化通讯口[{CommunicatorName}]失败,原因是{Communicator.Msg}", LogInfoType.ERROR); } else { LogInfo($"初始化通讯口[{CommunicatorName}]成功", LogInfoType.PASS); } GlobalVar.dicCommunicators.TryAdd(CommunicatorName, Communicator); } else { LogInfo($"初始化通讯口[{CommunicatorName}]成功", LogInfoType.PASS); Debug.WriteLine("No match found."); } GlobalVar.dicCommunicators.TryAdd(CommunicatorName, Communicator); } else { Debug.WriteLine("No match found."); } // 定义正则表达式以提取协议、IP 地址和端口 //1. \((.*?)\):\(和 \) 是用于匹配括号的转义字符。 // (.*?) 是一个非贪婪的匹配,用来匹配类名(MyProcesses.Communicators.TCPServer 或 MyProcesses.Communicators.UARTPort)。 //2. ([^:] +):匹配冒号之前的部分,即地址(127.0.0.1 或 COM5)。这里使用了[^:] 来匹配除了冒号之外的任意字符。 //3. (\d +) :匹配端口号,确保它匹配一个或多个数字。 string pattern = @"^\((?<ClassName>[^)]+)\)\[(?<IP>[^]]+)\]\[(?<PORT>[^]]+)\]$"; Match match = Regex.Match(CommunicatorAddress, pattern); if (match.Success) { string ClassName = match.Groups["ClassName"].Value; // "TCP" string IP = match.Groups["IP"].Value; // "127.0.0.1" string PORT = match.Groups["PORT"].Value; // "1111" if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT)) break; //利用反射创建实例 Type type = IProcess.GetExecutingAssembly().GetType(ClassName); if (type == null) { Debug.WriteLine("Class not found."); return false; } var Communicator = Activator.CreateInstance(type, CommunicatorName) as BaseCommunicator; if (Communicator == null) { Debug.WriteLine("BaseCommunicator not found."); return false; } //TCP客户端最后再连接 if (Communicator is TCPClient) { clientsCommunicatorsConnectionString.TryAdd(CommunicatorConnectionString.Key, CommunicatorConnectionString.Value); continue; } Communicator.CommunicatorConnections.Add("地址", IP); Communicator.CommunicatorConnections.Add("端口", PORT); Communicator.CommunicatorName = CommunicatorName; if (!Communicator.Connect()) { LogInfo($"初始化通讯口[{CommunicatorName}]失败,原因是{Communicator.Msg}", LogInfoType.ERROR); } else { LogInfo($"初始化通讯口[{CommunicatorName}]成功", LogInfoType.PASS); } GlobalVar.dicCommunicators.TryAdd(CommunicatorName, Communicator); } else { Debug.WriteLine("No match found."); } } } //TCP客户端最后连接 @@ -929,13 +987,26 @@ string ClassName = item.Value.GetType().FullName;// "TCP" string IP = item.Value.CommunicatorConnections["地址"].ToString();//"127.0.0.1" string PORT = item.Value.CommunicatorConnections["端口"].ToString();//"1111" if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT)) if (!string.IsNullOrEmpty(ClassName) && ClassName.Contains("SiemensLBS7")) { break; string CpuType = item.Value.CommunicatorConnections["型号"].ToString(); string PlcAddress = item.Value.CommunicatorConnections["变量地址"].ToString(); if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT) || string.IsNullOrEmpty(CpuType) || string.IsNullOrEmpty(PlcAddress)) { break; } string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}][{CpuType}][{PlcAddress}]"; GlobalVar.allCommunicatorsConnectionString.TryAdd(item.Key, CommunicatorConnectionString); } string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}]"; GlobalVar.allCommunicatorsConnectionString.TryAdd(item.Key, CommunicatorConnectionString); else { if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT)) { break; } string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}]"; GlobalVar.allCommunicatorsConnectionString.TryAdd(item.Key, CommunicatorConnectionString); } } var settings = new JsonSerializerSettings { LB_VisionFlowNode/IFlowContext.cs
@@ -283,6 +283,9 @@ [Node("Halcon2D斑点工具", "Haclon2D工具", "Basic", "Halcon2D斑点工具")] public void Halcon2D斑点工具(FlowNode node) { RunNodeAsync(node); } [Node("通讯模块", "通讯模块工具", "Basic", "通讯模块")] public void 通讯模块(FlowNode node) { RunNodeAsync(node); } #endregion LB_VisionProcesses/Communicators/CommunicatorConfig.cs
@@ -7,7 +7,7 @@ namespace LB_VisionProcesses.Communicators { [Serializable] [Process("通讯测试", Category = "通讯工具", Description = "创建通讯测试工具")] [Process("通讯模块", Category = "通讯工具", Description = "创建通讯模块工具")] public class CommunicatorConfig : IProcess { /// <summary> @@ -19,7 +19,7 @@ { this.dicCommunicators = dicCommunicators; strProcessName = "通讯测试"; strProcessName = "通讯模块"; strProcessClass = "LB_VisionProcesses.Communicators.CommunicatorConfig"; Params.Inputs.Add("通讯口名", ""); LB_VisionProcesses/Communicators/CommunicatorForm.Designer.cs
@@ -54,6 +54,8 @@ label6 = new Label(); themeForm1 = new ReaLTaiizor.Forms.ThemeForm(); controlBox1 = new ReaLTaiizor.Controls.ControlBox(); lblAddress = new Label(); txtAddress = new TextBox(); grpSetting.SuspendLayout(); grpReceive.SuspendLayout(); grpTest.SuspendLayout(); @@ -102,7 +104,7 @@ // // btnDisconnect // btnDisconnect.ForeColor = SystemColors.WindowText; btnDisconnect.ForeColor = SystemColors.Control; btnDisconnect.Location = new Point(118, 109); btnDisconnect.Name = "btnDisconnect"; btnDisconnect.Size = new Size(75, 23); @@ -113,7 +115,7 @@ // // btnConnect // btnConnect.ForeColor = SystemColors.WindowText; btnConnect.ForeColor = SystemColors.Control; btnConnect.Location = new Point(14, 109); btnConnect.Name = "btnConnect"; btnConnect.Size = new Size(75, 23); @@ -185,11 +187,13 @@ // grpTest // grpTest.Controls.Add(lblCom); grpTest.Controls.Add(txtAddress); grpTest.Controls.Add(ckbRuleCheck); grpTest.Controls.Add(cmbCom); grpTest.Controls.Add(cmbType); grpTest.Controls.Add(lblType); grpTest.Controls.Add(btnRun); grpTest.Controls.Add(lblAddress); grpTest.Controls.Add(lblMsg); grpTest.Controls.Add(txtMsg); grpTest.ForeColor = SystemColors.Control; @@ -269,6 +273,7 @@ // txtMsg.Location = new Point(59, 76); txtMsg.Name = "txtMsg"; txtMsg.ReadOnly = true; txtMsg.Size = new Size(245, 23); txtMsg.TabIndex = 0; // @@ -329,6 +334,23 @@ controlBox1.TabIndex = 0; controlBox1.Text = "controlBox1"; // // lblAddress // lblAddress.AutoSize = true; lblAddress.Location = new Point(20, 115); lblAddress.Name = "lblAddress"; lblAddress.Size = new Size(32, 17); lblAddress.TabIndex = 0; lblAddress.Text = "地址"; // // txtAddress // txtAddress.Location = new Point(59, 112); txtAddress.Name = "txtAddress"; txtAddress.ReadOnly = true; txtAddress.Size = new Size(94, 23); txtAddress.TabIndex = 6; // // CommunicatorForm // AutoScaleDimensions = new SizeF(96F, 96F); @@ -388,5 +410,7 @@ private Label label6; private ReaLTaiizor.Forms.ThemeForm themeForm1; private ReaLTaiizor.Controls.ControlBox controlBox1; private TextBox txtAddress; private Label lblAddress; } } LB_VisionProcesses/Communicators/CommunicatorForm.cs
@@ -85,6 +85,7 @@ cmbType.Text = type.ToString(); ckbRuleCheck.Checked = bRuleCheck; txtMsg.Text = Msg; this.grpSetting.ForeColor= SystemColors.Control; } } @@ -115,12 +116,16 @@ cmbIP.Visible = true; txtIP.Visible = false; this.lblAddress.Visible = false; this.txtAddress.Visible = false; lblIP.Text = "串口号"; lblIP.Text = "波特率"; cmbIP.Text = communicator.CommunicatorConnections["地址"].ToString(); txtPort.Text = communicator.CommunicatorConnections["端口"].ToString(); this.grpSetting.ForeColor = SystemColors.Control; } else if (communicator is LocalMonitor) { @@ -129,31 +134,40 @@ cmbIP.Visible = false; txtIP.Visible = true; this.lblAddress.Visible = false; this.txtAddress.Visible = false; lblIP.Text = "监控文件"; lblIP.Text = "写入文件"; txtIP.Text = communicator.CommunicatorConnections["地址"].ToString(); txtPort.Text = communicator.CommunicatorConnections["端口"].ToString(); this.grpSetting.ForeColor = SystemColors.Control; } else if (communicator is SiemensLBS7) { btnSend.Enabled = communicator.bConnected; btnRuleSend.Enabled = communicator.bConnected; cmbIP.Visible = false; txtIP.Visible = true; this.lblAddress.Visible = true; this.txtAddress.Visible = true; lblIP.Text = "IP"; lblIP.Text = "槽"; txtIP.Text = communicator.CommunicatorConnections["地址"].ToString(); txtPort.Text = communicator.CommunicatorConnections["槽"].ToString(); txtPort.Text = communicator.CommunicatorConnections["端口"].ToString(); this.txtAddress.Text = communicator.CommunicatorConnections["变量地址"]?.ToString(); this.grpSetting.ForeColor = SystemColors.Control; btnRuleSend.Visible = false; } else { btnSend.Enabled = communicator.bConnected; btnRuleSend.Enabled = false; this.lblAddress.Visible = false; this.txtAddress.Visible = false; cmbIP.Visible = false; txtIP.Visible = true; LB_VisionProcesses/Communicators/CommunicatorForm.resx
@@ -121,7 +121,7 @@ <data name="themeForm1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <value> iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO wgAADsIBFShKgAAAA+JJREFUWEftVkuIHGUQbt34iMEoq2S2q3p3yTJsuqpnJ+L6WBRdwaigohfFgEou wQAADsEBuJFr7QAAA+JJREFUWEftVkuIHGUQbt34iMEoq2S2q3p3yTJsuqpnJ+L6WBRdwaigohfFgEou BkVBUPCBCEG8BXNQ48GLeImCehIJxMsqhsSZruod46K4HtSIGjU+4iOr0c1I9fSsM3/PLNtCPO0H36m/ evz/X11VnreKVRTAHPOZumkY6lFwqURws3BwZ8ywTQnuiCP/+iTCzY1qaUPzdm/Atf3PaHre6XPsjyQM 2xLGV4XwIyX4QRj+UMK/lPFvJTyhBMeV8IgQvmRJuH4Ko+l5p9UjGBbCJ5RxTgj+VMZmXxKcSAjekHE/