C3204
2026-01-13 67fd626e321eb93bcc6427e017e536e696b0270a
LB_SmartVision/Forms/Pages/CommunicatorPage/CreateCommunicatorForm.cs
@@ -1,4 +1,6 @@
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;
@@ -30,17 +32,18 @@
                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();
@@ -51,6 +54,8 @@
                IP = uiComboBoxPort.Text;
                PORT = uiTextBoxPort.Text;
                communicator.CommunicatorConnections.Add("地址", IP);
                communicator.CommunicatorConnections.Add("端口", PORT);
            }
            else if (rButtonTCPServer.Checked)
            {
@@ -58,6 +63,8 @@
                IP = uiIPTextBox.Text;
                PORT = uiTextBoxPort.Text;
                communicator.CommunicatorConnections.Add("地址", IP);
                communicator.CommunicatorConnections.Add("端口", PORT);
            }
            else if (rButtonTCPClient.Checked)
            {
@@ -65,22 +72,65 @@
                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())
            {
                uiButtonCreate.Enabled = true;
@@ -92,6 +142,7 @@
        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)
        {
@@ -131,6 +182,10 @@
                uiLabelPort.Text = "波特率";
                uiTextBoxPort.Visible = true;
                uiLabelS7Type.Visible = false;
                uiComboBoxS7Type.Visible = false;
                uiButtonCreate.Enabled = false;
            }
        }
@@ -153,6 +208,9 @@
                uiLabelPort.Text = "端口";
                uiTextBoxPort.Visible = true;
                uiLabelS7Type.Visible = false;
                uiComboBoxS7Type.Visible = false;
                uiButtonCreate.Enabled = false;
            }
        }
@@ -174,26 +232,39 @@
                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());
                }
            }
        }
@@ -219,5 +290,50 @@
        {
            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;
            }
        }
    }
}