Browse Source

PLC连接

Linsk 3 months ago
parent
commit
1d6d28cccc

+ 34 - 10
Scada/FormMain.Designer.cs

@@ -58,7 +58,7 @@
             uiLabel16 = new Sunny.UI.UILabel();
             uiLabel16 = new Sunny.UI.UILabel();
             uiLabel17 = new Sunny.UI.UILabel();
             uiLabel17 = new Sunny.UI.UILabel();
             uiLabel18 = new Sunny.UI.UILabel();
             uiLabel18 = new Sunny.UI.UILabel();
-            uiLedBulb2 = new Sunny.UI.UILedBulb();
+            led_PlcState = new Sunny.UI.UILedBulb();
             uiLabel19 = new Sunny.UI.UILabel();
             uiLabel19 = new Sunny.UI.UILabel();
             uiLabel20 = new Sunny.UI.UILabel();
             uiLabel20 = new Sunny.UI.UILabel();
             uiLabel21 = new Sunny.UI.UILabel();
             uiLabel21 = new Sunny.UI.UILabel();
@@ -77,7 +77,7 @@
             Footer.Controls.Add(uiLabel21);
             Footer.Controls.Add(uiLabel21);
             Footer.Controls.Add(uiLabel20);
             Footer.Controls.Add(uiLabel20);
             Footer.Controls.Add(uiLabel19);
             Footer.Controls.Add(uiLabel19);
-            Footer.Controls.Add(uiLedBulb2);
+            Footer.Controls.Add(led_PlcState);
             Footer.Controls.Add(uiLabel18);
             Footer.Controls.Add(uiLabel18);
             Footer.Controls.Add(uiLabel17);
             Footer.Controls.Add(uiLabel17);
             Footer.Controls.Add(uiLabel16);
             Footer.Controls.Add(uiLabel16);
@@ -136,6 +136,8 @@
             uiPanel1.TabIndex = 0;
             uiPanel1.TabIndex = 0;
             uiPanel1.Text = null;
             uiPanel1.Text = null;
             uiPanel1.TextAlignment = ContentAlignment.MiddleCenter;
             uiPanel1.TextAlignment = ContentAlignment.MiddleCenter;
+            uiPanel1.MouseDown += Panel_MouseDown;
+            uiPanel1.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiSymbolLabel2
             // uiSymbolLabel2
             // 
             // 
@@ -173,6 +175,8 @@
             uiLabel8.Size = new Size(215, 33);
             uiLabel8.Size = new Size(215, 33);
             uiLabel8.TabIndex = 9;
             uiLabel8.TabIndex = 9;
             uiLabel8.Text = "2024-10-12 23:05:23";
             uiLabel8.Text = "2024-10-12 23:05:23";
+            uiLabel8.MouseDown += Panel_MouseDown;
+            uiLabel8.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiLabel7
             // uiLabel7
             // 
             // 
@@ -184,6 +188,8 @@
             uiLabel7.Size = new Size(44, 27);
             uiLabel7.Size = new Size(44, 27);
             uiLabel7.TabIndex = 8;
             uiLabel7.TabIndex = 8;
             uiLabel7.Text = "60%";
             uiLabel7.Text = "60%";
+            uiLabel7.MouseDown += Panel_MouseDown;
+            uiLabel7.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiLabel6
             // uiLabel6
             // 
             // 
@@ -195,6 +201,8 @@
             uiLabel6.Size = new Size(44, 27);
             uiLabel6.Size = new Size(44, 27);
             uiLabel6.TabIndex = 7;
             uiLabel6.TabIndex = 7;
             uiLabel6.Text = "25℃";
             uiLabel6.Text = "25℃";
+            uiLabel6.MouseDown += Panel_MouseDown;
+            uiLabel6.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiLabel5
             // uiLabel5
             // 
             // 
@@ -209,6 +217,8 @@
             uiLabel5.TabIndex = 6;
             uiLabel5.TabIndex = 6;
             uiLabel5.Text = "厂房湿度";
             uiLabel5.Text = "厂房湿度";
             uiLabel5.TextAlign = ContentAlignment.MiddleRight;
             uiLabel5.TextAlign = ContentAlignment.MiddleRight;
