| | |
| | | using LB_VisionProcesses.Communicators; |
| | | using LB_SmartVisionCommon; |
| | | using LB_VisionProcesses.Communicators; |
| | | using LB_VisionProcesses.Communicators.SiemensS7; |
| | | using LB_VisionProcesses.Communicators.TCom; |
| | | using RJCP.IO.Ports; |
| | | using System; |
| | |
| | | communicator = new UARTPort(); |
| | | |
| | | rButtonUART.Checked = true; |
| | | uiLabelS7Type.Visible = false; |
| | | uiComboBoxS7Type.Visible = false; |
| | | uiButtonCreate.Enabled = false; |
| | | } |
| | | |
| | | private void uiButtonTest_Click(object sender, EventArgs e) |
| | | { |
| | | uiButtonCreate.Enabled = false; |
| | | |
| | | rButtonUART.Enabled = false; |
| | | rButtonTCPServer.Enabled = false; |
| | | rButtonTCPClient.Enabled = false; |
| | | rButtonMonitor.Enabled = false; |
| | | rButtonS7.Enabled = false; |
| | | |
| | | if (communicator != null) |
| | | communicator.Disconnect(); |
| | |
| | | |
| | | IP = uiComboBoxPort.Text; |
| | | PORT = uiTextBoxPort.Text; |
| | | communicator.CommunicatorConnections.Add("地址", IP); |
| | | communicator.CommunicatorConnections.Add("端口", PORT); |
| | | } |
| | | else if (rButtonTCPServer.Checked) |
| | | { |
| | |
| | | |
| | | IP = uiIPTextBox.Text; |
| | | PORT = uiTextBoxPort.Text; |
| | | communicator.CommunicatorConnections.Add("地址", IP); |
| | | communicator.CommunicatorConnections.Add("端口", PORT); |
| | | } |
| | | else if (rButtonTCPClient.Checked) |
| | | { |
| | |
| | | |
| | | IP = uiIPTextBox.Text; |
| | | PORT = uiTextBoxPort.Text; |
| | | communicator.CommunicatorConnections.Add("地址", IP); |
| | | communicator.CommunicatorConnections.Add("端口", PORT); |
| | | } |
| | | else if (rButtonMonitor.Checked) |
| | | else if (rButtonS7.Checked) |
| | | { |
| | | communicator = new LocalMonitor(); |
| | | communicator = new SiemensLBS7(); |
| | | |
| | | IP = uiTextBoxPath.Text; |
| | | PORT = uiTextBoxPort.Text; |
| | | switch (uiComboBoxS7Type.Text) |
| | | { |
| | | case "S7200": |
| | | { |
| | | cpuType = S7.Net.CpuType.S7200; |
| | | break; |
| | | } |
| | | case "Logo0BA8": |
| | | { |
| | | cpuType = S7.Net.CpuType.Logo0BA8; |
| | | break; |
| | | } |
| | | case "S7200Smart": |
| | | { |
| | | cpuType = S7.Net.CpuType.S7200Smart; |
| | | break; |
| | | } |
| | | case "S7300": |
| | | { |
| | | cpuType = S7.Net.CpuType.S7300; |
| | | break; |
| | | } |
| | | case "S7400": |
| | | { |
| | | cpuType = S7.Net.CpuType.S7400; |
| | | break; |
| | | } |
| | | case "S71200": |
| | | { |
| | | cpuType = S7.Net.CpuType.S71200; |
| | | break; |
| | | } |
| | | case "S71500": |
| | | { |
| | | cpuType = S7.Net.CpuType.S71500; |
| | | break; |
| | | } |
| | | default: |
| | | cpuType = S7.Net.CpuType.S71500; |
| | | break; |
| | | } |
| | | communicator.CommunicatorConnections.Add("地址", IP); |
| | | communicator.CommunicatorConnections.Add("端口", PORT); |
| | | communicator.CommunicatorConnections.Add("型号", cpuType); |
| | | } |
| | | else |
| | | { |
| | | MessageBox.Show("未选择通讯类型!", "异常"); |
| | | return; |
| | | } |
| | | |
| | | communicator.CommunicatorConnections.Add("地址", IP); |
| | | communicator.CommunicatorConnections.Add("端口", PORT); |
| | | if (communicator.Connect()) |
| | | if (!communicator.Connect()) |
| | | { |
| | | uiButtonCreate.Enabled = true; |
| | | communicator.Disconnect(); |
| | |
| | | |
| | | public string IP = string.Empty; |
| | | public string PORT = string.Empty; |
| | | public S7.Net.CpuType cpuType = S7.Net.CpuType.S71500; |
| | | |
| | | private void uiButtonCreate_Click(object sender, EventArgs e) |
| | | { |
| | | if (communicator.Connect()) |
| | | if (!communicator.Connect()) |
| | | { |
| | | bCreate = true; |
| | | this.Close(); |
| | |
| | | uiLabelPort.Text = "波特率"; |
| | | uiTextBoxPort.Visible = true; |
| | | |
| | | uiLabelS7Type.Visible = false; |
| | | uiComboBoxS7Type.Visible = false; |
| | | |
| | | |
| | | uiButtonCreate.Enabled = false; |
| | | } |
| | | } |
| | |
| | | uiLabelPort.Text = "端口"; |
| | | uiTextBoxPort.Visible = true; |
| | | |
| | | uiLabelS7Type.Visible = false; |
| | | uiComboBoxS7Type.Visible = false; |
| | | |
| | | uiButtonCreate.Enabled = false; |
| | | } |
| | | } |
| | |
| | | uiLabelPort.Visible = true; |
| | | uiLabelPort.Text = "端口"; |
| | | uiTextBoxPort.Visible = true; |
| | | |
| | | uiLabelS7Type.Visible = false; |
| | | uiComboBoxS7Type.Visible = false; |
| | | |
| | | } |
| | | } |
| | | |
| | | private void rButtonMonitor_CheckedChanged(object sender, EventArgs e) |
| | | private void rButtonS7_CheckedChanged(object sender, EventArgs e) |
| | | { |
| | | uiButtonCreate.Enabled = false; |
| | | if (communicator != null) |
| | | communicator.Disconnect(); |
| | | |
| | | if (rButtonMonitor.Checked) |
| | | if (rButtonS7.Checked) |
| | | { |
| | | uiLabelIP.Visible = true; |
| | | uiLabelIP.Text = "监控文件"; |
| | | uiLabelIP.Text = "地址"; |
| | | uiIPTextBox.Visible = false; |
| | | uiComboBoxPort.Visible = false; |
| | | uiTextBoxPath.Visible = true; |
| | | |
| | | uiLabelPort.Visible = true; |
| | | uiLabelPort.Text = "写入文件"; |
| | | uiLabelPort.Text = "槽"; |
| | | uiTextBoxPort.Visible = true; |
| | | |
| | | uiLabelS7Type.Visible = true; |
| | | uiComboBoxS7Type.Visible = true; |
| | | uiComboBoxS7Type.Items.Clear(); |
| | | |
| | | foreach (var c in Enum.GetValues(typeof(S7.Net.CpuType))) |
| | | { |
| | | uiComboBoxS7Type.Items.Add(c.ToString()); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | uiButtonCreate.Enabled = false; |
| | | } |
| | | |
| | | private void uiComboBoxS7Type_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | switch (uiComboBoxS7Type.Text) |
| | | { |
| | | case "S7200": |
| | | { |
| | | cpuType = S7.Net.CpuType.S7200; |
| | | break; |
| | | } |
| | | case "Logo0BA8": |
| | | { |
| | | cpuType = S7.Net.CpuType.Logo0BA8; |
| | | break; |
| | | } |
| | | case "S7200Smart": |
| | | { |
| | | cpuType = S7.Net.CpuType.S7200Smart; |
| | | break; |
| | | } |
| | | case "S7300": |
| | | { |
| | | cpuType = S7.Net.CpuType.S7300; |
| | | break; |
| | | } |
| | | case "S7400": |
| | | { |
| | | cpuType = S7.Net.CpuType.S7400; |
| | | break; |
| | | } |
| | | case "S71200": |
| | | { |
| | | cpuType = S7.Net.CpuType.S71200; |
| | | break; |
| | | } |
| | | case "S71500": |
| | | { |
| | | cpuType = S7.Net.CpuType.S71500; |
| | | break; |
| | | } |
| | | default: |
| | | cpuType = S7.Net.CpuType.S71500; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |