using DataBlockHelper.DBHelpers; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.LjDeliverControlBoard.Entity; using Mesnac.Action.ChemicalWeighing.Util; using Mesnac.Controls.ChemicalWeighing; using Mesnac.Controls.Default; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Timer = System.Windows.Forms.Timer; namespace Mesnac.Action.ChemicalWeighing.LjDeliverControlBoard { public class InitAction : ChemicalWeighingAction, IAction { Timer timer; DB191Helper DB191 = new DB191Helper(); List Controls; MCButtonEntity ButtonE = new MCButtonEntity(); MCRadioButtonEntity RadioButtonE = new MCRadioButtonEntity(); SwitchLightEntity SwitchLightE = new SwitchLightEntity(); public void Run(RuntimeParameter runtime) { RunIni(runtime); Controls = GetAllControls(); SetAllControls(); InitOnce(); ButtonE.BoardStartA.MouseDown += MouseDown; ButtonE.BoardStartB.MouseDown += MouseDown; ButtonE.BoardStartC.MouseDown += MouseDown; ButtonE.BoardStopA.MouseDown += MouseDown; ButtonE.BoardStopB.MouseDown += MouseDown; ButtonE.BoardStopC.MouseDown += MouseDown; ButtonE.AlarmClearA.MouseDown += MouseDown; ButtonE.AlarmClearB.MouseDown += MouseDown; ButtonE.AlarmClearC.MouseDown += MouseDown; ButtonE.BoardStartA.MouseUp += MouseUp; ButtonE.BoardStartB.MouseUp += MouseUp; ButtonE.BoardStartC.MouseUp += MouseUp; ButtonE.BoardStopA.MouseUp += MouseUp; ButtonE.BoardStopB.MouseUp += MouseUp; ButtonE.BoardStopC.MouseUp += MouseUp; ButtonE.AlarmClearA.MouseUp += MouseUp; ButtonE.AlarmClearB.MouseUp += MouseUp; ButtonE.AlarmClearC.MouseUp += MouseUp; timer = new Timer(); timer.Interval = 1000; timer.Enabled = true; timer.Tick += GetPlcValue;//添加事件 } private void MouseDown(object sender, MouseEventArgs e) { if (sender == ButtonE.BoardStartA) { DB191WriteHelper.SetStartA(true); } else if (sender == ButtonE.BoardStartB) { DB191WriteHelper.SetStartB(true); } else if (sender == ButtonE.BoardStartC) { DB191WriteHelper.SetStartC(true); } else if (sender == ButtonE.BoardStopA) { DB191WriteHelper.SetStopA(true); } else if (sender == ButtonE.BoardStopB) { DB191WriteHelper.SetStopB(true); } else if (sender == ButtonE.BoardStopC) { DB191WriteHelper.SetStopC(true); } else if (sender == ButtonE.AlarmClearA) { DB191WriteHelper.SetClearAlarmA(true); } else if (sender == ButtonE.AlarmClearB) { DB191WriteHelper.SetClearAlarmB(true); } else if (sender == ButtonE.AlarmClearC) { DB191WriteHelper.SetClearAlarmC(true); } } private void MouseUp(object sender, MouseEventArgs e) { if (sender == ButtonE.BoardStartA) { DB191WriteHelper.SetStartA(false); } else if (sender == ButtonE.BoardStartB) { DB191WriteHelper.SetStartB(false); } else if (sender == ButtonE.BoardStartC) { DB191WriteHelper.SetStartC(false); } else if (sender == ButtonE.BoardStopA) { DB191WriteHelper.SetStopA(false); } else if (sender == ButtonE.BoardStopB) { DB191WriteHelper.SetStopB(false); } else if (sender == ButtonE.BoardStopC) { DB191WriteHelper.SetStopC(false); } else if (sender == ButtonE.AlarmClearA) { DB191WriteHelper.SetClearAlarmA(false); } else if (sender == ButtonE.AlarmClearB) { DB191WriteHelper.SetClearAlarmB(false); } else if (sender == ButtonE.AlarmClearC) { DB191WriteHelper.SetClearAlarmC(false); } } private void SetAllControls() { ControlsImprot.ControlImport(ButtonE, Controls); ControlsImprot.ControlImport(RadioButtonE, Controls); ControlsImprot.ControlImport(SwitchLightE, Controls); } private void InitOnce() { if (DB191.GetPanelOnOff()[0]) { ButtonE.BoardOnA.Text = "关闭面板"; ButtonE.BoardOnA.BackColor = System.Drawing.Color.LightGreen; } else { ButtonE.BoardOnA.Text = "面板启用"; ButtonE.BoardOnA.BackColor = System.Drawing.Color.Yellow; } if (DB191.GetPanelOnOff()[1]) { ButtonE.BoardOnB.Text = "关闭面板"; ButtonE.BoardOnB.BackColor = System.Drawing.Color.LightGreen; } else { ButtonE.BoardOnB.Text = "面板启用"; ButtonE.BoardOnB.BackColor = System.Drawing.Color.Yellow; } if (DB191.GetPanelOnOff()[2]) { ButtonE.BoardOnC.Text = "关闭面板"; ButtonE.BoardOnC.BackColor = System.Drawing.Color.LightGreen; } else { ButtonE.BoardOnC.Text = "面板启用"; ButtonE.BoardOnC.BackColor = System.Drawing.Color.Yellow; } } private void GetPlcValue(object sender, EventArgs e) { DB191 = new DB191Helper(); SetPanelA(); SetPanelB(); SetPanelC(); } private void SetPanelA() { ControlsImprot.SetSwitchLight(SwitchLightE.SGLAA, DB191.ControlPanel_A.siloGroupLamp1); ControlsImprot.SetSwitchLight(SwitchLightE.SGLBA, DB191.ControlPanel_A.siloGroupLamp2); ControlsImprot.SetSwitchLight(SwitchLightE.SGLCA, DB191.ControlPanel_A.siloGroupLamp3); ControlsImprot.SetSwitchLight(SwitchLightE.SGLDA, DB191.ControlPanel_A.siloGroupLamp4); ControlsImprot.SetSwitchLight(SwitchLightE.SGLEA, DB191.ControlPanel_A.siloGroupLamp5); ControlsImprot.SetSwitchLight(SwitchLightE.SLAA, DB191.ControlPanel_A.siloLamp1); ControlsImprot.SetSwitchLight(SwitchLightE.SLBA, DB191.ControlPanel_A.siloLamp2); ControlsImprot.SetSwitchLight(SwitchLightE.SLCA, DB191.ControlPanel_A.siloLamp3); ControlsImprot.SetSwitchLight(SwitchLightE.SLDA, DB191.ControlPanel_A.siloLamp4); ControlsImprot.SetSwitchLight(SwitchLightE.StartLightA, DB191.ControlPanel_A.startLamp); ControlsImprot.SetSwitchLight(SwitchLightE.StopLightA, false, DB191.ControlPanel_A.stopLamp); ControlsImprot.SetSwitchLight(SwitchLightE.RoadCorrectA, DB191.ControlPanel_A.pathOkLamp); ControlsImprot.SetSwitchLight(SwitchLightE.TubeCleanA, DB191.ControlPanel_A.cleanLamp); ControlsImprot.SetSwitchLight(SwitchLightE.ActionBottleFullA, DB191.ControlPanel_A.siloFullLamp); ControlsImprot.SetSwitchLight(SwitchLightE.AlarmLightA, false, DB191.ControlPanel_A.Buzzer); } private void SetPanelB() { ControlsImprot.SetSwitchLight(SwitchLightE.SGLAB, DB191.ControlPanel_B.siloGroupLamp1); ControlsImprot.SetSwitchLight(SwitchLightE.SGLBB, DB191.ControlPanel_B.siloGroupLamp2); ControlsImprot.SetSwitchLight(SwitchLightE.SGLCB, DB191.ControlPanel_B.siloGroupLamp3); ControlsImprot.SetSwitchLight(SwitchLightE.SGLDB, DB191.ControlPanel_B.siloGroupLamp4); ControlsImprot.SetSwitchLight(SwitchLightE.SGLEB, DB191.ControlPanel_B.siloGroupLamp5); ControlsImprot.SetSwitchLight(SwitchLightE.SLAB, DB191.ControlPanel_B.siloLamp1); ControlsImprot.SetSwitchLight(SwitchLightE.SLBB, DB191.ControlPanel_B.siloLamp2); ControlsImprot.SetSwitchLight(SwitchLightE.SLCB, DB191.ControlPanel_B.siloLamp3); ControlsImprot.SetSwitchLight(SwitchLightE.SLDB, DB191.ControlPanel_B.siloLamp4); ControlsImprot.SetSwitchLight(SwitchLightE.StartLightB, DB191.ControlPanel_B.startLamp); ControlsImprot.SetSwitchLight(SwitchLightE.StopLightB, false, DB191.ControlPanel_B.stopLamp); ControlsImprot.SetSwitchLight(SwitchLightE.RoadCorrectB, DB191.ControlPanel_B.pathOkLamp); ControlsImprot.SetSwitchLight(SwitchLightE.TubeCleanB, DB191.ControlPanel_B.cleanLamp); ControlsImprot.SetSwitchLight(SwitchLightE.ActionBottleFullB, DB191.ControlPanel_B.siloFullLamp); ControlsImprot.SetSwitchLight(SwitchLightE.AlarmLightB, false, DB191.ControlPanel_B.Buzzer); } private void SetPanelC() { ControlsImprot.SetSwitchLight(SwitchLightE.SGLAC, DB191.ControlPanel_C.siloGroupLamp1); ControlsImprot.SetSwitchLight(SwitchLightE.SGLBC, DB191.ControlPanel_C.siloGroupLamp2); ControlsImprot.SetSwitchLight(SwitchLightE.SGLCC, DB191.ControlPanel_C.siloGroupLamp3); ControlsImprot.SetSwitchLight(SwitchLightE.SGLDC, DB191.ControlPanel_C.siloGroupLamp4); ControlsImprot.SetSwitchLight(SwitchLightE.SGLEC, DB191.ControlPanel_C.siloGroupLamp5); ControlsImprot.SetSwitchLight(SwitchLightE.SLAC, DB191.ControlPanel_C.siloLamp1); ControlsImprot.SetSwitchLight(SwitchLightE.SLBC, DB191.ControlPanel_C.siloLamp2); ControlsImprot.SetSwitchLight(SwitchLightE.SLCC, DB191.ControlPanel_C.siloLamp3); ControlsImprot.SetSwitchLight(SwitchLightE.SLDC, DB191.ControlPanel_C.siloLamp4); ControlsImprot.SetSwitchLight(SwitchLightE.StartLightC, DB191.ControlPanel_C.startLamp); ControlsImprot.SetSwitchLight(SwitchLightE.StopLightC, false, DB191.ControlPanel_C.stopLamp); ControlsImprot.SetSwitchLight(SwitchLightE.RoadCorrectC, DB191.ControlPanel_C.pathOkLamp); ControlsImprot.SetSwitchLight(SwitchLightE.TubeCleanC, DB191.ControlPanel_C.cleanLamp); ControlsImprot.SetSwitchLight(SwitchLightE.ActionBottleFullC, DB191.ControlPanel_C.siloFullLamp); ControlsImprot.SetSwitchLight(SwitchLightE.AlarmLightC, false, DB191.ControlPanel_C.Buzzer); } } }