Browse Source

setting form

weijw 5 months ago
parent
commit
2cebf0979e
10 changed files with 726 additions and 106 deletions
  1. 109 0
      ConfigHelper.cs
  2. 90 24
      MainForm.Designer.cs
  3. 102 51
      MainForm.cs
  4. 9 0
      MainForm.resx
  5. 3 0
      Program.cs
  6. 321 4
      SettingForm.Designer.cs
  7. 59 1
      SettingForm.cs
  8. 25 25
      SettingForm.resx
  9. 2 1
      config.xml
  10. 6 0
      xicheji.csproj

+ 109 - 0
ConfigHelper.cs

@@ -0,0 +1,109 @@
+
+using S7.Net;
+using System.Xml.Linq;
+
+namespace xicheji
+{
+    public class ConfigHelper
+    {
+        private const string configFileName = "config.xml";
+        private static Config? _config;
+
+        public static Config GetConfig()
+        {
+            _config ??= LoadConfig();
+            return _config;
+        }
+
+        private static Config LoadConfig()
+        {
+            if (!File.Exists(configFileName))
+            {
+                return new Config();
+            }
+
+            var xdoc = XDocument.Load(configFileName);
+            if (xdoc.Root == null)
+            {
+                return new Config();
+            }
+
+            var config = new Config();
+
+            var platform = xdoc.Root!.Element("Platform");
+            config.Server = platform?.Attribute("Server")?.Value ?? "";
+
+            var device = xdoc.Root!.Element("Device");
+            config.PLCIP = device?.Attribute("IP")?.Value ?? "";
+            config.PLCPort = device?.Attribute("Port")?.Value ?? "";
+            config.PLCType = Enum.Parse<CpuType>(device?.Attribute("Type")?.Value ?? "S7200");
+            config.PLCReceiveInterval = int.Parse(device?.Attribute("ReceiveInterval")?.Value ?? "2");
+
+            var camera = xdoc.Root!.Element("Camera");
+            config.CameraIP = camera?.Attribute("IP")?.Value ?? "";
+            config.CameraPort = camera?.Attribute("Port")?.Value ?? "";
+            config.CameraUserName = camera?.Attribute("UserName")?.Value ?? "";
+            config.CameraPassword = camera?.Attribute("Password")?.Value ?? "";
+
+            var variablesRoot = xdoc.Root!.Element("Variables");
+            if (variablesRoot != null)
+            {
+                config.DBName = variablesRoot.Attribute("DBName")?.Value ?? "DB1";
+                var variables = variablesRoot.Elements("Variable");
+                foreach (XElement item in variables)
+                {
+                    var variable = new Variable();
+                    variable.Name = item.Attribute("Name")?.Value ?? "";
+                    variable.Key = item.Attribute("Key")?.Value ?? "";
+                    variable.Desc = item.Attribute("Desc")?.Value ?? "";
+                    if (string.IsNullOrEmpty(variable.Name) || string.IsNullOrEmpty(variable.Key))
+                    {
+                        continue;
+                    }
+
+                    config.Variables.Add(variable);
+                }
+            }
+
+            return config;
+        }
+
+        public static void SaveConfig(Config config)
+        {
+            _config = config;
+
+
+        }
+
+        public static Variable? FindVariable(string variableName)
+        {
+            var config = GetConfig();
+
+            var variable = config.Variables.Find(x => x.Name == variableName);
+
+            return variable;
+        }
+    }
+
+    public class Config
+    {
+        public string Server { get; set; } = string.Empty;
+        public string PLCIP { get; set; } = string.Empty;
+        public string PLCPort { get; set; } = string.Empty;
+        public CpuType PLCType { get; set; } = CpuType.S7200;
+        public int PLCReceiveInterval { get; set; } = 2;
+        public string CameraIP { get; set; } = string.Empty;
+        public string CameraPort { get; set; } = string.Empty;
+        public string CameraUserName { get; set; } = string.Empty;
+        public string CameraPassword { get; set; } = string.Empty;
+        public string DBName { get; set; } = string.Empty;
+        public List<Variable> Variables { get; set; } = new();
+    }
+
+    public class Variable
+    {
+        public string Name { get; set; } = string.Empty;
+        public string Key { get; set; } = string.Empty;
+        public string Desc { get; set; } = string.Empty;
+    }
+}