+            uiLabel5.MouseDown += Panel_MouseDown;
+            uiLabel5.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiLabel4
             // uiLabel4
             // 
             // 
@@ -223,6 +233,8 @@
             uiLabel4.TabIndex = 5;
             uiLabel4.TabIndex = 5;
             uiLabel4.Text = "厂房温度";
             uiLabel4.Text = "厂房温度";
             uiLabel4.TextAlign = ContentAlignment.MiddleRight;
             uiLabel4.TextAlign = ContentAlignment.MiddleRight;
+            uiLabel4.MouseDown += Panel_MouseDown;
+            uiLabel4.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiScrollingText1
             // uiScrollingText1
             // 
             // 
@@ -234,6 +246,8 @@
             uiScrollingText1.Size = new Size(283, 48);
             uiScrollingText1.Size = new Size(283, 48);
             uiScrollingText1.TabIndex = 4;
             uiScrollingText1.TabIndex = 4;
             uiScrollingText1.Text = "系统正常";
             uiScrollingText1.Text = "系统正常";
+            uiScrollingText1.MouseDown += Panel_MouseDown;
+            uiScrollingText1.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiLabel3
             // uiLabel3
             // 
             // 
@@ -245,6 +259,8 @@
             uiLabel3.Size = new Size(103, 39);
             uiLabel3.Size = new Size(103, 39);
             uiLabel3.TabIndex = 1;
             uiLabel3.TabIndex = 1;
             uiLabel3.Text = "工程师";
             uiLabel3.Text = "工程师";
+            uiLabel3.MouseDown += Panel_MouseDown;
+            uiLabel3.MouseMove += Panel_MouseMove;
             // 
             // 
             // pictureBox2
             // pictureBox2
             // 
             // 
@@ -255,6 +271,8 @@
             pictureBox2.Size = new Size(65, 65);
             pictureBox2.Size = new Size(65, 65);
             pictureBox2.TabIndex = 3;
             pictureBox2.TabIndex = 3;
             pictureBox2.TabStop = false;
             pictureBox2.TabStop = false;
+            pictureBox2.MouseDown += Panel_MouseDown;
+            pictureBox2.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiLabel2
             // uiLabel2
             // 
             // 
@@ -266,6 +284,8 @@
             uiLabel2.Size = new Size(299, 26);
             uiLabel2.Size = new Size(299, 26);
             uiLabel2.TabIndex = 2;
             uiLabel2.TabIndex = 2;
             uiLabel2.Text = "Spary Process SCADA System";
             uiLabel2.Text = "Spary Process SCADA System";
+            uiLabel2.MouseDown += Panel_MouseDown;
+            uiLabel2.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiLabel1
             // uiLabel1
             // 
             // 
@@ -277,6 +297,8 @@
             uiLabel1.Size = new Size(335, 45);
             uiLabel1.Size = new Size(335, 45);
             uiLabel1.TabIndex = 1;
             uiLabel1.TabIndex = 1;
             uiLabel1.Text = "喷涂工艺SCADA系统";
             uiLabel1.Text = "喷涂工艺SCADA系统";
+            uiLabel1.MouseDown += Panel_MouseDown;
+            uiLabel1.MouseMove += Panel_MouseMove;
             // 
             // 
             // pictureBox1
             // pictureBox1
             // 
             // 
@@ -287,6 +309,8 @@
             pictureBox1.Size = new Size(65, 66);
             pictureBox1.Size = new Size(65, 66);
             pictureBox1.TabIndex = 0;
             pictureBox1.TabIndex = 0;
             pictureBox1.TabStop = false;
             pictureBox1.TabStop = false;
+            pictureBox1.MouseDown += Panel_MouseDown;
+            pictureBox1.MouseMove += Panel_MouseMove;
             // 
             // 
             // uiLabel9
             // uiLabel9
             // 
             // 
@@ -479,14 +503,14 @@
             uiLabel18.Text = "软件版本";
             uiLabel18.Text = "软件版本";
             uiLabel18.TextAlign = ContentAlignment.MiddleRight;
             uiLabel18.TextAlign = ContentAlignment.MiddleRight;
             // 
             // 
-            // uiLedBulb2
+            // led_PlcState
             // 
             // 
-            uiLedBulb2.BackColor = Color.Transparent;
-            uiLedBulb2.Location = new Point(174, 11);
-            uiLedBulb2.Name = "uiLedBulb2";
-            uiLedBulb2.Size = new Size(40, 40);
-            uiLedBulb2.TabIndex = 5;
-            uiLedBulb2.Text = "uiLedBulb2";
+            led_PlcState.BackColor = Color.Transparent;
+            led_PlcState.Location = new Point(174, 11);
+            led_PlcState.Name = "led_PlcState";
+            led_PlcState.Size = new Size(40, 40);
+            led_PlcState.TabIndex = 5;
+            led_PlcState.Text = "uiLedBulb2";
             // 
             // 
             // uiLabel19
             // uiLabel19
             // 
             // 
@@ -581,7 +605,7 @@
         private Sunny.UI.UILabel uiLabel21;
         private Sunny.UI.UILabel uiLabel21;
         private Sunny.UI.UILabel uiLabel20;
         private Sunny.UI.UILabel uiLabel20;
         private Sunny.UI.UILabel uiLabel19;
         private Sunny.UI.UILabel uiLabel19;
-        private Sunny.UI.UILedBulb uiLedBulb2;
+        private Sunny.UI.UILedBulb led_PlcState;
         private Sunny.UI.UILabel uiLabel18;
         private Sunny.UI.UILabel uiLabel18;
         private Sunny.UI.UILabel uiLabel17;
         private Sunny.UI.UILabel uiLabel17;
         private Sunny.UI.UILabel uiLabel16;
         private Sunny.UI.UILabel uiLabel16;

+ 125 - 7
Scada/FormMain.cs

@@ -2,7 +2,9 @@ using Helper;
 using HZY.Framework.DependencyInjection;
 using HZY.Framework.DependencyInjection;
 using IoTClient.Clients.PLC;
 using IoTClient.Clients.PLC;
 using IoTClient.Common.Enums;
 using IoTClient.Common.Enums;
+using IoTClient.Enums;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
 using MiniExcelLibs;
 using MiniExcelLibs;
 using Model;
 using Model;
 using Scada.Page;
 using Scada.Page;
