using DataBlockHelper; using DataBlockHelper.DBHelpers; using DevExpress.XtraSplashScreen; 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.Data; 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(); MCLabelEntity LabelE = new MCLabelEntity(); MCCombobox MotorSelect; public void Run(RuntimeParameter runtime) { RunIni(runtime); Controls = GetAllControls(); SetAllControls(); MotorSelect = Controls.FirstOrDefault(x => x != null && x.Name == "MotorSelect") as MCCombobox; 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); ControlsImprot.ControlImport(LabelE, 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; } DataTable dataTable = new DataTable(); dataTable.Columns.Add("CmbValue", typeof(string)); dataTable.Columns.Add("CmbDisplay", typeof(string)); DataRow dr = dataTable.NewRow(); dr[0] = "0"; dr[1] = "二级除尘器除尘风机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "2"; dr[1] = "大仓 A 组除尘风机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "4"; dr[1] = "大仓 B 组除尘风机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "6"; dr[1] = "大仓 C 组除尘风机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "8"; dr[1] = "大仓 D 组除尘风机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "10"; dr[1] = "大仓 E 组除尘风机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "12"; dr[1] = "磨粉分析机电机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "14"; dr[1] = "磨粉除尘风机电机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "16"; dr[1] = "磨粉罗茨风机电机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "18"; dr[1] = "磨粉皮带正转电机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "20"; dr[1] = "磨粉皮带反转电机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "22"; dr[1] = "磨粉主机电机"; //主接触器 dataTable.Rows.Add(dr); //dr = dataTable.NewRow(); //dr[0] = "24"; //dr[1] = "磨粉主机电机星型接触器"; //dataTable.Rows.Add(dr); //dr = dataTable.NewRow(); //dr[0] = "26"; //dr[1] = "磨粉主机电机三角型接触器"; //dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "28"; dr[1] = "磨粉风机电机"; //主接触器 dataTable.Rows.Add(dr); //dr = dataTable.NewRow(); //dr[0] = "30"; //dr[1] = "磨粉风机机电机星型接触器"; //dataTable.Rows.Add(dr); //dr = dataTable.NewRow(); //dr[0] = "32"; //dr[1] = "磨粉风机机电机三角型接触器"; //dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "34"; dr[1] = "筛分机 A 电机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "48"; dr[1] = "筛分机 B 电机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "62"; dr[1] = "筛分机 C 电机"; dataTable.Rows.Add(dr); dr = dataTable.NewRow(); dr[0] = "76"; dr[1] = "磨粉旋转阀电机"; dataTable.Rows.Add(dr); MotorSelect.DataSource = dataTable; } private void GetPlcValue(object sender, EventArgs e) { DB191 = new DB191Helper(); SetPanelA(); SetPanelB(); SetPanelC(); GetMotorStatus(); GetMotorStatus2(); try { if (GetAllControls().Count == 0) { timer.Stop(); timer.Dispose(); } } finally {} } private void GetMotorStatus() { string str = MotorSelect.MCValue.ToString(); byte byt = ControlsHelper.ReadMode(str); int value = Convert.ToInt32(str); if (value <= 32) { if (!byt.GetBit(0) && byt.GetBit(1)) { LabelE.NowMode.MCValue = "自动"; } else if (byt.GetBit(0) && !byt.GetBit(1)) { LabelE.NowMode.MCValue = "手动"; } else { LabelE.NowMode.MCValue = "未设置"; } if (!byt.GetBit(2) && byt.GetBit(3)) { LabelE.NowManual.MCValue = "关闭"; } else if (byt.GetBit(2) && !byt.GetBit(3)) { LabelE.NowManual.MCValue = "开启"; } else { LabelE.NowManual.MCValue = "未设置"; } //if (!byt.GetBit(4) && byt.GetBit(5)) //{ // LabelE.NowAuto.MCValue = "关闭"; //} //else if (byt.GetBit(4) && !byt.GetBit(5)) //{ // LabelE.NowAuto.MCValue = "开启"; //} //else //{ // LabelE.NowAuto.MCValue = "未设置"; //} } else { if (!byt.GetBit(0) && byt.GetBit(1)) { LabelE.NowMode.MCValue = "手动"; } else if (byt.GetBit(0) && !byt.GetBit(1)) { LabelE.NowMode.MCValue = "自动"; } else { LabelE.NowMode.MCValue = "未设置"; } //if (!byt.GetBit(2) && byt.GetBit(3)) //{ // LabelE.NowAuto.MCValue = "关闭"; //} //else if (byt.GetBit(2) && !byt.GetBit(3)) //{ // LabelE.NowAuto.MCValue = "开启"; //} //else //{ // LabelE.NowAuto.MCValue = "未设置"; //} if (!byt.GetBit(4) && byt.GetBit(5)) { LabelE.NowManual.MCValue = "关闭"; } else if (byt.GetBit(4) && !byt.GetBit(5)) { LabelE.NowManual.MCValue = "开启"; } else { LabelE.NowManual.MCValue = "未设置"; } } } /// /// 去换一个方式 /// private void GetMotorStatus2() { int str = MotorSelect.SelectedIndex; var dic= DB191.GetDianJi; //1 手动 if (dic[str]) { LabelE.NowMode.MCValue = "手动"; } else { LabelE.NowMode.MCValue = "自动"; } } 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); } } }