+ 90 - 24
MainForm.Designer.cs

@@ -28,33 +28,87 @@
         /// </summary>
         private void InitializeComponent()
         {
-            button1 = new Button();
-            richTextBox1 = new RichTextBox();
+            components = new System.ComponentModel.Container();
+            button4 = new Button();
+            pictureBox1 = new PictureBox();
+            nowTimer = new System.Windows.Forms.Timer(components);
+            uploadTimer = new System.Windows.Forms.Timer(components);
+            receivePLCTimer = new System.Windows.Forms.Timer(components);
+            lblTime = new Label();
+            btnSetting = new Button();
+            btnConnectCamera = new Button();
             button2 = new Button();
             button3 = new Button();
+            ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
             SuspendLayout();
             // 
-            // button1
+            // button4
             // 
-            button1.Location = new Point(126, 47);
-            button1.Name = "button1";
-            button1.Size = new Size(75, 23);
-            button1.TabIndex = 0;
-            button1.Text = "button1";
-            button1.UseVisualStyleBackColor = true;
-            button1.Click += button1_Click;
+            button4.Location = new Point(199, 55);
+            button4.Name = "button4";
+            button4.Size = new Size(75, 23);
+            button4.TabIndex = 5;
+            button4.Text = "button4";
+            button4.UseVisualStyleBackColor = true;
+            button4.Click += button4_Click;
             // 
-            // richTextBox1
+            // pictureBox1
             // 
-            richTextBox1.Location = new Point(462, 28);
-            richTextBox1.Name = "richTextBox1";
-            richTextBox1.Size = new Size(299, 392);
-            richTextBox1.TabIndex = 1;
-            richTextBox1.Text = "";
+            pictureBox1.Location = new Point(690, 131);
+            pictureBox1.Name = "pictureBox1";
+            pictureBox1.Size = new Size(365, 463);
+            pictureBox1.TabIndex = 6;
+            pictureBox1.TabStop = false;
+            // 
+            // nowTimer
+            // 
+            nowTimer.Enabled = true;
+            nowTimer.Interval = 1000;
+            nowTimer.Tick += nowTimer_Tick;
+            // 
+            // uploadTimer
+            // 
+            uploadTimer.Tick += uploadTimer_Tick;
+            // 
+            // receivePLCTimer
+            // 
+            receivePLCTimer.Tick += receivePLCTimer_Tick;
+            // 
+            // lblTime
+            // 
+            lblTime.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+            lblTime.AutoSize = true;
+            lblTime.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
+            lblTime.Location = new Point(871, 25);
+            lblTime.Name = "lblTime";
+            lblTime.Size = new Size(203, 21);
+            lblTime.TabIndex = 7;
+            lblTime.Text = "0000年 0月 00日  00:00:00";
+            // 
+            // btnSetting
+            // 
+            btnSetting.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+            btnSetting.Location = new Point(815, 26);
+            btnSetting.Name = "btnSetting";
+            btnSetting.Size = new Size(50, 23);
+            btnSetting.TabIndex = 8;
+            btnSetting.Text = "配置";
+            btnSetting.UseVisualStyleBackColor = true;
+            btnSetting.Click += btnSetting_Click;
+            // 
+            // btnConnectCamera
+            // 
+            btnConnectCamera.Location = new Point(975, 102);
+            btnConnectCamera.Name = "btnConnectCamera";
+            btnConnectCamera.Size = new Size(80, 23);
+            btnConnectCamera.TabIndex = 0;
+            btnConnectCamera.Text = "重连摄像头";
+            btnConnectCamera.UseVisualStyleBackColor = true;
+            btnConnectCamera.Click += button1_Click;
             // 
             // button2
             // 
-            button2.Location = new Point(126, 76);
+            button2.Location = new Point(23, 55);
             button2.Name = "button2";
             button2.Size = new Size(75, 23);
             button2.TabIndex = 3;
@@ -64,7 +118,7 @@
             // 
             // button3
             // 
-            button3.Location = new Point(115, 125);
+            button3.Location = new Point(104, 55);
             button3.Name = "button3";
             button3.Size = new Size(75, 23);
             button3.TabIndex = 4;
@@ -76,20 +130,32 @@
             // 
             AutoScaleDimensions = new SizeF(7F, 17F);
             AutoScaleMode = AutoScaleMode.Font;
-            ClientSize = new Size(800, 450);
+            ClientSize = new Size(1086, 662);
+            Controls.Add(btnSetting);
+            Controls.Add(lblTime);
+            Controls.Add(pictureBox1);
+            Controls.Add(button4);
             Controls.Add(button3);
             Controls.Add(button2);
-            Controls.Add(richTextBox1);
-            Controls.Add(button1);
+            Controls.Add(btnConnectCamera);
             Name = "MainForm";
+            ShowIcon = false;
             Text = "Form1";
+            Load += MainForm_Load;
+            ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
             ResumeLayout(false);
+            PerformLayout();
         }
 
         #endregion