@@ -13,10 +15,13 @@ namespace Scada
     public partial class FormMain : UIHeaderAsideMainFooterFrame,IScopedSelfDependency
     public partial class FormMain : UIHeaderAsideMainFooterFrame,IScopedSelfDependency
     {
     {
         private bool plcIsConnected;
         private bool plcIsConnected;
+        private readonly ILogger<FormMain> _logger;
+        private Point mPoint;
+        private CancellationTokenSource cts = new CancellationTokenSource();
 
 
-        public FormMain()
+        public FormMain(ILogger<FormMain> logger)
         {
         {
-            
+            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
             InitializeComponent();
             InitializeComponent();
             InitAsideUI();
             InitAsideUI();
             InitHeaderUI();
             InitHeaderUI();
@@ -28,8 +33,8 @@ namespace Scada
 
 
         private void InitConfig()
         private void InitConfig()
         {
         {
-            //读取PLC配置
-            Globals.IpAddress = Globals.IniFile.ReadString("PLC参数", "IP", "192.168.1.180");
+            //读取PLC配置 192.168.1.180  127.0.0.1
+            Globals.IpAddress = Globals.IniFile.ReadString("PLC参数", "IP", "127.0.0.1");
             Globals.Port = Globals.IniFile.ReadInt("PLC参数", "Port", 102);
             Globals.Port = Globals.IniFile.ReadInt("PLC参数", "Port", 102);
             Globals.CpuType = Enum.Parse<SiemensVersion>(Globals.IniFile.ReadString("PLC参数", "CpuType", SiemensVersion.S7_1200.ToString()));
             Globals.CpuType = Enum.Parse<SiemensVersion>(Globals.IniFile.ReadString("PLC参数", "CpuType", SiemensVersion.S7_1200.ToString()));
             Globals.Slot = Globals.IniFile.ReadByte("PLC参数", "Slot", 0);
             Globals.Slot = Globals.IniFile.ReadByte("PLC参数", "Slot", 0);
@@ -38,17 +43,117 @@ namespace Scada
             Globals.ConnectTimeOut = Globals.IniFile.ReadInt("PLC参数", "ConnectTimeOut", 3000);
             Globals.ConnectTimeOut = Globals.IniFile.ReadInt("PLC参数", "ConnectTimeOut", 3000);
             Globals.ReadTimeInterval = Globals.IniFile.ReadInt("PLC参数", "ReadTimeInterval", 300);
             Globals.ReadTimeInterval = Globals.IniFile.ReadInt("PLC参数", "ReadTimeInterval", 300);
             Globals.ReConnectTimeInterval = Globals.IniFile.ReadInt("PLC参数", "ReConnectTimeInterval", 3000);
             Globals.ReConnectTimeInterval = Globals.IniFile.ReadInt("PLC参数", "ReConnectTimeInterval", 3000);
-        }
 
 
+            //PLC变量表路径
+            Globals.PlcVarConfigPath = Globals.IniFile.ReadString("PLC参数", "变量表地址", Path.Combine(Application.StartupPath, "PLC_Var_Config.xlsx"));
+
+            //删除文件夹路径
+            Globals.DelFilePath = Globals.IniFile.ReadString("系统参数", "删除文件夹路径", Path.Combine(Application.StartupPath, "Logs"));
+            //保存天数
+            Globals.SaveDay = Globals.IniFile.ReadString("系统参数", "保存天数", "30");
+
+            //试用时长
+            Globals.SYTime = Globals.IniFile.ReadInt("软件参数", "试用时间", 100);
+
+            //软件版本
+            Globals.SoftwareVersion = Globals.IniFile.ReadString("软件参数", "软件版本", "V1.0");
+
+            _logger.LogInformation("读取配置文件成功");
+        }
         private void InitPlcClient()
         private void InitPlcClient()
         {
         {
-            Globals.PlcVarConfigPath = Globals.IniFile.ReadString("PLC参数", "变量表地址",Application.StartupPath+"\\config.ini");
             var plcVarList = MiniExcel.Query<PLCVarConfigModel>(Globals.PlcVarConfigPath).ToList();
             var plcVarList = MiniExcel.Query<PLCVarConfigModel>(Globals.PlcVarConfigPath).ToList();
 
 
             Globals.SiemensClient = new SiemensClient(Globals.CpuType, Globals.IpAddress, Globals.Port, Globals.Slot, Globals.Rack, Globals.ConnectTimeOut);
             Globals.SiemensClient = new SiemensClient(Globals.CpuType, Globals.IpAddress, Globals.Port, Globals.Slot, Globals.Rack, Globals.ConnectTimeOut);
             var connectResult = Globals.SiemensClient.Open();
             var connectResult = Globals.SiemensClient.Open();
-        }
 
 
+            if(connectResult.IsSucceed)
+            {
+                plcIsConnected = true;
+                this.led_PlcState.On = true;
+            }
+            else
+            {
+                plcIsConnected = false;
+                this.led_PlcState.On = false;
+            }
+            for (int i = 0; i < plcVarList.Count; i++)
+            {
+                //初始化PLC变量地址字典 地址-类型
+                Globals.ReadDic.Add(plcVarList[i].PLC地址, Enum.Parse<DataTypeEnum>(plcVarList[i].变量类型, true));//忽略大小写
+                                                                                                             //初始化PLC变量写入 名称-地址                                                                                       //初始化PLC变量值字典 名称-值
+                Globals.WriteDic.Add(plcVarList[i].名称, plcVarList[i].PLC地址);
+                //初始化PLC变量值字典 名称-值
+                Globals.DataDic.Add(plcVarList[i].名称, "NA");
+                if (plcVarList[i].是否保存.ToLower() == "true")
+                {
+                    Globals.SaveList.Add(plcVarList[i].名称);
+                }
+            }
+
+            _logger.LogInformation("初始化PLC客户端成功");
+
+            try
+            {
+                Task.Run(async () =>
+                {
+                    while (!cts.IsCancellationRequested)
+                    {
+                        if (plcIsConnected)
+                        {
+                            //这个方法的目的是将大量的数据读取请求分批处理,以提高性能和可管理性。
+                            var readResult = Globals.SiemensClient.BatchRead(Globals.ReadDic);
+                            if (readResult.IsSucceed)
+                            {
+                                for (int i = 0; i < plcVarList.Count; i++)
+                                {
+                                    Globals.DataDic[plcVarList[i].名称] = readResult.Value[plcVarList[i].PLC地址];
+                                }
+                            }
+                            else
+                            {
+                                Globals.SiemensClient.Close();
+                                plcIsConnected = false;
+
+                                this.Invoke(() =>
+                                {
+                                    this.led_PlcState.On = false;
+                                });
+                            }
+                            await Task.Delay(Globals.ReadTimeInterval);
+                        }
+                        else
+                        {
+                            //重连PLC
+                            var reConnectResult = Globals.SiemensClient.Open();
+                            if (reConnectResult.IsSucceed)
+                            {
+                                plcIsConnected = true;
+                                this.Invoke(() =>
+                                {
+                                    this.led_PlcState.On = true;
+                                });
+                            }
+                            else
+                            {
+                                plcIsConnected = false;
+                                this.Invoke(() =>
+                                {
+                                    this.led_PlcState.On = false;
+                                });
+                                await Task.Delay(Globals.ReConnectTimeInterval);
+                            }
+                        }
+                    }
+
+                    await Task.Delay(1000);
+                }, cts.Token);
+            }
+            catch (Exception)
+            {
+                throw;
+            }
+        }
         private void InitAsideUI()
         private void InitAsideUI()
         {
         {
             int pageIndex = 1000;
             int pageIndex = 1000;
@@ -152,5 +257,18 @@ namespace Scada
                     break;
                     break;
             }
             }
         }
         }
+
+        private void Panel_MouseDown(object sender, MouseEventArgs e)
+        {
+            mPoint = new Point(e.X, e.Y);
+        }
+
+        private void Panel_MouseMove(object sender, MouseEventArgs e)
+        {
+            if (e.Button == MouseButtons.Left)
+            {
+                this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
+            }
+        }
     }
     }
 }
 }

