From c738aeab37d30389ad3e6cb0ce460f9fcee1f05f Mon Sep 17 00:00:00 2001 From: gongxh Date: Thu, 19 May 2022 12:55:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frmMainDetailNew.Designer.cs | 502 ++++---- CleanMachineHMI/Utils/GlobalHelper.cs | 10 +- CleanMachineHMI/Utils/PlcOperationHelper.cs | 1136 +++++++++-------- CleanMachineHMI/frmLogin.cs | 1 + CleanMachineHMI/frmMainNew.cs | 382 +++--- 5 files changed, 1047 insertions(+), 984 deletions(-) diff --git a/CleanMachineHMI/FrmUserControl/frmMainDetailNew.Designer.cs b/CleanMachineHMI/FrmUserControl/frmMainDetailNew.Designer.cs index 80e7bdd..a3a92ad 100644 --- a/CleanMachineHMI/FrmUserControl/frmMainDetailNew.Designer.cs +++ b/CleanMachineHMI/FrmUserControl/frmMainDetailNew.Designer.cs @@ -50,14 +50,31 @@ namespace CleanMachineHMI.FrmUserControl this.kryptonButton3 = new Krypton.Toolkit.KryptonButton(); this.knud_WorkedFullPalletNum = new Krypton.Toolkit.KryptonTextBox(); this.kryptonGroupBox7 = new Krypton.Toolkit.KryptonGroupBox(); + this.circleButton1 = new CleanMachineHMI.CircleButton(); this.kryptonLabel12 = new Krypton.Toolkit.KryptonLabel(); this.kryptonLabel11 = new Krypton.Toolkit.KryptonLabel(); + this.cbt_fpalletmod = new CleanMachineHMI.CircleButton(); + this.cbt_staticbar = new CleanMachineHMI.CircleButton(); + this.swtbtn_fullPalletMod = new CleanMachineHMI.LSwitchButton(); + this.swtbtn_staticBar = new CleanMachineHMI.LSwitchButton(); this.label2 = new System.Windows.Forms.Label(); this.kryptonLabel6 = new Krypton.Toolkit.KryptonLabel(); this.label1 = new System.Windows.Forms.Label(); + this.swtbtn_nozzle1 = new CleanMachineHMI.LSwitchButton(); + this.cbt_RunStatusTran = new CleanMachineHMI.CircleButton(); + this.cbt_NozzleStatusTran = new CleanMachineHMI.CircleButton(); + this.cbt_ResetSys = new CleanMachineHMI.CircleButton(); this.kryptonLabel7 = new Krypton.Toolkit.KryptonLabel(); + this.cbt_StopTran = new CleanMachineHMI.CircleButton(); + this.swtbtn_brush3 = new CleanMachineHMI.LSwitchButton(); + this.cbt_StartTran = new CleanMachineHMI.CircleButton(); + this.cbt_Brush3StatusTran = new CleanMachineHMI.CircleButton(); + this.swtbtn_brush1 = new CleanMachineHMI.LSwitchButton(); this.kryptonLabel8 = new Krypton.Toolkit.KryptonLabel(); + this.cbt_Brush1StatusTran = new CleanMachineHMI.CircleButton(); this.kryptonLabel9 = new Krypton.Toolkit.KryptonLabel(); + this.swtbtn_brush2 = new CleanMachineHMI.LSwitchButton(); + this.cbt_Brush2StatusTran = new CleanMachineHMI.CircleButton(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.kryptonGroupBox1 = new Krypton.Toolkit.KryptonGroupBox(); this.kryptonLabel13 = new Krypton.Toolkit.KryptonLabel(); @@ -187,23 +204,6 @@ namespace CleanMachineHMI.FrmUserControl this.btnIO = new Krypton.Toolkit.KryptonButton(); this.btnManual = new Krypton.Toolkit.KryptonButton(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.circleButton1 = new CleanMachineHMI.CircleButton(); - this.cbt_fpalletmod = new CleanMachineHMI.CircleButton(); - this.cbt_staticbar = new CleanMachineHMI.CircleButton(); - this.swtbtn_fullPalletMod = new CleanMachineHMI.LSwitchButton(); - this.swtbtn_staticBar = new CleanMachineHMI.LSwitchButton(); - this.swtbtn_nozzle1 = new CleanMachineHMI.LSwitchButton(); - this.cbt_RunStatusTran = new CleanMachineHMI.CircleButton(); - this.cbt_NozzleStatusTran = new CleanMachineHMI.CircleButton(); - this.cbt_ResetSys = new CleanMachineHMI.CircleButton(); - this.cbt_StopTran = new CleanMachineHMI.CircleButton(); - this.swtbtn_brush3 = new CleanMachineHMI.LSwitchButton(); - this.cbt_StartTran = new CleanMachineHMI.CircleButton(); - this.cbt_Brush3StatusTran = new CleanMachineHMI.CircleButton(); - this.swtbtn_brush1 = new CleanMachineHMI.LSwitchButton(); - this.cbt_Brush1StatusTran = new CleanMachineHMI.CircleButton(); - this.swtbtn_brush2 = new CleanMachineHMI.LSwitchButton(); - this.cbt_Brush2StatusTran = new CleanMachineHMI.CircleButton(); ((System.ComponentModel.ISupportInitialize)(this.kryptonGroupBox8)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.kryptonGroupBox8.Panel)).BeginInit(); this.kryptonGroupBox8.Panel.SuspendLayout(); @@ -529,6 +529,21 @@ namespace CleanMachineHMI.FrmUserControl this.kryptonGroupBox7.TabIndex = 5; this.kryptonGroupBox7.Values.Heading = ""; // + // circleButton1 + // + this.circleButton1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); + this.circleButton1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.circleButton1.ForeColor = System.Drawing.Color.White; + this.circleButton1.Location = new System.Drawing.Point(68, 331); + this.circleButton1.Name = "circleButton1"; + this.circleButton1.Size = new System.Drawing.Size(60, 60); + this.circleButton1.TabIndex = 53; + this.circleButton1.Text = "Auto Stop"; + this.circleButton1.UseVisualStyleBackColor = false; + this.circleButton1.Visible = false; + this.circleButton1.Click += new System.EventHandler(this.circleButton1_Click); + this.circleButton1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.circleButton1_KeyUp); + // // kryptonLabel12 // this.kryptonLabel12.Location = new System.Drawing.Point(21, 302); @@ -546,6 +561,62 @@ namespace CleanMachineHMI.FrmUserControl this.kryptonLabel11.TabIndex = 50; this.kryptonLabel11.Values.Text = "静电棒"; // + // cbt_fpalletmod + // + this.cbt_fpalletmod.BackColor = System.Drawing.Color.Gray; + this.cbt_fpalletmod.Location = new System.Drawing.Point(203, 300); + this.cbt_fpalletmod.Name = "cbt_fpalletmod"; + this.cbt_fpalletmod.Size = new System.Drawing.Size(30, 30); + this.cbt_fpalletmod.TabIndex = 49; + this.cbt_fpalletmod.UseVisualStyleBackColor = false; + this.cbt_fpalletmod.Visible = false; + // + // cbt_staticbar + // + this.cbt_staticbar.BackColor = System.Drawing.Color.Gray; + this.cbt_staticbar.Location = new System.Drawing.Point(203, 241); + this.cbt_staticbar.Name = "cbt_staticbar"; + this.cbt_staticbar.Size = new System.Drawing.Size(30, 30); + this.cbt_staticbar.TabIndex = 48; + this.cbt_staticbar.UseVisualStyleBackColor = false; + // + // swtbtn_fullPalletMod + // + this.swtbtn_fullPalletMod.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); + this.swtbtn_fullPalletMod.L_AnimateType = LEase.LEaseType.Quartic; + this.swtbtn_fullPalletMod.L_BarHight = 24; + this.swtbtn_fullPalletMod.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); + this.swtbtn_fullPalletMod.L_DotColor = System.Drawing.Color.White; + this.swtbtn_fullPalletMod.L_DotHight = 20; + this.swtbtn_fullPalletMod.L_IsOpen = false; + this.swtbtn_fullPalletMod.L_Margin = 2; + this.swtbtn_fullPalletMod.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.swtbtn_fullPalletMod.Location = new System.Drawing.Point(106, 300); + this.swtbtn_fullPalletMod.Name = "swtbtn_fullPalletMod"; + this.swtbtn_fullPalletMod.Size = new System.Drawing.Size(58, 25); + this.swtbtn_fullPalletMod.TabIndex = 47; + this.swtbtn_fullPalletMod.Text = "lSwitchButton4"; + this.swtbtn_fullPalletMod.Visible = false; + this.swtbtn_fullPalletMod.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_fullPalletMod_LSwitched); + // + // swtbtn_staticBar + // + this.swtbtn_staticBar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); + this.swtbtn_staticBar.L_AnimateType = LEase.LEaseType.Quartic; + this.swtbtn_staticBar.L_BarHight = 24; + this.swtbtn_staticBar.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); + this.swtbtn_staticBar.L_DotColor = System.Drawing.Color.White; + this.swtbtn_staticBar.L_DotHight = 20; + this.swtbtn_staticBar.L_IsOpen = false; + this.swtbtn_staticBar.L_Margin = 2; + this.swtbtn_staticBar.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.swtbtn_staticBar.Location = new System.Drawing.Point(105, 241); + this.swtbtn_staticBar.Name = "swtbtn_staticBar"; + this.swtbtn_staticBar.Size = new System.Drawing.Size(58, 25); + this.swtbtn_staticBar.TabIndex = 46; + this.swtbtn_staticBar.Text = "lSwitchButton4"; + this.swtbtn_staticBar.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_staticBar_LSwitched); + // // label2 // this.label2.AutoSize = true; @@ -579,6 +650,58 @@ namespace CleanMachineHMI.FrmUserControl this.label1.TabIndex = 8; this.label1.Text = "系统运行"; // + // swtbtn_nozzle1 + // + this.swtbtn_nozzle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); + this.swtbtn_nozzle1.L_AnimateType = LEase.LEaseType.Quartic; + this.swtbtn_nozzle1.L_BarHight = 24; + this.swtbtn_nozzle1.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); + this.swtbtn_nozzle1.L_DotColor = System.Drawing.Color.White; + this.swtbtn_nozzle1.L_DotHight = 20; + this.swtbtn_nozzle1.L_IsOpen = false; + this.swtbtn_nozzle1.L_Margin = 2; + this.swtbtn_nozzle1.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.swtbtn_nozzle1.Location = new System.Drawing.Point(106, 271); + this.swtbtn_nozzle1.Name = "swtbtn_nozzle1"; + this.swtbtn_nozzle1.Size = new System.Drawing.Size(58, 25); + this.swtbtn_nozzle1.TabIndex = 43; + this.swtbtn_nozzle1.Text = "lSwitchButton4"; + this.swtbtn_nozzle1.Visible = false; + this.swtbtn_nozzle1.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_nozzle1_LSwitched); + // + // cbt_RunStatusTran + // + this.cbt_RunStatusTran.BackColor = System.Drawing.Color.Gray; + this.cbt_RunStatusTran.Location = new System.Drawing.Point(203, 5); + this.cbt_RunStatusTran.Name = "cbt_RunStatusTran"; + this.cbt_RunStatusTran.Size = new System.Drawing.Size(30, 30); + this.cbt_RunStatusTran.TabIndex = 7; + this.cbt_RunStatusTran.UseVisualStyleBackColor = false; + // + // cbt_NozzleStatusTran + // + this.cbt_NozzleStatusTran.BackColor = System.Drawing.Color.Gray; + this.cbt_NozzleStatusTran.Location = new System.Drawing.Point(203, 272); + this.cbt_NozzleStatusTran.Name = "cbt_NozzleStatusTran"; + this.cbt_NozzleStatusTran.Size = new System.Drawing.Size(30, 30); + this.cbt_NozzleStatusTran.TabIndex = 42; + this.cbt_NozzleStatusTran.UseVisualStyleBackColor = false; + this.cbt_NozzleStatusTran.Visible = false; + // + // cbt_ResetSys + // + this.cbt_ResetSys.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(153)))), ((int)(((byte)(0))))); + this.cbt_ResetSys.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.cbt_ResetSys.ForeColor = System.Drawing.Color.White; + this.cbt_ResetSys.Location = new System.Drawing.Point(162, 41); + this.cbt_ResetSys.Name = "cbt_ResetSys"; + this.cbt_ResetSys.Size = new System.Drawing.Size(60, 60); + this.cbt_ResetSys.TabIndex = 5; + this.cbt_ResetSys.Text = "RESET"; + this.cbt_ResetSys.UseVisualStyleBackColor = false; + this.cbt_ResetSys.MouseDown += new System.Windows.Forms.MouseEventHandler(this.cbt_ResetSys_MouseDown); + this.cbt_ResetSys.MouseUp += new System.Windows.Forms.MouseEventHandler(this.cbt_ResetSys_MouseUp); + // // kryptonLabel7 // this.kryptonLabel7.Location = new System.Drawing.Point(20, 213); @@ -587,6 +710,80 @@ namespace CleanMachineHMI.FrmUserControl this.kryptonLabel7.TabIndex = 41; this.kryptonLabel7.Values.Text = "毛刷3"; // + // cbt_StopTran + // + this.cbt_StopTran.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); + this.cbt_StopTran.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.cbt_StopTran.ForeColor = System.Drawing.Color.White; + this.cbt_StopTran.Location = new System.Drawing.Point(96, 41); + this.cbt_StopTran.Name = "cbt_StopTran"; + this.cbt_StopTran.Size = new System.Drawing.Size(60, 60); + this.cbt_StopTran.TabIndex = 5; + this.cbt_StopTran.Text = "STOP"; + this.cbt_StopTran.UseVisualStyleBackColor = false; + this.cbt_StopTran.Click += new System.EventHandler(this.cbt_StopTran_Click); + this.cbt_StopTran.MouseDown += new System.Windows.Forms.MouseEventHandler(this.cbt_StopTran_MouseDown); + this.cbt_StopTran.MouseUp += new System.Windows.Forms.MouseEventHandler(this.cbt_StopTran_MouseUp); + // + // swtbtn_brush3 + // + this.swtbtn_brush3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); + this.swtbtn_brush3.L_AnimateType = LEase.LEaseType.Quartic; + this.swtbtn_brush3.L_BarHight = 24; + this.swtbtn_brush3.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); + this.swtbtn_brush3.L_DotColor = System.Drawing.Color.White; + this.swtbtn_brush3.L_DotHight = 20; + this.swtbtn_brush3.L_IsOpen = false; + this.swtbtn_brush3.L_Margin = 2; + this.swtbtn_brush3.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.swtbtn_brush3.Location = new System.Drawing.Point(105, 211); + this.swtbtn_brush3.Name = "swtbtn_brush3"; + this.swtbtn_brush3.Size = new System.Drawing.Size(58, 25); + this.swtbtn_brush3.TabIndex = 40; + this.swtbtn_brush3.Text = "lSwitchButton3"; + this.swtbtn_brush3.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_brush3_LSwitched); + // + // cbt_StartTran + // + this.cbt_StartTran.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(190)))), ((int)(((byte)(107))))); + this.cbt_StartTran.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.cbt_StartTran.Location = new System.Drawing.Point(30, 41); + this.cbt_StartTran.Name = "cbt_StartTran"; + this.cbt_StartTran.Size = new System.Drawing.Size(60, 60); + this.cbt_StartTran.TabIndex = 5; + this.cbt_StartTran.Text = "START"; + this.cbt_StartTran.UseVisualStyleBackColor = false; + this.cbt_StartTran.Click += new System.EventHandler(this.cbt_StartTran_Click); + this.cbt_StartTran.MouseDown += new System.Windows.Forms.MouseEventHandler(this.cbt_StartTran_MouseDown); + this.cbt_StartTran.MouseUp += new System.Windows.Forms.MouseEventHandler(this.cbt_StartTran_MouseUp); + // + // cbt_Brush3StatusTran + // + this.cbt_Brush3StatusTran.BackColor = System.Drawing.Color.Gray; + this.cbt_Brush3StatusTran.Location = new System.Drawing.Point(203, 210); + this.cbt_Brush3StatusTran.Name = "cbt_Brush3StatusTran"; + this.cbt_Brush3StatusTran.Size = new System.Drawing.Size(30, 30); + this.cbt_Brush3StatusTran.TabIndex = 39; + this.cbt_Brush3StatusTran.UseVisualStyleBackColor = false; + // + // swtbtn_brush1 + // + this.swtbtn_brush1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); + this.swtbtn_brush1.L_AnimateType = LEase.LEaseType.Quartic; + this.swtbtn_brush1.L_BarHight = 24; + this.swtbtn_brush1.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); + this.swtbtn_brush1.L_DotColor = System.Drawing.Color.White; + this.swtbtn_brush1.L_DotHight = 20; + this.swtbtn_brush1.L_IsOpen = false; + this.swtbtn_brush1.L_Margin = 2; + this.swtbtn_brush1.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.swtbtn_brush1.Location = new System.Drawing.Point(105, 153); + this.swtbtn_brush1.Name = "swtbtn_brush1"; + this.swtbtn_brush1.Size = new System.Drawing.Size(58, 25); + this.swtbtn_brush1.TabIndex = 35; + this.swtbtn_brush1.Text = "lSwitchButton1"; + this.swtbtn_brush1.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_brush1_LSwitched); + // // kryptonLabel8 // this.kryptonLabel8.Location = new System.Drawing.Point(20, 184); @@ -595,6 +792,15 @@ namespace CleanMachineHMI.FrmUserControl this.kryptonLabel8.TabIndex = 38; this.kryptonLabel8.Values.Text = "毛刷2"; // + // cbt_Brush1StatusTran + // + this.cbt_Brush1StatusTran.BackColor = System.Drawing.Color.Gray; + this.cbt_Brush1StatusTran.Location = new System.Drawing.Point(203, 150); + this.cbt_Brush1StatusTran.Name = "cbt_Brush1StatusTran"; + this.cbt_Brush1StatusTran.Size = new System.Drawing.Size(30, 30); + this.cbt_Brush1StatusTran.TabIndex = 33; + this.cbt_Brush1StatusTran.UseVisualStyleBackColor = false; + // // kryptonLabel9 // this.kryptonLabel9.Location = new System.Drawing.Point(20, 155); @@ -603,6 +809,33 @@ namespace CleanMachineHMI.FrmUserControl this.kryptonLabel9.TabIndex = 34; this.kryptonLabel9.Values.Text = "毛刷1"; // + // swtbtn_brush2 + // + this.swtbtn_brush2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); + this.swtbtn_brush2.L_AnimateType = LEase.LEaseType.Quartic; + this.swtbtn_brush2.L_BarHight = 24; + this.swtbtn_brush2.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); + this.swtbtn_brush2.L_DotColor = System.Drawing.Color.White; + this.swtbtn_brush2.L_DotHight = 20; + this.swtbtn_brush2.L_IsOpen = false; + this.swtbtn_brush2.L_Margin = 2; + this.swtbtn_brush2.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); + this.swtbtn_brush2.Location = new System.Drawing.Point(105, 182); + this.swtbtn_brush2.Name = "swtbtn_brush2"; + this.swtbtn_brush2.Size = new System.Drawing.Size(58, 25); + this.swtbtn_brush2.TabIndex = 37; + this.swtbtn_brush2.Text = "lSwitchButton2"; + this.swtbtn_brush2.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_brush2_LSwitched); + // + // cbt_Brush2StatusTran + // + this.cbt_Brush2StatusTran.BackColor = System.Drawing.Color.Gray; + this.cbt_Brush2StatusTran.Location = new System.Drawing.Point(203, 180); + this.cbt_Brush2StatusTran.Name = "cbt_Brush2StatusTran"; + this.cbt_Brush2StatusTran.Size = new System.Drawing.Size(30, 30); + this.cbt_Brush2StatusTran.TabIndex = 36; + this.cbt_Brush2StatusTran.UseVisualStyleBackColor = false; + // // tableLayoutPanel2 // this.tableLayoutPanel2.BackColor = System.Drawing.Color.Transparent; @@ -810,6 +1043,7 @@ namespace CleanMachineHMI.FrmUserControl this.ktb_ShiftCount.Size = new System.Drawing.Size(71, 23); this.ktb_ShiftCount.TabIndex = 1; this.ktb_ShiftCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.ktb_ShiftCount.Visible = false; // // ktb_FinishedPalletNum // @@ -839,6 +1073,7 @@ namespace CleanMachineHMI.FrmUserControl this.kryptonLabel16.Size = new System.Drawing.Size(76, 20); this.kryptonLabel16.TabIndex = 0; this.kryptonLabel16.Values.Text = "Shift Count"; + this.kryptonLabel16.Visible = false; // // kryptonLabel15 // @@ -2563,239 +2798,6 @@ namespace CleanMachineHMI.FrmUserControl this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); // - // circleButton1 - // - this.circleButton1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); - this.circleButton1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.circleButton1.ForeColor = System.Drawing.Color.White; - this.circleButton1.Location = new System.Drawing.Point(68, 331); - this.circleButton1.Name = "circleButton1"; - this.circleButton1.Size = new System.Drawing.Size(60, 60); - this.circleButton1.TabIndex = 53; - this.circleButton1.Text = "Auto Stop"; - this.circleButton1.UseVisualStyleBackColor = false; - this.circleButton1.Visible = false; - this.circleButton1.Click += new System.EventHandler(this.circleButton1_Click); - this.circleButton1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.circleButton1_KeyUp); - // - // cbt_fpalletmod - // - this.cbt_fpalletmod.BackColor = System.Drawing.Color.Gray; - this.cbt_fpalletmod.Location = new System.Drawing.Point(203, 300); - this.cbt_fpalletmod.Name = "cbt_fpalletmod"; - this.cbt_fpalletmod.Size = new System.Drawing.Size(30, 30); - this.cbt_fpalletmod.TabIndex = 49; - this.cbt_fpalletmod.UseVisualStyleBackColor = false; - this.cbt_fpalletmod.Visible = false; - // - // cbt_staticbar - // - this.cbt_staticbar.BackColor = System.Drawing.Color.Gray; - this.cbt_staticbar.Location = new System.Drawing.Point(203, 241); - this.cbt_staticbar.Name = "cbt_staticbar"; - this.cbt_staticbar.Size = new System.Drawing.Size(30, 30); - this.cbt_staticbar.TabIndex = 48; - this.cbt_staticbar.UseVisualStyleBackColor = false; - // - // swtbtn_fullPalletMod - // - this.swtbtn_fullPalletMod.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); - this.swtbtn_fullPalletMod.L_AnimateType = LEase.LEaseType.Quartic; - this.swtbtn_fullPalletMod.L_BarHight = 24; - this.swtbtn_fullPalletMod.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); - this.swtbtn_fullPalletMod.L_DotColor = System.Drawing.Color.White; - this.swtbtn_fullPalletMod.L_DotHight = 20; - this.swtbtn_fullPalletMod.L_IsOpen = false; - this.swtbtn_fullPalletMod.L_Margin = 2; - this.swtbtn_fullPalletMod.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); - this.swtbtn_fullPalletMod.Location = new System.Drawing.Point(106, 300); - this.swtbtn_fullPalletMod.Name = "swtbtn_fullPalletMod"; - this.swtbtn_fullPalletMod.Size = new System.Drawing.Size(58, 25); - this.swtbtn_fullPalletMod.TabIndex = 47; - this.swtbtn_fullPalletMod.Text = "lSwitchButton4"; - this.swtbtn_fullPalletMod.Visible = false; - this.swtbtn_fullPalletMod.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_fullPalletMod_LSwitched); - // - // swtbtn_staticBar - // - this.swtbtn_staticBar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); - this.swtbtn_staticBar.L_AnimateType = LEase.LEaseType.Quartic; - this.swtbtn_staticBar.L_BarHight = 24; - this.swtbtn_staticBar.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); - this.swtbtn_staticBar.L_DotColor = System.Drawing.Color.White; - this.swtbtn_staticBar.L_DotHight = 20; - this.swtbtn_staticBar.L_IsOpen = false; - this.swtbtn_staticBar.L_Margin = 2; - this.swtbtn_staticBar.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); - this.swtbtn_staticBar.Location = new System.Drawing.Point(105, 241); - this.swtbtn_staticBar.Name = "swtbtn_staticBar"; - this.swtbtn_staticBar.Size = new System.Drawing.Size(58, 25); - this.swtbtn_staticBar.TabIndex = 46; - this.swtbtn_staticBar.Text = "lSwitchButton4"; - this.swtbtn_staticBar.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_staticBar_LSwitched); - // - // swtbtn_nozzle1 - // - this.swtbtn_nozzle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); - this.swtbtn_nozzle1.L_AnimateType = LEase.LEaseType.Quartic; - this.swtbtn_nozzle1.L_BarHight = 24; - this.swtbtn_nozzle1.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); - this.swtbtn_nozzle1.L_DotColor = System.Drawing.Color.White; - this.swtbtn_nozzle1.L_DotHight = 20; - this.swtbtn_nozzle1.L_IsOpen = false; - this.swtbtn_nozzle1.L_Margin = 2; - this.swtbtn_nozzle1.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); - this.swtbtn_nozzle1.Location = new System.Drawing.Point(106, 271); - this.swtbtn_nozzle1.Name = "swtbtn_nozzle1"; - this.swtbtn_nozzle1.Size = new System.Drawing.Size(58, 25); - this.swtbtn_nozzle1.TabIndex = 43; - this.swtbtn_nozzle1.Text = "lSwitchButton4"; - this.swtbtn_nozzle1.Visible = false; - this.swtbtn_nozzle1.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_nozzle1_LSwitched); - // - // cbt_RunStatusTran - // - this.cbt_RunStatusTran.BackColor = System.Drawing.Color.Gray; - this.cbt_RunStatusTran.Location = new System.Drawing.Point(203, 5); - this.cbt_RunStatusTran.Name = "cbt_RunStatusTran"; - this.cbt_RunStatusTran.Size = new System.Drawing.Size(30, 30); - this.cbt_RunStatusTran.TabIndex = 7; - this.cbt_RunStatusTran.UseVisualStyleBackColor = false; - // - // cbt_NozzleStatusTran - // - this.cbt_NozzleStatusTran.BackColor = System.Drawing.Color.Gray; - this.cbt_NozzleStatusTran.Location = new System.Drawing.Point(203, 272); - this.cbt_NozzleStatusTran.Name = "cbt_NozzleStatusTran"; - this.cbt_NozzleStatusTran.Size = new System.Drawing.Size(30, 30); - this.cbt_NozzleStatusTran.TabIndex = 42; - this.cbt_NozzleStatusTran.UseVisualStyleBackColor = false; - this.cbt_NozzleStatusTran.Visible = false; - // - // cbt_ResetSys - // - this.cbt_ResetSys.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(153)))), ((int)(((byte)(0))))); - this.cbt_ResetSys.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.cbt_ResetSys.ForeColor = System.Drawing.Color.White; - this.cbt_ResetSys.Location = new System.Drawing.Point(182, 41); - this.cbt_ResetSys.Name = "cbt_ResetSys"; - this.cbt_ResetSys.Size = new System.Drawing.Size(60, 60); - this.cbt_ResetSys.TabIndex = 5; - this.cbt_ResetSys.Text = "RESET"; - this.cbt_ResetSys.UseVisualStyleBackColor = false; - this.cbt_ResetSys.MouseDown += new System.Windows.Forms.MouseEventHandler(this.cbt_ResetSys_MouseDown); - this.cbt_ResetSys.MouseUp += new System.Windows.Forms.MouseEventHandler(this.cbt_ResetSys_MouseUp); - // - // cbt_StopTran - // - this.cbt_StopTran.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); - this.cbt_StopTran.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.cbt_StopTran.ForeColor = System.Drawing.Color.White; - this.cbt_StopTran.Location = new System.Drawing.Point(96, 41); - this.cbt_StopTran.Name = "cbt_StopTran"; - this.cbt_StopTran.Size = new System.Drawing.Size(60, 60); - this.cbt_StopTran.TabIndex = 5; - this.cbt_StopTran.Text = "STOP"; - this.cbt_StopTran.UseVisualStyleBackColor = false; - this.cbt_StopTran.Click += new System.EventHandler(this.cbt_StopTran_Click); - this.cbt_StopTran.MouseDown += new System.Windows.Forms.MouseEventHandler(this.cbt_StopTran_MouseDown); - this.cbt_StopTran.MouseUp += new System.Windows.Forms.MouseEventHandler(this.cbt_StopTran_MouseUp); - // - // swtbtn_brush3 - // - this.swtbtn_brush3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); - this.swtbtn_brush3.L_AnimateType = LEase.LEaseType.Quartic; - this.swtbtn_brush3.L_BarHight = 24; - this.swtbtn_brush3.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); - this.swtbtn_brush3.L_DotColor = System.Drawing.Color.White; - this.swtbtn_brush3.L_DotHight = 20; - this.swtbtn_brush3.L_IsOpen = false; - this.swtbtn_brush3.L_Margin = 2; - this.swtbtn_brush3.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); - this.swtbtn_brush3.Location = new System.Drawing.Point(105, 211); - this.swtbtn_brush3.Name = "swtbtn_brush3"; - this.swtbtn_brush3.Size = new System.Drawing.Size(58, 25); - this.swtbtn_brush3.TabIndex = 40; - this.swtbtn_brush3.Text = "lSwitchButton3"; - this.swtbtn_brush3.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_brush3_LSwitched); - // - // cbt_StartTran - // - this.cbt_StartTran.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(190)))), ((int)(((byte)(107))))); - this.cbt_StartTran.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.cbt_StartTran.Location = new System.Drawing.Point(9, 41); - this.cbt_StartTran.Name = "cbt_StartTran"; - this.cbt_StartTran.Size = new System.Drawing.Size(60, 60); - this.cbt_StartTran.TabIndex = 5; - this.cbt_StartTran.Text = "START"; - this.cbt_StartTran.UseVisualStyleBackColor = false; - this.cbt_StartTran.Click += new System.EventHandler(this.cbt_StartTran_Click); - this.cbt_StartTran.MouseDown += new System.Windows.Forms.MouseEventHandler(this.cbt_StartTran_MouseDown); - this.cbt_StartTran.MouseUp += new System.Windows.Forms.MouseEventHandler(this.cbt_StartTran_MouseUp); - // - // cbt_Brush3StatusTran - // - this.cbt_Brush3StatusTran.BackColor = System.Drawing.Color.Gray; - this.cbt_Brush3StatusTran.Location = new System.Drawing.Point(203, 210); - this.cbt_Brush3StatusTran.Name = "cbt_Brush3StatusTran"; - this.cbt_Brush3StatusTran.Size = new System.Drawing.Size(30, 30); - this.cbt_Brush3StatusTran.TabIndex = 39; - this.cbt_Brush3StatusTran.UseVisualStyleBackColor = false; - // - // swtbtn_brush1 - // - this.swtbtn_brush1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); - this.swtbtn_brush1.L_AnimateType = LEase.LEaseType.Quartic; - this.swtbtn_brush1.L_BarHight = 24; - this.swtbtn_brush1.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); - this.swtbtn_brush1.L_DotColor = System.Drawing.Color.White; - this.swtbtn_brush1.L_DotHight = 20; - this.swtbtn_brush1.L_IsOpen = false; - this.swtbtn_brush1.L_Margin = 2; - this.swtbtn_brush1.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); - this.swtbtn_brush1.Location = new System.Drawing.Point(105, 153); - this.swtbtn_brush1.Name = "swtbtn_brush1"; - this.swtbtn_brush1.Size = new System.Drawing.Size(58, 25); - this.swtbtn_brush1.TabIndex = 35; - this.swtbtn_brush1.Text = "lSwitchButton1"; - this.swtbtn_brush1.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_brush1_LSwitched); - // - // cbt_Brush1StatusTran - // - this.cbt_Brush1StatusTran.BackColor = System.Drawing.Color.Gray; - this.cbt_Brush1StatusTran.Location = new System.Drawing.Point(203, 150); - this.cbt_Brush1StatusTran.Name = "cbt_Brush1StatusTran"; - this.cbt_Brush1StatusTran.Size = new System.Drawing.Size(30, 30); - this.cbt_Brush1StatusTran.TabIndex = 33; - this.cbt_Brush1StatusTran.UseVisualStyleBackColor = false; - // - // swtbtn_brush2 - // - this.swtbtn_brush2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(225))))); - this.swtbtn_brush2.L_AnimateType = LEase.LEaseType.Quartic; - this.swtbtn_brush2.L_BarHight = 24; - this.swtbtn_brush2.L_CloseColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(64)))), ((int)(((byte)(20))))); - this.swtbtn_brush2.L_DotColor = System.Drawing.Color.White; - this.swtbtn_brush2.L_DotHight = 20; - this.swtbtn_brush2.L_IsOpen = false; - this.swtbtn_brush2.L_Margin = 2; - this.swtbtn_brush2.L_OpenColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); - this.swtbtn_brush2.Location = new System.Drawing.Point(105, 182); - this.swtbtn_brush2.Name = "swtbtn_brush2"; - this.swtbtn_brush2.Size = new System.Drawing.Size(58, 25); - this.swtbtn_brush2.TabIndex = 37; - this.swtbtn_brush2.Text = "lSwitchButton2"; - this.swtbtn_brush2.LSwitched += new CleanMachineHMI.LSwitchButton.LSwitchedEventHandler(this.swtbtn_brush2_LSwitched); - // - // cbt_Brush2StatusTran - // - this.cbt_Brush2StatusTran.BackColor = System.Drawing.Color.Gray; - this.cbt_Brush2StatusTran.Location = new System.Drawing.Point(203, 180); - this.cbt_Brush2StatusTran.Name = "cbt_Brush2StatusTran"; - this.cbt_Brush2StatusTran.Size = new System.Drawing.Size(30, 30); - this.cbt_Brush2StatusTran.TabIndex = 36; - this.cbt_Brush2StatusTran.UseVisualStyleBackColor = false; - // // frmMainDetailNew // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); diff --git a/CleanMachineHMI/Utils/GlobalHelper.cs b/CleanMachineHMI/Utils/GlobalHelper.cs index 2cc8907..3c5f12a 100644 --- a/CleanMachineHMI/Utils/GlobalHelper.cs +++ b/CleanMachineHMI/Utils/GlobalHelper.cs @@ -244,15 +244,7 @@ namespace CleanMachineHMI } } // 定义一个委托类型的事件 - public static event EventHandler OnShowMainFrmAlarmMsg; - public static bool eventAlarmLock = false; - public static void ShowMainFrmAlarmMsg(object sender, EventArgs e) - { - if (!eventAlarmLock) - { - OnShowMainFrmAlarmMsg?.Invoke(sender, e); - } - } + public static frmPopupWarningMsg PopupWarningMsgForm { get; set; } //定义一个委托类型的事件 public static event EventHandler OnSyncFinishPalletData; diff --git a/CleanMachineHMI/Utils/PlcOperationHelper.cs b/CleanMachineHMI/Utils/PlcOperationHelper.cs index 0ae9a5e..1570769 100644 --- a/CleanMachineHMI/Utils/PlcOperationHelper.cs +++ b/CleanMachineHMI/Utils/PlcOperationHelper.cs @@ -162,6 +162,9 @@ namespace CleanMachineHMI // public System.Threading.AutoResetEvent thEvent = new System.Threading.AutoResetEvent(false); + + + private void RefreshPlcItem() { Stopwatch stopWatch = new Stopwatch(); @@ -182,7 +185,7 @@ namespace CleanMachineHMI stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - // Console.WriteLine($"读取PLC时间:{ts.Milliseconds}", LogTypeEum.Run); + // Console.WriteLine($"读取PLC时间:{ts.Milliseconds}", LogTypeEum.Run); if (haschange) { @@ -328,52 +331,52 @@ namespace CleanMachineHMI try { #endif - bool[] readBytArr_M = master.ReadCoils(slaveAddress, 2248, 50); - bool[] readBytArr_M1 = master.ReadCoils(slaveAddress, 2048, 50); - if (readBytArr_M.Length > 0 && readBytArr_M1.Length > 0) - { - if (PlcItemMd_M_List != null && PlcItemMd_M_List.Count > 0) + bool[] readBytArr_M = master.ReadCoils(slaveAddress, 2248, 50); + bool[] readBytArr_M1 = master.ReadCoils(slaveAddress, 2048, 50); + if (readBytArr_M.Length > 0 && readBytArr_M1.Length > 0) { - foreach (PlcItem item in PlcItemMd_M_List) + if (PlcItemMd_M_List != null && PlcItemMd_M_List.Count > 0) { - string value = ""; - if (Convert.ToInt32(item.PlcItemPriAddress) >= 200) + foreach (PlcItem item in PlcItemMd_M_List) { - - if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) + string value = ""; + if (Convert.ToInt32(item.PlcItemPriAddress) >= 200) { - //string PlcItemId = item.PlcItemId.ToString(); - //string plcdatatype = item.PlcItemDataType.ToString(); - int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); - value = readBytArr_M[plcItemDeviationAddress].ToString(); + if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) + { + //string PlcItemId = item.PlcItemId.ToString(); + //string plcdatatype = item.PlcItemDataType.ToString(); + int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); + value = readBytArr_M[plcItemDeviationAddress].ToString(); + + } } - } - else - { - if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) + else { - //string PlcItemId = item.PlcItemId.ToString(); - //string plcdatatype = item.PlcItemDataType.ToString(); - int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); - value = readBytArr_M1[plcItemDeviationAddress].ToString(); + if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) + { + //string PlcItemId = item.PlcItemId.ToString(); + //string plcdatatype = item.PlcItemDataType.ToString(); + int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); + value = readBytArr_M1[plcItemDeviationAddress].ToString(); + } } - } - if (value != "") - { - if (item.PlcItemValue != value) + if (value != "") { - haschange = true; - Console.WriteLine(item.PlcItemCode + "数据变化"); + if (item.PlcItemValue != value) + { + haschange = true; + Console.WriteLine(item.PlcItemCode + "数据变化"); + } + item.PlcItemValue = value; + Global.ShowSensorStatus(item, new EventArgs()); } - item.PlcItemValue = value; - Global.ShowSensorStatus(item, new EventArgs()); - } + } } } - } #if RELEASE } catch (Exception ex) @@ -389,107 +392,119 @@ namespace CleanMachineHMI { #endif - ushort[] tmpReadAlarmBytArr_D = master.ReadHoldingRegisters(slaveAddress, 4106, 50); - ushort[] readBytArr_D = master.ReadHoldingRegisters(slaveAddress, 4505, 50); - if (readBytArr_D.Length > 0 && tmpReadAlarmBytArr_D.Length > 0) - { - if (PlcItemMd_D_List != null && PlcItemMd_D_List.Count > 0) + ushort[] tmpReadAlarmBytArr_D = master.ReadHoldingRegisters(slaveAddress, 4106, 50); + ushort[] readBytArr_D = master.ReadHoldingRegisters(slaveAddress, 4505, 50); + if (readBytArr_D.Length > 0 && tmpReadAlarmBytArr_D.Length > 0) { - foreach (PlcItem item in PlcItemMd_D_List) + if (PlcItemMd_D_List != null && PlcItemMd_D_List.Count > 0) { - var value = ""; - if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) + foreach (PlcItem item in PlcItemMd_D_List) { - - string PlcItemId = item.PlcItemId.ToString(); - // string plcdatatype = item.PlcItemDataType.ToString(); - int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); - if (Convert.ToInt32(item.PlcItemPriAddress) < 409) + var value = ""; + if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) { - value = tmpReadAlarmBytArr_D[plcItemDeviationAddress].ToString(); - } - else - { - - if (item.PlcItemDataLength == 2) + string PlcItemId = item.PlcItemId.ToString(); + // string plcdatatype = item.PlcItemDataType.ToString(); + int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); + if (Convert.ToInt32(item.PlcItemPriAddress) < 409) { - // ushort[] tmp_1 = new ushort[] { readBytArr_D[plcItemDeviationAddress], readBytArr_D[plcItemDeviationAddress + 1] }; - - #region 方法一 :Short数组转换为int数据 20201014 孙亚龙 - //低位 short 的字节数组。 - byte[] tmpByt_1 = BitConverter.GetBytes(readBytArr_D[plcItemDeviationAddress]); - //高位 short 的字节数组。 - byte[] tmpByt_2 = BitConverter.GetBytes(readBytArr_D[plcItemDeviationAddress + 1]); - //组合为int32的字节数组。 - byte[] tmpByt_3 = new byte[] { tmpByt_1[0], tmpByt_1[1], tmpByt_2[0], tmpByt_2[1] }; - - - //readBytArr_D[plcItemDeviationAddress + 1] << 16 + - value = BitConverter.ToInt32(tmpByt_3, 0).ToString(); - #endregion - - #region 方法二 :Short数组转换为int数据 20201014 孙亚龙 - //相较而言 使用位移的算法效率更高一些。 - // value = ((readBytArr_D[plcItemDeviationAddress + 1] << 16) + readBytArr_D[plcItemDeviationAddress]).ToString(); - - - #endregion + value = tmpReadAlarmBytArr_D[plcItemDeviationAddress].ToString(); } else { - value = readBytArr_D[plcItemDeviationAddress].ToString(); + + if (item.PlcItemDataLength == 2) + { + // ushort[] tmp_1 = new ushort[] { readBytArr_D[plcItemDeviationAddress], readBytArr_D[plcItemDeviationAddress + 1] }; + + #region 方法一 :Short数组转换为int数据 20201014 孙亚龙 + //低位 short 的字节数组。 + byte[] tmpByt_1 = BitConverter.GetBytes(readBytArr_D[plcItemDeviationAddress]); + //高位 short 的字节数组。 + byte[] tmpByt_2 = BitConverter.GetBytes(readBytArr_D[plcItemDeviationAddress + 1]); + //组合为int32的字节数组。 + byte[] tmpByt_3 = new byte[] { tmpByt_1[0], tmpByt_1[1], tmpByt_2[0], tmpByt_2[1] }; + + + //readBytArr_D[plcItemDeviationAddress + 1] << 16 + + value = BitConverter.ToInt32(tmpByt_3, 0).ToString(); + #endregion + + #region 方法二 :Short数组转换为int数据 20201014 孙亚龙 + //相较而言 使用位移的算法效率更高一些。 + // value = ((readBytArr_D[plcItemDeviationAddress + 1] << 16) + readBytArr_D[plcItemDeviationAddress]).ToString(); + + + #endregion + + } + else + { + value = readBytArr_D[plcItemDeviationAddress].ToString(); + } } } - } - if (value != "") - { - if (item.PlcItemValue != value) + if (value != "") { - if (item.PlcItemCode != "PlcHeartbeatWriteData" && item.PlcItemCode != "PlcHeartbeatReadData") + if (item.PlcItemValue != value) { - haschange = true; - Console.WriteLine(item.PlcItemCode + "数据变化"); + if (item.PlcItemCode != "PlcHeartbeatWriteData" && item.PlcItemCode != "PlcHeartbeatReadData") + { + haschange = true; + Console.WriteLine(item.PlcItemCode + "数据变化"); + } + item.PlcItemValue = value; + } - item.PlcItemValue = value; + } } - - } - } - string priStr = "D"; - int index = 10; - Global.CmWarningLogMd_List.Clear(); - for (var i = 0; i < 9; i++) - { - var plcitem = $"{priStr}{index + i}"; - - if (tmpReadAlarmBytArr_D[i] != 0) + string priStr = "D"; + int index = 10; + bool alarmChange = false; + Global.CmWarningLogMd_List.Clear(); + for (var i = 0; i < 9; i++) { - var wanglist = Global.CheckWarng(tmpReadAlarmBytArr_D[i], plcitem); - Global.CmWarningLogMd_List.AddRange(wanglist); + var plcitem = $"{priStr}{index + i}"; + if (lastAlarm[i] != tmpReadAlarmBytArr_D[i]) + { + if (tmpReadAlarmBytArr_D[i] != 0) + { + var wanglist = Global.CheckWarng(tmpReadAlarmBytArr_D[i], plcitem); + Global.CmWarningLogMd_List.AddRange(wanglist); + } + lastAlarm[i] = tmpReadAlarmBytArr_D[i]; + alarmChange = true; + + } } - } - if (Global.CmWarningLogMd_List.Count() > 0) - { - Global.ShowMainFrmAlarmMsg(true, EventArgs.Empty); - } - else - { - Global.ShowMainFrmAlarmMsg(false, EventArgs.Empty); - } + + if (alarmChange) + { + ShowMainFrmAlarmMsg(); + } + + //if (Global.CmWarningLogMd_List.Count() > 0) + //{ + // ShowMainFrmAlarmMsg(true, EventArgs.Empty); + //} + //else + //{ + // ShowMainFrmAlarmMsg(false, EventArgs.Empty); + //} - // HandleWaringLog(tmpReadAlarmBytArr_D); - } + // HandleWaringLog(tmpReadAlarmBytArr_D); + } #if RELEASE } catch (Exception ex) @@ -499,11 +514,40 @@ namespace CleanMachineHMI #endif } + ushort[] lastAlarm = new ushort[9] { 0, 0, 0, 0, 0, 0, 0, 0, 0, }; + public delegate void AlarmChange(); + + public event AlarmChange OnShowMainFrmAlarmMsg; + + public void DoShowAlarm(object param) + { + if (!eventAlarmLock) + { + OnShowMainFrmAlarmMsg?.Invoke(); + } + + + + } + + public bool eventAlarmLock = false; + public void ShowMainFrmAlarmMsg() + { + if (_synchronization != null) + { + _synchronization.Post(DoShowAlarm, null); + } + + } + + + + //报警信息记录 private void HandleWaringLog(ushort[] tmpReadAlarmBytArr_D) { @@ -511,29 +555,200 @@ namespace CleanMachineHMI try { #endif - int index = 10; - string priStr = "D"; - string priWarnCode = "bit"; - for (int i = 0; i < tmpReadAlarmBytArr_D.Length; i++) - { - if (i <= 1) - {//D10~D11 报警 - char[] tmpCharArr = Convert.ToString(tmpReadAlarmBytArr_D[i], 2).PadLeft(16, '0').Reverse().ToArray(); - for (int j = 0; j < tmpCharArr.Length; j++) + int index = 10; + string priStr = "D"; + string priWarnCode = "bit"; + for (int i = 0; i < tmpReadAlarmBytArr_D.Length; i++) + { + if (i <= 1) + {//D10~D11 报警 + char[] tmpCharArr = Convert.ToString(tmpReadAlarmBytArr_D[i], 2).PadLeft(16, '0').Reverse().ToArray(); + for (int j = 0; j < tmpCharArr.Length; j++) + { + if (tmpCharArr[j] == '1') + {//当前报警 + Warning tmpMd = Global.BasWarningMd_List.Find(x => x.PlcItemCode == $"{priStr + (index + i)}" && x.WarningCode == $"{priWarnCode + j}" && x.WarningType == "1"); + if (tmpMd != null) + { + WarningLog warnLogTmp = Global.CmWarningLogMd_List.Find(y => y.WaringStatus == 0 && y.WarningHandleResult == 0 && y.WarningCode == tmpMd.WarningCode && y.PlcItemCode == tmpMd.PlcItemCode); + if (warnLogTmp != null) + {//找到报警项,并增加版本 + warnLogTmp.UpdateTime = DateTime.Now; + warnLogTmp.DataVersion += 1; + } + else + {//新报警增加记录 + Global.CmWarningLogMd_List.Add(new WarningLog + { + WarningCode = tmpMd.WarningCode, + WarningName = tmpMd.WarningName, + WarningType = tmpMd.WarningType, + WarningMessage = tmpMd.WarningMessage, + WarningTime = DateTime.Now, + PlcItemCode = tmpMd.PlcItemCode, + WaringStatus = 0, + WarningHandleResult = 0, + CreateBy = 1, + CreateTime = DateTime.Now, + UpdateBy = 1, + UpdateTime = DateTime.Now, + DataVersion = 0, + }); + } + } + #region 已删除 + + // string sql = $@"SELECT * FROM BAS_WARNING WHERE PLC_ITEM_CODE = '{priStr + (index + i)}' and WARNING_CODE = '{priWarnCode + i}' and WARNING_TYPE = '1'"; + // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; + // if (dt != null && dt.Rows.Count > 0) + // { + // string sql1 = $@" + // INSERT INTO CM_WARNING_LOG ( + // WARNING_CODE, + // WARNING_NAME, + // WARNING_TYPE, + // WARNING_MESSAGE, + // WARNING_TIME, + // PLC_ITEM_CODE, + // WARING_STATUS, + // WARNING_HANDLE_RESULT, + // CREATE_BY, + // CREATE_TIME, + // UPDATE_BY, + // UPDATE_TIME, + // DATA_VERSION + // ) + // SELECT + // '{dt.Rows[0]["WARNING_CODE"]}', + // '{dt.Rows[0]["WARNING_NAME"]}', + // '{dt.Rows[0]["WARNING_TYPE"]}', + // '{dt.Rows[0]["WARNING_MESSAGE"]}', + // datetime('now', 'localtime'), + // '{dt.Rows[0]["PLC_ITEM_CODE"]}', + // 0, + // 0, + // 1, + // datetime('now', 'localtime'), + // 1, + // datetime('now', 'localtime'), + // 0 + // WHERE NOT EXISTS (SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}') + // "; + // LeadDbHelperSQLite.ExecuteSql(sql1); + + // string sql2 = $@" + //UPDATE CM_WARNING_LOG set UPDATE_TIME = datetime('now', 'localtime'),DATA_VERSION = DATA_VERSION + 1 + // WHERE EXISTS(SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}') and WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}'; + // "; + // LeadDbHelperSQLite.ExecuteSql(sql2); + // } + + #endregion + } + else + {//当前报警项没有报警 + Warning tmpMd = Global.BasWarningMd_List.Find(x => x.PlcItemCode == $"{priStr + (index + i)}" && x.WarningCode == $"{priWarnCode + j}" && x.WarningType == "1"); + if (tmpMd != null) + {//之前有报警,则结束当前报警项 + WarningLog warnLogTmp = Global.CmWarningLogMd_List.Find(y => y.WaringStatus == 0 && y.WarningHandleResult == 0 && y.WarningCode == tmpMd.WarningCode && y.PlcItemCode == tmpMd.PlcItemCode); + if (warnLogTmp != null) + { + warnLogTmp.UpdateTime = DateTime.Now; + warnLogTmp.DataVersion += 1; + warnLogTmp.WaringStatus = 1; + warnLogTmp.WarningHandleResult = 1; + warnLogTmp.WarningHandleTime = DateTime.Now; + } + } + #region 已删除 + //string sql = $@"SELECT * FROM BAS_WARNING WHERE PLC_ITEM_CODE = '{priStr + (index + i)}' and WARNING_CODE = '{priWarnCode + i}' and WARNING_TYPE = '1'"; + //DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; + //if (dt != null && dt.Rows.Count > 0) + //{ + // string sql2 = $@" + // UPDATE CM_WARNING_LOG + // SET UPDATE_TIME = datetime('now', 'localtime'), + // DATA_VERSION = DATA_VERSION + 1, + // WARING_STATUS = 1, + // WARNING_HANDLE_RESULT = 1, + // WARNING_HANDLE_TIME = datetime('now', 'localtime') + // WHERE + // EXISTS ( SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 AND WARNING_HANDLE_RESULT = 0 AND WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' AND PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}' ) + // AND WARING_STATUS = 0 + // AND WARNING_HANDLE_RESULT = 0 + // AND WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' + // AND PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}'; + // "; + // LeadDbHelperSQLite.ExecuteSql(sql2); + //} + #endregion + } + } + } + else if (i == 2) { - if (tmpCharArr[j] == '1') - {//当前报警 - Warning tmpMd = Global.BasWarningMd_List.Find(x => x.PlcItemCode == $"{priStr + (index + i)}" && x.WarningCode == $"{priWarnCode + j}" && x.WarningType == "1"); + //char[] tmpCharArr = Convert.ToString(tmpReadAlarmBytArr_D[i], 2).PadLeft(16, '0').Reverse().ToArray(); + //if (tmpCharArr.Contains('1')) + //{ + // List warnLst = new List(); + // for (int j = 0; j < tmpCharArr.Length; j++) + // { + // if (tmpCharArr[j] == '1') + // { + // Bas_WarningMd tmpMd = GlobalHelper.BasWarningMd_List.Find(x => x.PlcItemCode == $"{priStr + (index + i)}" && x.WarningCode == $"{priWarnCode + j}" && x.WarningType == "1"); + // if (tmpMd != null) + // { + // warnLst.Add(tmpMd); + // } + // } + // } + // GlobalHelper.ShowWarningMsg(warnLst, new EventArgs()); + //} + } + else if (i >= 3 && i <= 9) + {//D13~D19报警 + if (tmpReadAlarmBytArr_D[i] == 0) + { + WarningLog warnLogTmp = Global.CmWarningLogMd_List.Find(y => y.WaringStatus == 0 && y.WarningHandleResult == 0 && y.PlcItemCode == $"{priStr + (index + i)}"); + if (warnLogTmp != null) + { + warnLogTmp.UpdateTime = DateTime.Now; + warnLogTmp.DataVersion += 1; + warnLogTmp.WaringStatus = 1; + warnLogTmp.WarningHandleResult = 1; + warnLogTmp.WarningHandleTime = DateTime.Now; + } + #region 已删除 + //string sql2 = $@" + // UPDATE CM_WARNING_LOG + // SET UPDATE_TIME = datetime('now', 'localtime'), + // DATA_VERSION = DATA_VERSION + 1, + // WARING_STATUS = 1, + // WARNING_HANDLE_RESULT = 1, + // WARNING_HANDLE_TIME = datetime('now', 'localtime') + // WHERE + // EXISTS ( SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 AND WARNING_HANDLE_RESULT = 0 AND WARNING_CODE = '{i}' AND PLC_ITEM_CODE is NULL ) + // AND WARING_STATUS = 0 + // AND WARNING_HANDLE_RESULT = 0 + // AND WARNING_CODE = 'i' + // AND PLC_ITEM_CODE is NULL; + // "; + //LeadDbHelperSQLite.ExecuteSql(sql2); + #endregion + } + else + {//根据报警编码,获取报警信息,根据读取顺序编号,组成PlcItemCode + Warning tmpMd = Global.BasWarningMd_List.Find(x => string.IsNullOrEmpty(x.PlcItemCode) && x.WarningCode == tmpReadAlarmBytArr_D[i].ToString() && x.WarningType == "2"); if (tmpMd != null) { - WarningLog warnLogTmp = Global.CmWarningLogMd_List.Find(y => y.WaringStatus == 0 && y.WarningHandleResult == 0 && y.WarningCode == tmpMd.WarningCode && y.PlcItemCode == tmpMd.PlcItemCode); + WarningLog warnLogTmp = Global.CmWarningLogMd_List.Find(y => y.WaringStatus == 0 && y.WarningHandleResult == 0 && y.WarningCode == tmpMd.WarningCode && y.PlcItemCode == $"{priStr + (index + i)}"); if (warnLogTmp != null) - {//找到报警项,并增加版本 + { warnLogTmp.UpdateTime = DateTime.Now; warnLogTmp.DataVersion += 1; } else - {//新报警增加记录 + { Global.CmWarningLogMd_List.Add(new WarningLog { WarningCode = tmpMd.WarningCode, @@ -541,7 +756,7 @@ namespace CleanMachineHMI WarningType = tmpMd.WarningType, WarningMessage = tmpMd.WarningMessage, WarningTime = DateTime.Now, - PlcItemCode = tmpMd.PlcItemCode, + PlcItemCode = $"{priStr + (index + i)}", WaringStatus = 0, WarningHandleResult = 0, CreateBy = 1, @@ -552,13 +767,14 @@ namespace CleanMachineHMI }); } } + #region 已删除 - // string sql = $@"SELECT * FROM BAS_WARNING WHERE PLC_ITEM_CODE = '{priStr + (index + i)}' and WARNING_CODE = '{priWarnCode + i}' and WARNING_TYPE = '1'"; - // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; - // if (dt != null && dt.Rows.Count > 0) - // { - // string sql1 = $@" + // string sql = $@"SELECT * FROM BAS_WARNING WHERE PLC_ITEM_CODE is NULL and WARNING_CODE = '{i}' and WARNING_TYPE = '2'"; + // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; + // if (dt != null && dt.Rows.Count > 0) + // { + // string sql1 = $@" // INSERT INTO CM_WARNING_LOG ( // WARNING_CODE, // WARNING_NAME, @@ -588,203 +804,31 @@ namespace CleanMachineHMI // 1, // datetime('now', 'localtime'), // 0 - // WHERE NOT EXISTS (SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}') + // WHERE NOT EXISTS (SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE is NULL) // "; - // LeadDbHelperSQLite.ExecuteSql(sql1); - - // string sql2 = $@" + // LeadDbHelperSQLite.ExecuteSql(sql1); + // string sql2 = $@" //UPDATE CM_WARNING_LOG set UPDATE_TIME = datetime('now', 'localtime'),DATA_VERSION = DATA_VERSION + 1 - // WHERE EXISTS(SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}') and WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}'; + // WHERE EXISTS(SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE is NULL) and WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and is NULL; // "; - // LeadDbHelperSQLite.ExecuteSql(sql2); - // } + // LeadDbHelperSQLite.ExecuteSql(sql2); + // } + #endregion - #endregion - } - else - {//当前报警项没有报警 - Warning tmpMd = Global.BasWarningMd_List.Find(x => x.PlcItemCode == $"{priStr + (index + i)}" && x.WarningCode == $"{priWarnCode + j}" && x.WarningType == "1"); - if (tmpMd != null) - {//之前有报警,则结束当前报警项 - WarningLog warnLogTmp = Global.CmWarningLogMd_List.Find(y => y.WaringStatus == 0 && y.WarningHandleResult == 0 && y.WarningCode == tmpMd.WarningCode && y.PlcItemCode == tmpMd.PlcItemCode); - if (warnLogTmp != null) - { - warnLogTmp.UpdateTime = DateTime.Now; - warnLogTmp.DataVersion += 1; - warnLogTmp.WaringStatus = 1; - warnLogTmp.WarningHandleResult = 1; - warnLogTmp.WarningHandleTime = DateTime.Now; - } - } - #region 已删除 - //string sql = $@"SELECT * FROM BAS_WARNING WHERE PLC_ITEM_CODE = '{priStr + (index + i)}' and WARNING_CODE = '{priWarnCode + i}' and WARNING_TYPE = '1'"; - //DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; - //if (dt != null && dt.Rows.Count > 0) - //{ - // string sql2 = $@" - // UPDATE CM_WARNING_LOG - // SET UPDATE_TIME = datetime('now', 'localtime'), - // DATA_VERSION = DATA_VERSION + 1, - // WARING_STATUS = 1, - // WARNING_HANDLE_RESULT = 1, - // WARNING_HANDLE_TIME = datetime('now', 'localtime') - // WHERE - // EXISTS ( SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 AND WARNING_HANDLE_RESULT = 0 AND WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' AND PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}' ) - // AND WARING_STATUS = 0 - // AND WARNING_HANDLE_RESULT = 0 - // AND WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' - // AND PLC_ITEM_CODE = '{dt.Rows[0]["PLC_ITEM_CODE"]}'; - // "; - // LeadDbHelperSQLite.ExecuteSql(sql2); - //} - #endregion } } - } - else if (i == 2) - { - //char[] tmpCharArr = Convert.ToString(tmpReadAlarmBytArr_D[i], 2).PadLeft(16, '0').Reverse().ToArray(); - //if (tmpCharArr.Contains('1')) - //{ - // List warnLst = new List(); - // for (int j = 0; j < tmpCharArr.Length; j++) - // { - // if (tmpCharArr[j] == '1') - // { - // Bas_WarningMd tmpMd = GlobalHelper.BasWarningMd_List.Find(x => x.PlcItemCode == $"{priStr + (index + i)}" && x.WarningCode == $"{priWarnCode + j}" && x.WarningType == "1"); - // if (tmpMd != null) - // { - // warnLst.Add(tmpMd); - // } - // } - // } - // GlobalHelper.ShowWarningMsg(warnLst, new EventArgs()); - //} - } - else if (i >= 3 && i <= 9) - {//D13~D19报警 - if (tmpReadAlarmBytArr_D[i] == 0) + else if (i > 9) { - WarningLog warnLogTmp = Global.CmWarningLogMd_List.Find(y => y.WaringStatus == 0 && y.WarningHandleResult == 0 && y.PlcItemCode == $"{priStr + (index + i)}"); - if (warnLogTmp != null) - { - warnLogTmp.UpdateTime = DateTime.Now; - warnLogTmp.DataVersion += 1; - warnLogTmp.WaringStatus = 1; - warnLogTmp.WarningHandleResult = 1; - warnLogTmp.WarningHandleTime = DateTime.Now; - } - #region 已删除 - //string sql2 = $@" - // UPDATE CM_WARNING_LOG - // SET UPDATE_TIME = datetime('now', 'localtime'), - // DATA_VERSION = DATA_VERSION + 1, - // WARING_STATUS = 1, - // WARNING_HANDLE_RESULT = 1, - // WARNING_HANDLE_TIME = datetime('now', 'localtime') - // WHERE - // EXISTS ( SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 AND WARNING_HANDLE_RESULT = 0 AND WARNING_CODE = '{i}' AND PLC_ITEM_CODE is NULL ) - // AND WARING_STATUS = 0 - // AND WARNING_HANDLE_RESULT = 0 - // AND WARNING_CODE = 'i' - // AND PLC_ITEM_CODE is NULL; - // "; - //LeadDbHelperSQLite.ExecuteSql(sql2); - #endregion - } - else - {//根据报警编码,获取报警信息,根据读取顺序编号,组成PlcItemCode - Warning tmpMd = Global.BasWarningMd_List.Find(x => string.IsNullOrEmpty(x.PlcItemCode) && x.WarningCode == tmpReadAlarmBytArr_D[i].ToString() && x.WarningType == "2"); - if (tmpMd != null) - { - WarningLog warnLogTmp = Global.CmWarningLogMd_List.Find(y => y.WaringStatus == 0 && y.WarningHandleResult == 0 && y.WarningCode == tmpMd.WarningCode && y.PlcItemCode == $"{priStr + (index + i)}"); - if (warnLogTmp != null) - { - warnLogTmp.UpdateTime = DateTime.Now; - warnLogTmp.DataVersion += 1; - } - else - { - Global.CmWarningLogMd_List.Add(new WarningLog - { - WarningCode = tmpMd.WarningCode, - WarningName = tmpMd.WarningName, - WarningType = tmpMd.WarningType, - WarningMessage = tmpMd.WarningMessage, - WarningTime = DateTime.Now, - PlcItemCode = $"{priStr + (index + i)}", - WaringStatus = 0, - WarningHandleResult = 0, - CreateBy = 1, - CreateTime = DateTime.Now, - UpdateBy = 1, - UpdateTime = DateTime.Now, - DataVersion = 0, - }); - } - } - - #region 已删除 - - // string sql = $@"SELECT * FROM BAS_WARNING WHERE PLC_ITEM_CODE is NULL and WARNING_CODE = '{i}' and WARNING_TYPE = '2'"; - // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; - // if (dt != null && dt.Rows.Count > 0) - // { - // string sql1 = $@" - // INSERT INTO CM_WARNING_LOG ( - // WARNING_CODE, - // WARNING_NAME, - // WARNING_TYPE, - // WARNING_MESSAGE, - // WARNING_TIME, - // PLC_ITEM_CODE, - // WARING_STATUS, - // WARNING_HANDLE_RESULT, - // CREATE_BY, - // CREATE_TIME, - // UPDATE_BY, - // UPDATE_TIME, - // DATA_VERSION - // ) - // SELECT - // '{dt.Rows[0]["WARNING_CODE"]}', - // '{dt.Rows[0]["WARNING_NAME"]}', - // '{dt.Rows[0]["WARNING_TYPE"]}', - // '{dt.Rows[0]["WARNING_MESSAGE"]}', - // datetime('now', 'localtime'), - // '{dt.Rows[0]["PLC_ITEM_CODE"]}', - // 0, - // 0, - // 1, - // datetime('now', 'localtime'), - // 1, - // datetime('now', 'localtime'), - // 0 - // WHERE NOT EXISTS (SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE is NULL) - // "; - // LeadDbHelperSQLite.ExecuteSql(sql1); - // string sql2 = $@" - //UPDATE CM_WARNING_LOG set UPDATE_TIME = datetime('now', 'localtime'),DATA_VERSION = DATA_VERSION + 1 - // WHERE EXISTS(SELECT 1 FROM CM_WARNING_LOG WHERE WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and PLC_ITEM_CODE is NULL) and WARING_STATUS = 0 and WARNING_HANDLE_RESULT = 0 and WARNING_CODE = '{dt.Rows[0]["WARNING_CODE"]}' and is NULL; - // "; - // LeadDbHelperSQLite.ExecuteSql(sql2); - // } - #endregion - + break; } } - else if (i > 9) - { - break; - } - } - List tmpLst = Global.CmWarningLogMd_List.FindAll(x => x.WarningHandleResult == 1 && x.WaringStatus == 1); - if (tmpLst.Count >= 10) - { - foreach (WarningLog item in tmpLst) + List tmpLst = Global.CmWarningLogMd_List.FindAll(x => x.WarningHandleResult == 1 && x.WaringStatus == 1); + if (tmpLst.Count >= 10) { - string sql1 = $@" + foreach (WarningLog item in tmpLst) + { + string sql1 = $@" INSERT INTO CM_WARNING_LOG ( WARNING_CODE, WARNING_NAME, @@ -818,21 +862,21 @@ namespace CleanMachineHMI '{item.DataVersion}' ); "; - LeadDbHelperSQLite.Execute(sql1); + LeadDbHelperSQLite.Execute(sql1); + } + Global.CmWarningLogMd_List.RemoveAll(x => x.WarningHandleResult == 1 && x.WaringStatus == 1); } - Global.CmWarningLogMd_List.RemoveAll(x => x.WarningHandleResult == 1 && x.WaringStatus == 1); - } - if (Global.CmWarningLogMd_List.FindAll(x => x.WarningHandleResult == 0 && x.WaringStatus == 0).Count > 0) - { - //frmMainNew.Show_ptb_Alarm(true); - Global.ShowMainFrmAlarmMsg(true, EventArgs.Empty); - } - else - { - //frmMainNew.Show_ptb_Alarm(false); - Global.ShowMainFrmAlarmMsg(false, EventArgs.Empty); - } + if (Global.CmWarningLogMd_List.FindAll(x => x.WarningHandleResult == 0 && x.WaringStatus == 0).Count > 0) + { + //frmMainNew.Show_ptb_Alarm(true); + ShowMainFrmAlarmMsg(); + } + else + { + //frmMainNew.Show_ptb_Alarm(false); + ShowMainFrmAlarmMsg(); + } #if RELEASE } catch (Exception ex) @@ -848,50 +892,50 @@ namespace CleanMachineHMI try { #endif - List changeItems = new List(); - bool[] readBytArr_X = master.ReadInputs(slaveAddress, 1024, 50); - if (readBytArr_X.Length > 0) - //if(true) - { - if (PlcItemMd_X_List != null && PlcItemMd_X_List.Count > 0) + List changeItems = new List(); + bool[] readBytArr_X = master.ReadInputs(slaveAddress, 1024, 50); + if (readBytArr_X.Length > 0) + //if(true) { - foreach (PlcItem item in PlcItemMd_X_List) + if (PlcItemMd_X_List != null && PlcItemMd_X_List.Count > 0) { - string value = ""; - if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) + foreach (PlcItem item in PlcItemMd_X_List) { - string PlcItemId = item.PlcItemId.ToString(); - string plcdatatype = item.PlcItemDataType.ToString(); - int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); - value = readBytArr_X[plcItemDeviationAddress].ToString(); - if (value != null) + string value = ""; + if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) { - if (item.PlcItemValue != value) + string PlcItemId = item.PlcItemId.ToString(); + string plcdatatype = item.PlcItemDataType.ToString(); + int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); + value = readBytArr_X[plcItemDeviationAddress].ToString(); + if (value != null) { - haschange = true; - item.PlcItemValue = value; - // this.DoShowX_Y_Status(item); - changeItems.Add(item); - // Global.ShowX_Y_Status(item, new EventArgs()); - Global.ShowSensorStatus(item, new EventArgs()); + if (item.PlcItemValue != value) + { + haschange = true; + item.PlcItemValue = value; + // this.DoShowX_Y_Status(item); + changeItems.Add(item); + // Global.ShowX_Y_Status(item, new EventArgs()); + Global.ShowSensorStatus(item, new EventArgs()); + } + + } + + + //Random r = new Random(); + //item.PlcItemValue = r.Next(0, 2) == 0 ? "False" : "True"; + + } - - - - - //Random r = new Random(); - //item.PlcItemValue = r.Next(0, 2) == 0 ? "False" : "True"; - - } - } - this.DoShowX_Y_Status(changeItems); + this.DoShowX_Y_Status(changeItems); + } } - } #if RELEASE } catch (Exception ex) @@ -909,42 +953,42 @@ namespace CleanMachineHMI #endif - List changeItems = new List(); - bool[] readBytArr_Y = master.ReadCoils(slaveAddress, 1280, 50); - if (readBytArr_Y.Length > 0) - //if(true) - { - if (PlcItemMd_Y_List != null && PlcItemMd_Y_List.Count > 0) + List changeItems = new List(); + bool[] readBytArr_Y = master.ReadCoils(slaveAddress, 1280, 50); + if (readBytArr_Y.Length > 0) + //if(true) { - foreach (PlcItem item in PlcItemMd_Y_List) + if (PlcItemMd_Y_List != null && PlcItemMd_Y_List.Count > 0) { - string value = ""; - if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) + foreach (PlcItem item in PlcItemMd_Y_List) { - string PlcItemId = item.PlcItemId.ToString(); - string plcdatatype = item.PlcItemDataType.ToString(); - int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); - value = readBytArr_Y[plcItemDeviationAddress].ToString(); - - if (value != null) + string value = ""; + if (!string.IsNullOrEmpty(item.PlcItemDeviationAddress)) { - if (item.PlcItemValue != value) - { - haschange = true; - item.PlcItemValue = value; - changeItems.Add(item); - // this.DoShowX_Y_Status(item); - // Global.ShowX_Y_Status(item, new EventArgs()); - } - } - //Random r = new Random(); - //item.PlcItemValue = r.Next(0, 2) == 0 ? "False" : "True"; - } - } + string PlcItemId = item.PlcItemId.ToString(); + string plcdatatype = item.PlcItemDataType.ToString(); + int plcItemDeviationAddress = Convert.ToInt32(item.PlcItemDeviationAddress); + value = readBytArr_Y[plcItemDeviationAddress].ToString(); - this.DoShowX_Y_Status(changeItems); + if (value != null) + { + if (item.PlcItemValue != value) + { + haschange = true; + item.PlcItemValue = value; + changeItems.Add(item); + // this.DoShowX_Y_Status(item); + // Global.ShowX_Y_Status(item, new EventArgs()); + } + } + //Random r = new Random(); + //item.PlcItemValue = r.Next(0, 2) == 0 ? "False" : "True"; + } + } + + this.DoShowX_Y_Status(changeItems); + } } - } #if RELEASE } catch (Exception ex) @@ -1009,83 +1053,83 @@ namespace CleanMachineHMI try { #endif - object retObj; - switch (itemType) - { - case PlcItemTypeDesc.M: + object retObj; + switch (itemType) + { + case PlcItemTypeDesc.M: - PlcItem item_M = PlcItemMd_M_List.Find(x => x.PlcItemCode == plcItemCode); - if (item_M == null) - { - return null; - } - if (string.IsNullOrEmpty(item_M.PlcItemValue)) - { - retObj = false; - } - else - { - retObj = bool.Parse(item_M.PlcItemValue); - } - break; - case PlcItemTypeDesc.D: - PlcItem item_D = PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode); - if (item_D == null) - { - return null; - } - if (string.IsNullOrEmpty(item_D.PlcItemValue)) - { - retObj = 0; - } - else - { - if (item_D.PlcItemDataLength == 2) + PlcItem item_M = PlcItemMd_M_List.Find(x => x.PlcItemCode == plcItemCode); + if (item_M == null) { - retObj = int.Parse(item_D.PlcItemValue); + return null; + } + if (string.IsNullOrEmpty(item_M.PlcItemValue)) + { + retObj = false; } else { - retObj = short.Parse(item_D.PlcItemValue); + retObj = bool.Parse(item_M.PlcItemValue); } + break; + case PlcItemTypeDesc.D: + PlcItem item_D = PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode); + if (item_D == null) + { + return null; + } + if (string.IsNullOrEmpty(item_D.PlcItemValue)) + { + retObj = 0; + } + else + { + if (item_D.PlcItemDataLength == 2) + { + retObj = int.Parse(item_D.PlcItemValue); + } + else + { + retObj = short.Parse(item_D.PlcItemValue); + } - } - break; - case PlcItemTypeDesc.X: - PlcItem item_X = PlcItemMd_X_List.Find(x => x.PlcItemCode == plcItemCode); - if (item_X == null) - { - return null; - } - if (string.IsNullOrEmpty(item_X.PlcItemValue)) - { - retObj = false; - } - else - { - retObj = bool.Parse(item_X.PlcItemValue); - } - break; - case PlcItemTypeDesc.Y: - PlcItem item_Y = PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode); - if (item_Y == null) - { - return null; - } - if (string.IsNullOrEmpty(item_Y.PlcItemValue)) - { - retObj = false; - } - else - { - retObj = bool.Parse(item_Y.PlcItemValue); - } - break; - default: - retObj = null; - break; - } - return retObj; + } + break; + case PlcItemTypeDesc.X: + PlcItem item_X = PlcItemMd_X_List.Find(x => x.PlcItemCode == plcItemCode); + if (item_X == null) + { + return null; + } + if (string.IsNullOrEmpty(item_X.PlcItemValue)) + { + retObj = false; + } + else + { + retObj = bool.Parse(item_X.PlcItemValue); + } + break; + case PlcItemTypeDesc.Y: + PlcItem item_Y = PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode); + if (item_Y == null) + { + return null; + } + if (string.IsNullOrEmpty(item_Y.PlcItemValue)) + { + retObj = false; + } + else + { + retObj = bool.Parse(item_Y.PlcItemValue); + } + break; + default: + retObj = null; + break; + } + return retObj; #if RELEASE } catch (Exception ex) @@ -1103,55 +1147,55 @@ namespace CleanMachineHMI try { #endif - switch (itemType) - { - case PlcItemTypeDesc.M: - PlcItem item_M = PlcItemMd_M_List.Find(x => x.PlcItemCode == plcItemCode); - if (item_M == null) - { + switch (itemType) + { + case PlcItemTypeDesc.M: + PlcItem item_M = PlcItemMd_M_List.Find(x => x.PlcItemCode == plcItemCode); + if (item_M == null) + { + return false; + } + master.WriteSingleCoil(slaveAddress, Convert.ToUInt16(item_M.PlcItemModbusAddress), bool.Parse(writeValue)); + return true; + case PlcItemTypeDesc.Y: + PlcItem item_Y = PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode); + if (item_Y == null) + { + return false; + } + master.WriteSingleCoil(slaveAddress, Convert.ToUInt16(item_Y.PlcItemModbusAddress), bool.Parse(writeValue)); + return true; + case PlcItemTypeDesc.D: + PlcItem item_D = PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode); + if (item_D == null) + { + return false; + } + + + if (item_D.PlcItemDataLength == 2) + { + var _value = int.Parse(writeValue); + var bytes = BitConverter.GetBytes(_value); + var v1 = BitConverter.ToUInt16(bytes, 0); + var v2 = BitConverter.ToUInt16(bytes, 2); + master.WriteMultipleRegisters(slaveAddress, Convert.ToUInt16(item_D.PlcItemModbusAddress), new ushort[] { v1, v2 }); + + + } + else + { + master.WriteSingleRegister(slaveAddress, Convert.ToUInt16(item_D.PlcItemModbusAddress), ushort.Parse(writeValue)); + } + + + + return true; + case PlcItemTypeDesc.X: return false; - } - master.WriteSingleCoil(slaveAddress, Convert.ToUInt16(item_M.PlcItemModbusAddress), bool.Parse(writeValue)); - return true; - case PlcItemTypeDesc.Y: - PlcItem item_Y = PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode); - if (item_Y == null) - { + default: return false; - } - master.WriteSingleCoil(slaveAddress, Convert.ToUInt16(item_Y.PlcItemModbusAddress), bool.Parse(writeValue)); - return true; - case PlcItemTypeDesc.D: - PlcItem item_D = PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode); - if (item_D == null) - { - return false; - } - - - if (item_D.PlcItemDataLength == 2) - { - var _value = int.Parse(writeValue); - var bytes = BitConverter.GetBytes(_value); - var v1 = BitConverter.ToUInt16(bytes, 0); - var v2 = BitConverter.ToUInt16(bytes, 2); - master.WriteMultipleRegisters(slaveAddress, Convert.ToUInt16(item_D.PlcItemModbusAddress), new ushort[] { v1, v2 }); - - - } - else - { - master.WriteSingleRegister(slaveAddress, Convert.ToUInt16(item_D.PlcItemModbusAddress), ushort.Parse(writeValue)); - } - - - - return true; - case PlcItemTypeDesc.X: - return false; - default: - return false; - } + } #if RELEASE } catch (Exception ex) @@ -1173,35 +1217,14 @@ namespace CleanMachineHMI try { #endif - int wcsToPlcHeartData = Convert.ToInt32(ReadPlcItem("PlcHeartbeatWriteData", PlcItemTypeDesc.D) == null ? 0 : ReadPlcItem("PlcHeartbeatWriteData", PlcItemTypeDesc.D)); - int plcToWcsHeartData = Convert.ToInt32(ReadPlcItem("PlcHeartbeatReadData", PlcItemTypeDesc.D) == null ? 0 : ReadPlcItem("PlcHeartbeatReadData", PlcItemTypeDesc.D)); - if (wcsToPlcHeartData == 0 && plcToWcsHeartData == 0) - { - WritePlcItem("PlcHeartbeatWriteData", "1", PlcItemTypeDesc.D); - wcsToPlcHeartDataNew = 1; - } - else if (wcsToPlcHeartDataNew == plcToWcsHeartData && plcToWcsHeartData != 0 && wcsToPlcHeartDataNew != 0) - { - if (plcToWcsHeartData >= 256) + int wcsToPlcHeartData = Convert.ToInt32(ReadPlcItem("PlcHeartbeatWriteData", PlcItemTypeDesc.D) == null ? 0 : ReadPlcItem("PlcHeartbeatWriteData", PlcItemTypeDesc.D)); + int plcToWcsHeartData = Convert.ToInt32(ReadPlcItem("PlcHeartbeatReadData", PlcItemTypeDesc.D) == null ? 0 : ReadPlcItem("PlcHeartbeatReadData", PlcItemTypeDesc.D)); + if (wcsToPlcHeartData == 0 && plcToWcsHeartData == 0) { + WritePlcItem("PlcHeartbeatWriteData", "1", PlcItemTypeDesc.D); wcsToPlcHeartDataNew = 1; - wcsToPlcHeartData = wcsToPlcHeartDataNew; } - else - { - wcsToPlcHeartData = wcsToPlcHeartDataNew + 1; - } - if (WritePlcItem("PlcHeartbeatWriteData", wcsToPlcHeartData.ToString(), PlcItemTypeDesc.D)) - { - IsConn = true; - HeartbeatTime = DateTime.Now; - wcsToPlcHeartDataNew = wcsToPlcHeartData; - frmMainNew.Show_Plc_Alarm("Serial port open success, PLC connect success!"); - } - } - else if (wcsToPlcHeartDataNew == 0 && plcToWcsHeartData != 0) - { - if (plcToWcsHeartData == wcsToPlcHeartData) + else if (wcsToPlcHeartDataNew == plcToWcsHeartData && plcToWcsHeartData != 0 && wcsToPlcHeartDataNew != 0) { if (plcToWcsHeartData >= 256) { @@ -1220,27 +1243,48 @@ namespace CleanMachineHMI frmMainNew.Show_Plc_Alarm("Serial port open success, PLC connect success!"); } } - } - else - { - WritePlcItem("PlcHeartbeatWriteData", wcsToPlcHeartDataNew.ToString(), PlcItemTypeDesc.D); - } + else if (wcsToPlcHeartDataNew == 0 && plcToWcsHeartData != 0) + { + if (plcToWcsHeartData == wcsToPlcHeartData) + { + if (plcToWcsHeartData >= 256) + { + wcsToPlcHeartDataNew = 1; + wcsToPlcHeartData = wcsToPlcHeartDataNew; + } + else + { + wcsToPlcHeartData = wcsToPlcHeartDataNew + 1; + } + if (WritePlcItem("PlcHeartbeatWriteData", wcsToPlcHeartData.ToString(), PlcItemTypeDesc.D)) + { + IsConn = true; + HeartbeatTime = DateTime.Now; + wcsToPlcHeartDataNew = wcsToPlcHeartData; + frmMainNew.Show_Plc_Alarm("Serial port open success, PLC connect success!"); + } + } + } + else + { + WritePlcItem("PlcHeartbeatWriteData", wcsToPlcHeartDataNew.ToString(), PlcItemTypeDesc.D); + } #if UseHeartbeat - if (DateTime.Now > HeartbeatTime.AddSeconds(5))//心跳超时 - { - isConn = false; - //报警处理。 - frmMainNew.Show_Plc_Alarm("PLC heartbeat data is abnormal, PLC loses connection!"); - if (ReConnNum % 5 == 0) + if (DateTime.Now > HeartbeatTime.AddSeconds(5))//心跳超时 { - ClosePlcConn(); - PlcInit(); + IsConn = false; + //报警处理。 + frmMainNew.Show_Plc_Alarm("PLC heartbeat data is abnormal, PLC loses connection!"); + if (ReConnNum % 5 == 0) + { + ClosePlcConn(); + PlcInit(); + } + ReConnNum++; } - ReConnNum++; - } #endif #if RELEASE diff --git a/CleanMachineHMI/frmLogin.cs b/CleanMachineHMI/frmLogin.cs index 06267e0..051f604 100644 --- a/CleanMachineHMI/frmLogin.cs +++ b/CleanMachineHMI/frmLogin.cs @@ -31,6 +31,7 @@ namespace CleanMachineHMI private void btnExit_Click(object sender, EventArgs e) { + Application.Exit(); } diff --git a/CleanMachineHMI/frmMainNew.cs b/CleanMachineHMI/frmMainNew.cs index 8885e4f..533f0c9 100644 --- a/CleanMachineHMI/frmMainNew.cs +++ b/CleanMachineHMI/frmMainNew.cs @@ -69,7 +69,7 @@ namespace CleanMachineHMI Type frmType = Global.FrmModelList.Where(s => s.FormType == enumFormType).FirstOrDefault().Form; if (isDefaultPage) { - + kryptonNavigator1.Pages[0].Controls.Clear(); //kryptonNavigator1.Pages[0].Text = enumFormType.ToString(); @@ -106,14 +106,14 @@ namespace CleanMachineHMI { KryptonPage tmpPage1 = new KryptonPage { Text = enumFormType.ToString(), Name = enumFormType.ToString() }; this.SetSingleControlText(tmpPage1); - + ButtonSpecAny bsa = new ButtonSpecAny(); bsa.Style = PaletteButtonStyle.FormClose; bsa.Type = PaletteButtonSpecStyle.FormClose; bsa.Tag = tmpPage1; bsa.Click += btnClose_Click; kryptonNavigator1.Pages.Add(tmpPage1); - + //if (enumFormType.ToString() != "IoMonitor") //{ kryptonNavigator1.SelectedPage = tmpPage1; @@ -146,13 +146,13 @@ namespace CleanMachineHMI { ButtonSpecAny bsa = sender as ButtonSpecAny; var page = bsa.Tag as KryptonPage; - - foreach(var ctrl in page.Controls) + + foreach (var ctrl in page.Controls) { if (ctrl is Control) { (ctrl as Control).Visible = false; - } + } } @@ -304,7 +304,7 @@ namespace CleanMachineHMI MothedShowMessage = new dlgShowMessage(Test); RefreshFrmHost = new dlgRefreshFrmHost(ShowWorkingPalletFullNumAlarm); //Show_ptb_Alarm = new dlgShow_ptb_Alarm(ShowPicAlarm); - Global.OnShowMainFrmAlarmMsg += ShowPicAlarm; + PlcOperationHelper.Instance.OnShowMainFrmAlarmMsg += ShowPicAlarm; Show_Plc_Alarm = new dlgShow_Plc_Alarm(ShowPlcAlarm); RemoveMaintainingFlag = new dlgShowMessage(ClearMaintainingFlag); timer.Enabled = true; @@ -368,17 +368,20 @@ namespace CleanMachineHMI label3Professional.Text = msg; })); } - private void ShowPicAlarm(object isShowFlag, EventArgs e) + private void ShowPicAlarm() { - Invoke(new Action(() => - { - ptb_Alarm.Visible = (bool)isShowFlag; - KryptonPage tmpPage = kryptonNavigator1.Pages.FirstOrDefault(x => x.Name == EnumFormType.PlcAlarmLog.ToString()); - if (tmpPage != null && (bool)isShowFlag) - { - frmPlcAlarmLog.RefreshFrmHost(false); - } - })); + + ptb_Alarm.Visible = Global.CmWarningLogMd_List.Count > 0; + + //Invoke(new Action(() => + //{ + // ptb_Alarm.Visible = (bool)isShowFlag; + // KryptonPage tmpPage = kryptonNavigator1.Pages.FirstOrDefault(x => x.Name == EnumFormType.PlcAlarmLog.ToString()); + // if (tmpPage != null && (bool)isShowFlag) + // { + // frmPlcAlarmLog.RefreshFrmHost(false); + // } + //})); } private void InitWarningMsg() { @@ -555,195 +558,204 @@ namespace CleanMachineHMI //var sysParameters = new CleanMachine.BLL.SYS.ParameterBLL().GetList(""); //int maintainAlarmTime = int.Parse(sysParameters.FirstOrDefault(m => m.ParameterCode == "MaintainAlarmTime").ParameterValue); //int maintainTime = int.Parse(sysParameters.FirstOrDefault(m => m.ParameterCode == "MaintainTime").ParameterValue); - + bool lastShowscrapRate = false; + int showdMinit = 0; while (Global.SysThIsRunFlag) { #if !DEBUG try { #endif - #region 定时器运行函数 - //当前托报废率超过10%,则提示 - string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0"; - DataTable dt_CurrPalletmsg = LeadDbHelperSQLite.Query(sql_CurrPalletmsg).Tables[0]; - if (dt_CurrPalletmsg != null && dt_CurrPalletmsg.Rows.Count > 0) - { - string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString(); - string sqlCurrPalletScrapNumMsg = $@"SELECT CURRENT_NUMBER FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}' AND CONTAMINATION_DTL_CODE = 'MoistureOrWet'"; - string sqlCurrPalletCountNumMsg = $@"SELECT SUM(CURRENT_NUMBER) FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}'"; - DataTable dt_CurrPalletScrapNumMsg = LeadDbHelperSQLite.Query(sqlCurrPalletScrapNumMsg).Tables[0]; - DataTable dt_CurrPalletCountNumMsg = LeadDbHelperSQLite.Query(sqlCurrPalletCountNumMsg).Tables[0]; - if (dt_CurrPalletScrapNumMsg != null && dt_CurrPalletScrapNumMsg.Rows.Count > 0 && dt_CurrPalletCountNumMsg != null && dt_CurrPalletCountNumMsg.Rows.Count > 0) + #region 定时器运行函数 + //当前托报废率超过10%,则提示 + string sql_CurrPalletmsg = $@"SELECT * FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0"; + DataTable dt_CurrPalletmsg = LeadDbHelperSQLite.Query(sql_CurrPalletmsg).Tables[0]; + bool showscrapRate = false; + if (dt_CurrPalletmsg != null && dt_CurrPalletmsg.Rows.Count > 0) { - int ScrapNumMsg = Convert.ToInt32(dt_CurrPalletScrapNumMsg.Rows[0][0]); - int CountNumMsg = Convert.ToInt32(dt_CurrPalletCountNumMsg.Rows[0][0]); - if (CountNumMsg == 0 || ScrapNumMsg == 0) + string palletCodeMsg = dt_CurrPalletmsg.Rows[0]["WORKING_PALLET_CODE"].ToString(); + string sqlCurrPalletScrapNumMsg = $@"SELECT CURRENT_NUMBER FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}' AND CONTAMINATION_DTL_CODE = 'MoistureOrWet'"; + string sqlCurrPalletCountNumMsg = $@"SELECT SUM(CURRENT_NUMBER) FROM VW_WORKING_PALLET_MSG WHERE WORKING_PALLET_CODE = '{palletCodeMsg}'"; + DataTable dt_CurrPalletScrapNumMsg = LeadDbHelperSQLite.Query(sqlCurrPalletScrapNumMsg).Tables[0]; + DataTable dt_CurrPalletCountNumMsg = LeadDbHelperSQLite.Query(sqlCurrPalletCountNumMsg).Tables[0]; + if (dt_CurrPalletScrapNumMsg != null && dt_CurrPalletScrapNumMsg.Rows.Count > 0 && dt_CurrPalletCountNumMsg != null && dt_CurrPalletCountNumMsg.Rows.Count > 0) { - BeginInvoke(new Action(() => { label1.Visible = false; })); - } - else - { - int scrapRate = Convert.ToInt32(Math.Round(decimal.Parse(((decimal)ScrapNumMsg / (decimal)CountNumMsg).ToString("0.000")), 2) * 100); - if (scrapRate >= 10) + int ScrapNumMsg = Convert.ToInt32(dt_CurrPalletScrapNumMsg.Rows[0][0]); + int CountNumMsg = Convert.ToInt32(dt_CurrPalletCountNumMsg.Rows[0][0]); + if (CountNumMsg == 0 || ScrapNumMsg == 0) { BeginInvoke(new Action(() => { label1.Visible = false; })); } else { - BeginInvoke(new Action(() => { label1.Visible = false; })); + int scrapRate = Convert.ToInt32(Math.Round(decimal.Parse(((decimal)ScrapNumMsg / (decimal)CountNumMsg).ToString("0.000")), 2) * 100); + if (scrapRate >= 10) + { + BeginInvoke(new Action(() => { label1.Visible = false; })); + } + else + { + BeginInvoke(new Action(() => { label1.Visible = false; })); + } } } - } - else - { - BeginInvoke(new Action(() => { label1.Visible = false; })); - } - } - - if (Global.UserInfo != null) - { - - int SysRunTime = (int)PlcOperationHelper.Instance.ReadPlcItem("SysRuningTime", PlcItemTypeDesc.D); - - if (SysRunTime != 0) - { - new CleanMachine.BLL.CM.DayWorkTimeBLL().UpdateTime(DateTime.Today, SysRunTime, Global.UserInfo.UserName); - - - int Minutes = (SysRunTime - CleanMachineHMI.Global.MaintainTime) / 60; - BeginInvoke(new Action(() => + else { - - kryptonLabel1.Text = Minutes + " Minutes"; - pictureBox1.Visible = Minutes >= Global.MaintainAlarmTime; - - - })); + BeginInvoke(new Action(() => { label1.Visible = false; })); + } } - } + + int Minutes = 0; + if (Global.UserInfo != null) + { + + int SysRunTime = (int)PlcOperationHelper.Instance.ReadPlcItem("SysRuningTime", PlcItemTypeDesc.D); + + if (SysRunTime != 0) + { + new CleanMachine.BLL.CM.DayWorkTimeBLL().UpdateTime(DateTime.Today, SysRunTime, Global.UserInfo.UserName); - //string sqlParam = $@"SELECT * FROM SYS_PARAMETER"; - //DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0]; - //if (dtParam != null && dtParam.Rows.Count > 0) - //{ - // int sysRuningTimeLen = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'SysRuningTimeLen'")[0]["PARAMETER_VALUE"]); - // int scrapRate = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'ScrapRate'")[0]["PARAMETER_VALUE"]); - // int maintainItemTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainItemTime'")[0]["PARAMETER_VALUE"]); - // int maintainAlarmTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainAlarmTime'")[0]["PARAMETER_VALUE"]); - // int maintainQuitTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainQuitTime'")[0]["PARAMETER_VALUE"]); - // int maintainFlag = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainFlag'")[0]["PARAMETER_VALUE"]); - // string maintainRelieveCode = dtParam.Select("PARAMETER_CODE = 'MaintainRelieveCode'")[0]["PARAMETER_VALUE"].ToString(); - // if (maintainFlag == 0) - // { - // bool isRun = (bool)PlcOperationHelper.Instance.ReadPlcItem("CleanMacRunStatusNew", PlcItemTypeDesc.M); + Minutes = (SysRunTime - CleanMachineHMI.Global.MaintainTime) / 60; - // if (isRun) - // { - // if (timerRunNUm == 60) - // { - // sysRuningTimeLen++; - // if (sysRuningTimeLen < maintainItemTime) - // { - // //pictureBox1.Visible = false; - // BeginInvoke(new Action(() => { pictureBox1.Visible = false; })); - // } - // else if (sysRuningTimeLen >= maintainItemTime && sysRuningTimeLen < maintainAlarmTime) - // { - // //pictureBox1.Visible = true; - // BeginInvoke(new Action(() => { pictureBox1.Visible = true; })); - // } - // else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime) - // { - // //BeginInvoke(new Action(() => - // //{ - // // pictureBox1.Visible = true; - // // if (!sysAlarmFrmShowFlag) - // // { - // // sysAlarmFrmShowFlag = true; - // // frmSysExitAlarm frm = new frmSysExitAlarm(); - // // //frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。"; - // // frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes."; - // // frm.TopLevel = true; - // // frm.ShowDialog(); - // // } - // //})); - // } - // else if (sysRuningTimeLen >= maintainQuitTime) - // { - // //BeginInvoke(new Action(() => - // //{ - // // pictureBox1.Visible = true; - // // string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0"; - // // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; - // // if (dt != null && dt.Rows.Count > 0) - // // { - // // if (!sysAlarmFrmShowFlag) - // // { - // // sysAlarmFrmShowFlag = true; - // // frmSysExitAlarm frm = new frmSysExitAlarm(); - // // frm.showMsg = $"The machine maintenance time has exceeded: [{(maintainQuitTime - sysRuningTimeLen)}] minutes, please complete the current operation tray as soon as possible, and carry out equipment maintenance !!!!!!"; - // // frm.TopLevel = true; - // // frm.ShowDialog(); - // // } - // // } - // // else - // // { - // // string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'"; - // // LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam); - // // PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M); - // // PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M); - // // PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M); - // // PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M); - // // Environment.Exit(0); - // // } - // //})); - // } - // string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'"; - // LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen); - // BeginInvoke(new Action(() => - // { - // kryptonLabel1.Text = sysRuningTimeLen + " Minutes"; - // })); - // timerRunNUm = 1; - // } - // else - // { - // timerRunNUm++; - // BeginInvoke(new Action(() => - // { - // kryptonLabel1.Text = sysRuningTimeLen + " Minutes"; - // })); - // } - // } + if (showdMinit != Minutes) + { + showdMinit = Minutes; + BeginInvoke(new Action(() => + { + + kryptonLabel1.Text = Minutes + " Minutes"; + pictureBox1.Visible = Minutes >= Global.MaintainAlarmTime; + + })); + } + + } + } + + + //string sqlParam = $@"SELECT * FROM SYS_PARAMETER"; + //DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0]; + //if (dtParam != null && dtParam.Rows.Count > 0) + //{ + // int sysRuningTimeLen = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'SysRuningTimeLen'")[0]["PARAMETER_VALUE"]); + // int scrapRate = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'ScrapRate'")[0]["PARAMETER_VALUE"]); + // int maintainItemTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainItemTime'")[0]["PARAMETER_VALUE"]); + // int maintainAlarmTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainAlarmTime'")[0]["PARAMETER_VALUE"]); + // int maintainQuitTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainQuitTime'")[0]["PARAMETER_VALUE"]); + // int maintainFlag = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainFlag'")[0]["PARAMETER_VALUE"]); + // string maintainRelieveCode = dtParam.Select("PARAMETER_CODE = 'MaintainRelieveCode'")[0]["PARAMETER_VALUE"].ToString(); + // if (maintainFlag == 0) + // { + // bool isRun = (bool)PlcOperationHelper.Instance.ReadPlcItem("CleanMacRunStatusNew", PlcItemTypeDesc.M); + + // if (isRun) + // { + + // if (timerRunNUm == 60) + // { + // sysRuningTimeLen++; + // if (sysRuningTimeLen < maintainItemTime) + // { + // //pictureBox1.Visible = false; + // BeginInvoke(new Action(() => { pictureBox1.Visible = false; })); + // } + // else if (sysRuningTimeLen >= maintainItemTime && sysRuningTimeLen < maintainAlarmTime) + // { + // //pictureBox1.Visible = true; + // BeginInvoke(new Action(() => { pictureBox1.Visible = true; })); + // } + // else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime) + // { + // //BeginInvoke(new Action(() => + // //{ + // // pictureBox1.Visible = true; + // // if (!sysAlarmFrmShowFlag) + // // { + // // sysAlarmFrmShowFlag = true; + // // frmSysExitAlarm frm = new frmSysExitAlarm(); + // // //frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。"; + // // frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes."; + // // frm.TopLevel = true; + // // frm.ShowDialog(); + // // } + // //})); + // } + // else if (sysRuningTimeLen >= maintainQuitTime) + // { + // //BeginInvoke(new Action(() => + // //{ + // // pictureBox1.Visible = true; + // // string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0"; + // // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0]; + // // if (dt != null && dt.Rows.Count > 0) + // // { + // // if (!sysAlarmFrmShowFlag) + // // { + // // sysAlarmFrmShowFlag = true; + // // frmSysExitAlarm frm = new frmSysExitAlarm(); + // // frm.showMsg = $"The machine maintenance time has exceeded: [{(maintainQuitTime - sysRuningTimeLen)}] minutes, please complete the current operation tray as soon as possible, and carry out equipment maintenance !!!!!!"; + // // frm.TopLevel = true; + // // frm.ShowDialog(); + // // } + // // } + // // else + // // { + // // string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'"; + // // LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam); + // // PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M); + // // PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M); + // // PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M); + // // PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M); + // // Environment.Exit(0); + // // } + // //})); + // } + // string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'"; + // LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen); + // BeginInvoke(new Action(() => + // { + // kryptonLabel1.Text = sysRuningTimeLen + " Minutes"; + // })); + // timerRunNUm = 1; + // } + // else + // { + // timerRunNUm++; + // BeginInvoke(new Action(() => + // { + // kryptonLabel1.Text = sysRuningTimeLen + " Minutes"; + // })); + // } + // } - // } - // else - // { - // BeginInvoke(new Action(() => - // { - // pictureBox1.Visible = true; - // })); - // } - //} + // } + // else + // { + // BeginInvoke(new Action(() => + // { + // pictureBox1.Visible = true; + // })); + // } + //} - #region 定期清理历史业务数据 -- 数据保存2个月 - //string sqlZbkWorkingPallet = $@"DELETE FROM ZBK_WORKING_PALLET WHERE julianday('now') - julianday(UPDATE_TIME) > 30"; - //string sqlZbkWorkingPalletDtl = $@"DELETE FROM ZBK_WORKING_PALLET_DTL WHERE julianday('now') - julianday(UPDATE_TIME) > 30"; - //LeadDbHelperSQLite.Execute(sqlZbkWorkingPallet); - //LeadDbHelperSQLite.Execute(sqlZbkWorkingPalletDtl); - #endregion + #region 定期清理历史业务数据 -- 数据保存2个月 + //string sqlZbkWorkingPallet = $@"DELETE FROM ZBK_WORKING_PALLET WHERE julianday('now') - julianday(UPDATE_TIME) > 30"; + //string sqlZbkWorkingPalletDtl = $@"DELETE FROM ZBK_WORKING_PALLET_DTL WHERE julianday('now') - julianday(UPDATE_TIME) > 30"; + //LeadDbHelperSQLite.Execute(sqlZbkWorkingPallet); + //LeadDbHelperSQLite.Execute(sqlZbkWorkingPalletDtl); + #endregion - // PlcOperationHelper.Instance.HeartbeatDetection(); - ShowWarningMsg(); - #endregion + // PlcOperationHelper.Instance.HeartbeatDetection(); + ShowWarningMsg(); + #endregion #if RELEASE - } + } catch (Exception ex) { @@ -786,9 +798,21 @@ namespace CleanMachineHMI { Task.Run(async delegate { + + if (Global.UserInfo != null) + + { + int SysRunTime = (int)PlcOperationHelper.Instance.ReadPlcItem("SysRuningTime", PlcItemTypeDesc.D); + + if (SysRunTime != 0) + { + new CleanMachine.BLL.CM.DayWorkTimeBLL().UpdateTime(DateTime.Today, SysRunTime, Global.UserInfo.UserName); + } + } + timer.Enabled = false; Global.SysThIsRunFlag = false; - Global.eventAlarmLock = true; + PlcOperationHelper.Instance.eventAlarmLock = true; if (Global.CmWarningLogMd_List.Count > 0) { foreach (WarningLog item in Global.CmWarningLogMd_List) @@ -890,7 +914,7 @@ namespace CleanMachineHMI private void frmMainNew_Shown(object sender, EventArgs e) { - // InitControl(); + // InitControl(); } private void InitControl() {