-
-        private Button button1;
-        private RichTextBox richTextBox1;
+        private Button button4;
+        private PictureBox pictureBox1;
+        private System.Windows.Forms.Timer nowTimer;
+        private System.Windows.Forms.Timer uploadTimer;
+        private System.Windows.Forms.Timer receivePLCTimer;
+        private Label lblTime;
+        private Button btnSetting;
+        private Button btnConnectCamera;
         private Button button2;
         private Button button3;
     }

+ 102 - 51
MainForm.cs

@@ -1,4 +1,6 @@
+using Hik.Api;
 using S7.Net;
+using System.Threading.Channels;
 using System.Windows.Forms;
 
 namespace xicheji
@@ -6,19 +8,29 @@ namespace xicheji
     public partial class MainForm : Form
     {
         private Plc? plc = null;
+        private HikApi? hikApi = null;
         public MainForm()
         {
             InitializeComponent();
         }
 
+        private void MainForm_Load(object sender, EventArgs e)
+        {
+            try
+            {
+
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message + ex.StackTrace);
+            }
+        }
+
         private void button1_Click(object sender, EventArgs e)
         {
             try
             {
-                plc = new Plc(CpuType.S7200, "127.0.0.1", 1502, 0, 1);
-                plc.Open();
-                richTextBox1.AppendText("���ӳɹ���\n\n");
-                richTextBox1.ScrollToCaret();
+                ConnectCamera();
             }
             catch (Exception ex)
             {
@@ -28,51 +40,24 @@ namespace xicheji
 
         private void button2_Click(object sender, EventArgs e)
         {
-            if (plc == null || !plc.IsConnected) return;
-            //plc��������c#���� bool => Bit
-            //Byte => byte
-            //word => ushort
-            //DWord => uint
-            //Int => short
-            //DInt => int
-            //Real => float
-            //LReal => double
-            //String => string
-            //DateTimeLong=>datetime
-            //s7wstring=>string
-
-            //PLCAddress.Parse
-            //1��DB100.DBB0 һ���ֽ���8��λ���ֱ�Ϊ0-- - 7������0.0----0.7��8λ   --Byte,byte
-            //2��DB100.DBW0һ�����������ֽڣ��ֱ�Ϊ DB100.DBB0�� DB100.DBB1       --Word,ushort
-            //3��DB100.DBD0һ��˫���������֣��ֱ�Ϊ DB100.DBW0�� DB100.DBW2       --DWord,uint
-            //4��DB100.DBX0.0 һ��λ��������С��λ     --Bit,bool
+            if (plc == null || !plc.IsConnected)
+            {
+                Log("连接成功!");
+                return;
+            }
+
+        }
 
+        private void button3_Click(object sender, EventArgs e)
+        {
+            plc?.Close();
+        }
+
+        private void button4_Click(object sender, EventArgs e)
+        {
             try
             {
 
-                var db = 1;
-                var start = plc.Read(DataType.DataBlock, db, 0, VarType.Byte, 1);
-                Log("start:", start);
-                var start2 = plc.Read("DB1.DBB0");
-                Log("start2:", start2);
-                var length = plc.Read(DataType.DataBlock, db, 1, VarType.Byte, 1);
-                Log("length:", length);
-                var length2 = plc.Read("DB1.DBB1");
-                Log("length2:", length2);
-                var mac = plc.Read(DataType.DataBlock, db, 2, VarType.Byte, 6);
-                Log("mac:", string.Join(":", (mac as byte[]).ToList().ConvertAll(a => "0x" + a.ToString("X2"))));
-                var val = plc.Read(DataType.DataBlock, db, 10, VarType.Bit, 1, 1);
-                Log("DB1.DBX10.1��ֵΪ:", val);
-                val = plc.Read(DataType.DataBlock, db, 10, VarType.Bit, 1, 2);
-                Log("DB1.DBX10.2��ֵΪ:", val);
-                val = plc.Read(DataType.DataBlock, db, 20, VarType.DWord, 1);
-                Log("��ȡDB1.DBX20 DWORD��ϴ������ֵΪ:", val);
-
-                var bbb = (bool)plc.Read("DB1.DBX10.1");
-                Log("bbb:", bbb);
-                var ccc = plc.Read("DB1.DBD20");
-                Log("ccc:", ccc);
-                //DWord.FromByteArray
             }
             catch (Exception ex)
             {
@@ -80,16 +65,82 @@ namespace xicheji
             }
         }
 
-        private void Log(params object[] msgs)
+        private void nowTimer_Tick(object sender, EventArgs e)
         {
-            richTextBox1.AppendText(string.Join(" ", msgs));
-            richTextBox1.AppendText("\n\n");
-            richTextBox1.ScrollToCaret();
+            try
+            {
+                var now = DateTime.Now;
+                lblTime.Text = $"{now.Year}年 {now.Month}月 {now.Day}日  {now.Hour}:{now.Minute}:{now.Second}";
+            }
+            catch { }
         }
 
-        private void button3_Click(object sender, EventArgs e)
+        private void receivePLCTimer_Tick(object sender, EventArgs e)
         {
-            plc?.Close();
+            try
+            {
+                if (plc == null || !plc.IsConnected)
+                {
+                    receivePLCTimer.Enabled = false;
+                    return;
+                }
+            }
+            catch { }
+        }
+
+        private void uploadTimer_Tick(object sender, EventArgs e)
+        {
+
+        }
+
+        private void btnSetting_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                var settingForm = new SettingForm();
+                if (settingForm.ShowDialog() == DialogResult.OK)
+                {
+                    ConnectPLC();
+                    ConnectCamera();
+
+                    receivePLCTimer.Enabled = true;
+                    uploadTimer.Enabled = true;
+                }
+            }
+            catch { }
+        }
+
+        private void ConnectPLC()
+        {
+            plc = new Plc(CpuType.S7200, "127.0.0.1", 1502, 0, 1);
+            plc.Open();
+
+            if (plc == null || !plc.IsConnected)
+            {
+                MessageBox.Show("PLC连接失败!");
+                return;
+            }
+        }
+
+        private void ConnectCamera()
+        {
+            hikApi = HikApi.Login("192.168.1.64", 8000, "admin", "password") as HikApi;
+
+            if (hikApi == null || !hikApi.Connected)
+            {
+                MessageBox.Show("摄像头连接失败!");
+                return;
+            }
+
+            hikApi.PlaybackService.StartPlayBack(hikApi.DefaultIpChannel, pictureBox1.Handle);
+        }
+
+        private void Log(params object[] msgs)
+        {
+            //richTextBox1.AppendText(string.Join(" ", msgs));
+            //richTextBox1.AppendText("\n\n");
+            //richTextBox1.ScrollToCaret();
+            Console.WriteLine(string.Join(" ", msgs));
         }
     }
 }