+ 12 - 0
Scada/Globals.cs

@@ -36,8 +36,20 @@ namespace Scada
         public static int ReConnectTimeInterval;
         public static int ReConnectTimeInterval;
 
 
         public static SiemensClient SiemensClient;
         public static SiemensClient SiemensClient;
+
         public static Dictionary<string, DataTypeEnum> ReadDic = new Dictionary<string, DataTypeEnum>();
         public static Dictionary<string, DataTypeEnum> ReadDic = new Dictionary<string, DataTypeEnum>();
         public static Dictionary<string, object> DataDic = new Dictionary<string, object>();
         public static Dictionary<string, object> DataDic = new Dictionary<string, object>();
         public static Dictionary<string, string> WriteDic = new Dictionary<string, string>();
         public static Dictionary<string, string> WriteDic = new Dictionary<string, string>();
+        public static IList<string> SaveList = new List<string>();
+
+        public static string DelFilePath;
+
+        public static string SaveDay;
+
+        public static int SYTime;
+
+        public static string SoftwareVersion;
+
+        
     }
     }
 }
 }

+ 28 - 28
Scada/Page/PageSystemParameterSet.Designer.cs

@@ -29,6 +29,8 @@
         private void InitializeComponent()
         private void InitializeComponent()
         {
         {
             uiTitlePanel1 = new Sunny.UI.UITitlePanel();
             uiTitlePanel1 = new Sunny.UI.UITitlePanel();
+            txt_plcConfig = new Sunny.UI.UITextBox();
+            uiLabel13 = new Sunny.UI.UILabel();
             txt_ReConnectTimeInterval = new Sunny.UI.UITextBox();
             txt_ReConnectTimeInterval = new Sunny.UI.UITextBox();
             uiLabel8 = new Sunny.UI.UILabel();
             uiLabel8 = new Sunny.UI.UILabel();
             txt_ReadTimeInterval = new Sunny.UI.UITextBox();
             txt_ReadTimeInterval = new Sunny.UI.UITextBox();
@@ -56,8 +58,6 @@
             txt_SoftwareVersion = new Sunny.UI.UITextBox();
             txt_SoftwareVersion = new Sunny.UI.UITextBox();
             uiLabel10 = new Sunny.UI.UILabel();
             uiLabel10 = new Sunny.UI.UILabel();
             btn_Save = new Sunny.UI.UIButton();
             btn_Save = new Sunny.UI.UIButton();
-            uiLabel13 = new Sunny.UI.UILabel();
-            text_plcConfig = new Sunny.UI.UITextBox();
             uiTitlePanel1.SuspendLayout();
             uiTitlePanel1.SuspendLayout();
             uiTitlePanel3.SuspendLayout();
             uiTitlePanel3.SuspendLayout();
             uiTitlePanel2.SuspendLayout();
             uiTitlePanel2.SuspendLayout();
@@ -65,7 +65,7 @@
             // 
             // 
             // uiTitlePanel1
             // uiTitlePanel1
             // 
             // 
-            uiTitlePanel1.Controls.Add(text_plcConfig);
+            uiTitlePanel1.Controls.Add(txt_plcConfig);
             uiTitlePanel1.Controls.Add(uiLabel13);
             uiTitlePanel1.Controls.Add(uiLabel13);
             uiTitlePanel1.Controls.Add(txt_ReConnectTimeInterval);
             uiTitlePanel1.Controls.Add(txt_ReConnectTimeInterval);
             uiTitlePanel1.Controls.Add(uiLabel8);
             uiTitlePanel1.Controls.Add(uiLabel8);
@@ -94,6 +94,30 @@
             uiTitlePanel1.Text = "PLC参数";
             uiTitlePanel1.Text = "PLC参数";
             uiTitlePanel1.TextAlignment = ContentAlignment.MiddleCenter;
             uiTitlePanel1.TextAlignment = ContentAlignment.MiddleCenter;
             // 
             // 
+            // txt_plcConfig
+            // 
+            txt_plcConfig.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            txt_plcConfig.Location = new Point(209, 49);
+            txt_plcConfig.Margin = new Padding(4, 5, 4, 5);
+            txt_plcConfig.MinimumSize = new Size(1, 16);
+            txt_plcConfig.Name = "txt_plcConfig";
+            txt_plcConfig.Padding = new Padding(5);
+            txt_plcConfig.ShowText = false;
+            txt_plcConfig.Size = new Size(392, 36);
+            txt_plcConfig.TabIndex = 18;
+            txt_plcConfig.TextAlignment = ContentAlignment.MiddleLeft;
+            txt_plcConfig.Watermark = "";
+            // 
+            // uiLabel13
+            // 
+            uiLabel13.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
+            uiLabel13.ForeColor = Color.FromArgb(48, 48, 48);
+            uiLabel13.Location = new Point(17, 56);
+            uiLabel13.Name = "uiLabel13";
+            uiLabel13.Size = new Size(209, 29);
+            uiLabel13.TabIndex = 17;
+            uiLabel13.Text = "上位机配置文件地址";
+            // 
             // txt_ReConnectTimeInterval
             // txt_ReConnectTimeInterval
             // 
             // 
             txt_ReConnectTimeInterval.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
             txt_ReConnectTimeInterval.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
@@ -431,30 +455,6 @@
             btn_Save.Text = "保存";
             btn_Save.Text = "保存";
             btn_Save.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             btn_Save.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
             // 
             // 
-            // uiLabel13
-            // 
-            uiLabel13.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            uiLabel13.ForeColor = Color.FromArgb(48, 48, 48);
-            uiLabel13.Location = new Point(17, 56);
-            uiLabel13.Name = "uiLabel13";
-            uiLabel13.Size = new Size(209, 29);
-            uiLabel13.TabIndex = 17;
-            uiLabel13.Text = "上位机配置文件地址";
-            // 
-            // text_plcConfig
-            // 
-            text_plcConfig.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
-            text_plcConfig.Location = new Point(209, 49);
-            text_plcConfig.Margin = new Padding(4, 5, 4, 5);
-            text_plcConfig.MinimumSize = new Size(1, 16);
-            text_plcConfig.Name = "text_plcConfig";
-            text_plcConfig.Padding = new Padding(5);
-            text_plcConfig.ShowText = false;
-            text_plcConfig.Size = new Size(392, 36);
-            text_plcConfig.TabIndex = 18;
-            text_plcConfig.TextAlignment = ContentAlignment.MiddleLeft;
-            text_plcConfig.Watermark = "";
-            // 
             // PageSystemParameterSet
             // PageSystemParameterSet
             // 
             // 
             AutoScaleMode = AutoScaleMode.None;
             AutoScaleMode = AutoScaleMode.None;
@@ -502,7 +502,7 @@
         private Sunny.UI.UILabel uiLabel12;
         private Sunny.UI.UILabel uiLabel12;
         private Sunny.UI.UIRadioButtonGroup rbg_Save;
         private Sunny.UI.UIRadioButtonGroup rbg_Save;
         private Sunny.UI.UIButton btn_Save;
         private Sunny.UI.UIButton btn_Save;
-        private Sunny.UI.UITextBox text_plcConfig;
+        private Sunny.UI.UITextBox txt_plcConfig;
         private Sunny.UI.UILabel uiLabel13;
         private Sunny.UI.UILabel uiLabel13;
     }
     }
 }
 }