+ 9 - 0
MainForm.resx

@@ -117,4 +117,13 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
+  <metadata name="nowTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <metadata name="uploadTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>286, 24</value>
+  </metadata>
+  <metadata name="receivePLCTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>136, 20</value>
+  </metadata>
 </root>

+ 3 - 0
Program.cs

@@ -1,3 +1,5 @@
+using Hik.Api;
+
 namespace xicheji
 {
     internal static class Program
@@ -11,6 +13,7 @@ namespace xicheji
             // To customize application configuration such as set high DPI settings or default font,
             // see https://aka.ms/applicationconfiguration.
             ApplicationConfiguration.Initialize();
+            HikApi.Initialize();
             Application.Run(new MainForm());
         }
     }

+ 321 - 4
SettingForm.Designer.cs

@@ -28,12 +28,329 @@
         /// </summary>
         private void InitializeComponent()
         {
-            this.components = new System.ComponentModel.Container();
-            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(800, 450);
-            this.Text = "SettingForm";
+            btnOK = new Button();
+            btnCancel = new Button();
+            groupBox1 = new GroupBox();
+            txtServer = new TextBox();
+            label1 = new Label();
+            groupBox2 = new GroupBox();
+            label6 = new Label();
+            nudInterval = new NumericUpDown();
+            cboPLCType = new ComboBox();
+            label4 = new Label();
+            label5 = new Label();
+            txtPLCPort = new TextBox();
+            label3 = new Label();
+            txtPLCIP = new TextBox();
+            label2 = new Label();
+            groupBox3 = new GroupBox();
+            label7 = new Label();
+            label8 = new Label();
+            txtPassword = new TextBox();
+            txtUserName = new TextBox();
+            txtCameraPort = new TextBox();
+            label10 = new Label();
+            txtCameraIP = new TextBox();
+            label11 = new Label();
+            groupBox1.SuspendLayout();
+            groupBox2.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)nudInterval).BeginInit();
+            groupBox3.SuspendLayout();
+            SuspendLayout();
+            // 
+            // btnOK
+            // 
+            btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+            btnOK.Location = new Point(276, 486);
+            btnOK.Name = "btnOK";
+            btnOK.Size = new Size(75, 23);
+            btnOK.TabIndex = 0;
+            btnOK.Text = "确定";
+            btnOK.UseVisualStyleBackColor = true;
+            btnOK.Click += btnOK_Click;
+            // 
+            // btnCancel
+            // 
+            btnCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+            btnCancel.Location = new Point(357, 486);
+            btnCancel.Name = "btnCancel";
+            btnCancel.Size = new Size(75, 23);
+            btnCancel.TabIndex = 1;
+            btnCancel.Text = "取消";
+            btnCancel.UseVisualStyleBackColor = true;
+            btnCancel.Click += btnCancel_Click;
+            // 
+            // groupBox1
+            // 
+            groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            groupBox1.Controls.Add(txtServer);
+            groupBox1.Controls.Add(label1);
+            groupBox1.Location = new Point(12, 12);
+            groupBox1.Name = "groupBox1";
+            groupBox1.Size = new Size(420, 64);
+            groupBox1.TabIndex = 2;
+            groupBox1.TabStop = false;
+            groupBox1.Text = "平台";
+            // 
+            // txtServer
+            // 
+            txtServer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtServer.Location = new Point(90, 22);
+            txtServer.Name = "txtServer";
+            txtServer.Size = new Size(303, 23);
+            txtServer.TabIndex = 1;
+            // 
+            // label1
+            // 
+            label1.AutoSize = true;
+            label1.Location = new Point(25, 25);
+            label1.Name = "label1";
+            label1.Size = new Size(59, 17);
+            label1.TabIndex = 0;
+            label1.Text = "服务地址:";
+            // 
+            // groupBox2
+            // 
+            groupBox2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            groupBox2.Controls.Add(label6);
+            groupBox2.Controls.Add(nudInterval);
+            groupBox2.Controls.Add(cboPLCType);
+            groupBox2.Controls.Add(label4);
+            groupBox2.Controls.Add(label5);
+            groupBox2.Controls.Add(txtPLCPort);
+            groupBox2.Controls.Add(label3);
+            groupBox2.Controls.Add(txtPLCIP);
+            groupBox2.Controls.Add(label2);
+            groupBox2.Location = new Point(12, 92);
+            groupBox2.Name = "groupBox2";
+            groupBox2.Size = new Size(420, 182);
+            groupBox2.TabIndex = 2;
+            groupBox2.TabStop = false;
+            groupBox2.Text = "PLC";
+            // 
+            // label6
+            // 
+            label6.AutoSize = true;
+            label6.Location = new Point(131, 148);
+            label6.Name = "label6";
+            label6.Size = new Size(20, 17);
+            label6.TabIndex = 4;
+            label6.Text = "秒";
+            // 
+            // nudInterval
+            // 
+            nudInterval.Location = new Point(90, 145);
+            nudInterval.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
+            nudInterval.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
+            nudInterval.Name = "nudInterval";
+            nudInterval.Size = new Size(40, 23);
+            nudInterval.TabIndex = 3;
+            nudInterval.TextAlign = HorizontalAlignment.Right;
+            nudInterval.Value = new decimal(new int[] { 2, 0, 0, 0 });
+            // 
+            // cboPLCType
+            // 
+            cboPLCType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            cboPLCType.FormattingEnabled = true;
+            cboPLCType.Location = new Point(90, 104);
+            cboPLCType.Name = "cboPLCType";
+            cboPLCType.Size = new Size(303, 25);
+            cboPLCType.TabIndex = 2;
+            // 
+            // label4
+            // 
+            label4.AutoSize = true;
+            label4.Location = new Point(25, 107);
+            label4.Name = "label4";
+            label4.Size = new Size(35, 17);
+            label4.TabIndex = 0;
+            label4.Text = "类型:";
+            // 
+            // label5
+            // 
+            label5.AutoSize = true;
+            label5.Location = new Point(25, 148);
+            label5.Name = "label5";
+            label5.Size = new Size(59, 17);
+            label5.TabIndex = 0;
+            label5.Text = "接受频率:";
+            // 
+            // txtPLCPort
+            // 
+            txtPLCPort.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtPLCPort.Location = new Point(90, 63);
+            txtPLCPort.Name = "txtPLCPort";
+            txtPLCPort.Size = new Size(303, 23);
+            txtPLCPort.TabIndex = 1;
+            // 
+            // label3
+            // 
+            label3.AutoSize = true;
+            label3.Location = new Point(25, 66);
+            label3.Name = "label3";
+            label3.Size = new Size(47, 17);
+            label3.TabIndex = 0;
+            label3.Text = "端口号:";
+            // 
+            // txtPLCIP
+            // 
+            txtPLCIP.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtPLCIP.Location = new Point(90, 22);
+            txtPLCIP.Name = "txtPLCIP";
+            txtPLCIP.Size = new Size(303, 23);
+            txtPLCIP.TabIndex = 1;
+            // 
+            // label2
+            // 
+            label2.AutoSize = true;
+            label2.Location = new Point(25, 25);
+            label2.Name = "label2";
+            label2.Size = new Size(22, 17);
+            label2.TabIndex = 0;
+            label2.Text = "IP:";
+            // 
+            // groupBox3
+            // 
+            groupBox3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            groupBox3.Controls.Add(label7);
+            groupBox3.Controls.Add(label8);
+            groupBox3.Controls.Add(txtPassword);
+            groupBox3.Controls.Add(txtUserName);
+            groupBox3.Controls.Add(txtCameraPort);
+            groupBox3.Controls.Add(label10);
+            groupBox3.Controls.Add(txtCameraIP);
+            groupBox3.Controls.Add(label11);
+            groupBox3.Location = new Point(12, 291);
+            groupBox3.Name = "groupBox3";
+            groupBox3.Size = new Size(420, 182);
+            groupBox3.TabIndex = 2;
+            groupBox3.TabStop = false;
+            groupBox3.Text = "摄像头";
+            // 
+            // label7
+            // 
+            label7.AutoSize = true;
+            label7.Location = new Point(25, 145);
+            label7.Name = "label7";
+            label7.Size = new Size(35, 17);
+            label7.TabIndex = 0;
+            label7.Text = "密码:";
+            // 
+            // label8
+            // 
+            label8.AutoSize = true;
+            label8.Location = new Point(25, 104);
+            label8.Name = "label8";
+            label8.Size = new Size(47, 17);
+            label8.TabIndex = 0;
+            label8.Text = "用户名:";
+            // 
+            // txtPassword
+            // 
+            txtPassword.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtPassword.Location = new Point(90, 142);
+            txtPassword.Name = "txtPassword";
+            txtPassword.Size = new Size(303, 23);
+            txtPassword.TabIndex = 1;
+            // 
+            // txtUserName
+            // 
+            txtUserName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtUserName.Location = new Point(90, 102);
+            txtUserName.Name = "txtUserName";
+            txtUserName.Size = new Size(303, 23);
+            txtUserName.TabIndex = 1;
+            // 
+            // txtCameraPort
+            // 
+            txtCameraPort.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtCameraPort.Location = new Point(90, 62);
+            txtCameraPort.Name = "txtCameraPort";
+            txtCameraPort.Size = new Size(303, 23);
+            txtCameraPort.TabIndex = 1;
+            // 
+            // label10
+            // 
+            label10.AutoSize = true;
+            label10.Location = new Point(25, 65);
+            label10.Name = "label10";
+            label10.Size = new Size(47, 17);
+            label10.TabIndex = 0;
+            label10.Text = "端口号:";
+            // 
+            // txtCameraIP
+            // 
+            txtCameraIP.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtCameraIP.Location = new Point(90, 22);
+            txtCameraIP.Name = "txtCameraIP";
+            txtCameraIP.Size = new Size(303, 23);
+            txtCameraIP.TabIndex = 1;
+            // 
+            // label11
+            // 
+            label11.AutoSize = true;
+            label11.Location = new Point(25, 25);
+            label11.Name = "label11";
+            label11.Size = new Size(22, 17);
+            label11.TabIndex = 0;
+            label11.Text = "IP:";
+            // 
+            // SettingForm
+            // 
+            AutoScaleDimensions = new SizeF(7F, 17F);
+            AutoScaleMode = AutoScaleMode.Font;
+            ClientSize = new Size(444, 521);
+            Controls.Add(groupBox3);
+            Controls.Add(groupBox2);
+            Controls.Add(groupBox1);
+            Controls.Add(btnCancel);
+            Controls.Add(btnOK);
+            FormBorderStyle = FormBorderStyle.FixedSingle;
+            MaximizeBox = false;
+            MinimizeBox = false;
+            MinimumSize = new Size(460, 560);
+            Name = "SettingForm";
+            ShowIcon = false;
+            StartPosition = FormStartPosition.CenterParent;
+            Text = "配置";
+            Load += SettingForm_Load;
+            groupBox1.ResumeLayout(false);
+            groupBox1.PerformLayout();
+            groupBox2.ResumeLayout(false);
+            groupBox2.PerformLayout();
+            ((System.ComponentModel.ISupportInitialize)nudInterval).EndInit();
+            groupBox3.ResumeLayout(false);
+            groupBox3.PerformLayout();
+            ResumeLayout(false);
         }
 
         #endregion
+
+        private Button btnOK;
+        private Button btnCancel;
+        private GroupBox groupBox1;
+        private TextBox txtServer;
+        private Label label1;
+        private GroupBox groupBox2;
+        private TextBox txtPLCIP;
+        private Label label2;
+        private ComboBox cboPLCType;
+        private Label label4;
+        private TextBox txtPLCPort;
+        private Label label3;
+        private Label label6;
+        private NumericUpDown nudInterval;
+        private Label label5;
+        private GroupBox groupBox3;
+        private Label label8;
+        private Label label9;
+        private TextBox txtCameraIP;
+        private Label label10;
+        private TextBox txtCameraPort;
+        private Label label11;
+        private TextBox txtUserName;
+        private Label label7;
+        private TextBox txtPassword;
+        private TextBox textBox3;
     }
 }

+ 59 - 1
SettingForm.cs

@@ -1,4 +1,5 @@
-using System;
+using S7.Net;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
@@ -16,5 +17,62 @@ namespace xicheji
         {
             InitializeComponent();
         }
+
+        private void SettingForm_Load(object sender, EventArgs e)
+        {
+            try
+            {
+                var names = Enum.GetNames<CpuType>();
+                cboPLCType.Items.Clear();
+                cboPLCType.Items.AddRange(names);
+
+
+                var config = ConfigHelper.GetConfig();
+
+                txtServer.Text = config.Server;
+                txtPLCIP.Text = config.PLCIP;
+                txtPLCPort.Text = config.PLCPort;
+                cboPLCType.SelectedItem = Enum.GetName<CpuType>(config.PLCType);
+                nudInterval.Value = config.PLCReceiveInterval;
+                txtCameraIP.Text = config.CameraIP;
+                txtCameraPort.Text = config.CameraPort;
+                txtUserName.Text = config.CameraUserName;
+                txtPassword.Text = config.CameraPassword;
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message + ex.StackTrace);
+            }
+        }
+
+        private void btnOK_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                var config = ConfigHelper.GetConfig();
+
+                config.Server = txtServer.Text;
+                config.PLCIP = txtPLCIP.Text;
+                config.PLCPort = txtPLCPort.Text;
+                config.PLCType = Enum.Parse<CpuType>(cboPLCType.Text);
+                config.PLCReceiveInterval = int.Parse(nudInterval.Value.ToString());
+                config.CameraIP = txtCameraIP.Text;
+                config.CameraPort = txtCameraPort.Text;
+                config.CameraUserName = txtUserName.Text;
+                config.CameraPassword = txtPassword.Text;
+
+                ConfigHelper.SaveConfig(config);
+                this.DialogResult = DialogResult.OK;
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message + ex.StackTrace);
+            }
+        }
+
+        private void btnCancel_Click(object sender, EventArgs e)
+        {
+            this.DialogResult = DialogResult.Cancel;
+        }
     }
 }