+ 10 - 1
Scada/Page/PageSystemParameterSet.cs

@@ -27,7 +27,16 @@ namespace Scada.Page
 
 
         private void InitSystemParameter()
         private void InitSystemParameter()
         {
         {
-            this.text_plcConfig.Text = Globals.PlcVarConfigPath;
+            this.txt_plcConfig.Text = Globals.PlcVarConfigPath;
+            this.txt_ConnectTimeOut.Text = Globals.ConnectTimeOut.ToString();
+            this.txt_ReadTimeInterval.Text = Globals.ReadTimeInterval.ToString();
+            this.txt_ReConnectTimeInterval.Text = Globals.ReConnectTimeInterval.ToString();
+            this.txt_IPAddress.Text = Globals.IpAddress;
+            this.txt_Port.Text = Globals.Port.ToString();
+            this.cb_CPUType.Text = Globals.CpuType.ToString();
+            this.txt_Slot.Text = Globals.Slot.ToString();
+            this.txt_Rack.Text = Globals.Rack.ToString();
+            
         }
         }
     }
     }
 }
 }

+ 26 - 0
Scada/Program.cs

@@ -1,6 +1,10 @@
 using System.Reflection;
 using System.Reflection;
 using HZY.Framework.DependencyInjection;
 using HZY.Framework.DependencyInjection;