+ 25 - 25
SettingForm.resx

@@ -1,17 +1,17 @@
 <?xml version="1.0" encoding="utf-8"?>
 <root>
-  <!-- 
+  <!--
     Microsoft ResX Schema 
-    
+
     Version 2.0
-    
-    The primary goals of this format is to allow a simple XML format 
-    that is mostly human readable. The generation and parsing of the 
-    various data types are done through the TypeConverter classes 
+
+    The primary goals of this format is to allow a simple XML format
+    that is mostly human readable. The generation and parsing of the
+    various data types are done through the TypeConverter classes
     associated with the data types.
-    
+
     Example:
-    
+
     ... ado.net/XML headers & schema ...
     <resheader name="resmimetype">text/microsoft-resx</resheader>
     <resheader name="version">2.0</resheader>
@@ -26,36 +26,36 @@
         <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
         <comment>This is a comment</comment>
     </data>
-                
-    There are any number of "resheader" rows that contain simple 
+
+    There are any number of "resheader" rows that contain simple
     name/value pairs.
-    
-    Each data row contains a name, and value. The row also contains a 
-    type or mimetype. Type corresponds to a .NET class that support 
-    text/value conversion through the TypeConverter architecture. 
-    Classes that don't support this are serialized and stored with the 
+
+    Each data row contains a name, and value. The row also contains a
+    type or mimetype. Type corresponds to a .NET class that support
+    text/value conversion through the TypeConverter architecture.
+    Classes that don't support this are serialized and stored with the
     mimetype set.
-    
-    The mimetype is used for serialized objects, and tells the 
-    ResXResourceReader how to depersist the object. This is currently not 
+
+    The mimetype is used for serialized objects, and tells the
+    ResXResourceReader how to depersist the object. This is currently not
     extensible. For a given mimetype the value must be set accordingly:
-    
-    Note - application/x-microsoft.net.object.binary.base64 is the format 
-    that the ResXResourceWriter will generate, however the reader can 
+
+    Note - application/x-microsoft.net.object.binary.base64 is the format
+    that the ResXResourceWriter will generate, however the reader can
     read any of the formats listed below.
-    
+
     mimetype: application/x-microsoft.net.object.binary.base64
-    value   : The object must be serialized with 
+    value   : The object must be serialized with
             : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
             : and then encoded with base64 encoding.
     
     mimetype: application/x-microsoft.net.object.soap.base64
-    value   : The object must be serialized with 
+    value   : The object must be serialized with
             : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
             : and then encoded with base64 encoding.
 
     mimetype: application/x-microsoft.net.object.bytearray.base64
-    value   : The object must be serialized into a byte array 
+    value   : The object must be serialized into a byte array
             : using a System.ComponentModel.TypeConverter
             : and then encoded with base64 encoding.
     -->

+ 2 - 1
config.xml

@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <Config>
-	<Platform Server="IP+Port+BasePath"  UploadInterval="2"/>
+	<Platform Server="http[s]://+IP+Port+BasePath"  UploadInterval="2"/>
 	<!--Type: S7200,Logo0BA8,S7200Smart,S7300,S7400,S71200,S71500-->
 	<Device IP="127.0.0.1" Port="1502" Type="S7200" ReceiveInterval="2" MacVariable="" Gateway="" Netmask="" />
+	<Camera IP="127.0.0.1" Port="1502" UserName="user" Password="Wayclouds2024" />
 	<Variables DBName="DB1">
 		<Variable Name="FF" Key="DBX0"/>
 		<Variable Name="数据长度" Key="DBX1"/>

+ 6 - 0
xicheji.csproj

@@ -15,4 +15,10 @@
     <PackageReference Include="S7netplus" Version="0.20.0" />
   </ItemGroup>
 
+  <ItemGroup>
+    <None Update="config.xml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
 </Project>