+using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog;
+using NLog.Extensions.Logging;
 
 
 namespace Scada
 namespace Scada
 {
 {
@@ -12,6 +16,8 @@ namespace Scada
         [STAThread]
         [STAThread]
         static void Main()
         static void Main()
         {
         {
+            
+
             var services = new ServiceCollection();
             var services = new ServiceCollection();
             ConfigureServices(services);
             ConfigureServices(services);
             ApplicationConfiguration.Initialize();
             ApplicationConfiguration.Initialize();
@@ -29,6 +35,26 @@ namespace Scada
             {
             {
                 options.Assemblies = new[] { typeof(Program).Assembly };
                 options.Assemblies = new[] { typeof(Program).Assembly };
             });
             });
+
+            IConfigurationBuilder cfgBuilder = new ConfigurationBuilder()
+     .SetBasePath(Environment.CurrentDirectory)
+     .AddJsonFile("appsettings.json");
+
+            //构建json配置
+            IConfiguration configuration = cfgBuilder.Build();
+            //注入json单例对象
+            services.AddSingleton<IConfiguration>(configuration)
+                .AddLogging(loggerBuilder => {
+                    loggerBuilder.ClearProviders();//清除其他日志的提供者
+                    loggerBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);//设置等级
+                    loggerBuilder.AddNLog();
+                });
+
+            //获取NLog配置信息
+            var nlogConifg = configuration.GetSection("NLog");
+
+            //设置Nlog配置
+            LogManager.Configuration = new NLogLoggingConfiguration(nlogConifg);
         }
         }
     }
     }
 }
 }