using Mesnac.Action.ChemicalWeighing.Entity; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMachinery { public partial class ElectronicMachinery : Form { BasePlcHelper Plc = BasePlcHelper.Instance; int ManualModeIsOpen; int ManualModeIsStart; int AutoModeIsStart; string DmName; public ElectronicMachinery() { InitializeComponent(); ManualModeIsOpen = GetDataNameValue("_ManualMode").NowValue.ToInt(); ManualModeIsStart = GetDataNameValue("_StartManual").NowValue.ToInt(); AutoModeIsStart = Plc.DM1GDP01_StartAuto.NowValue.ToInt(); if (ManualModeIsOpen == 0) { ManualMode.Text = "切换手动模式"; ModeLable.Text = "自动模式"; if(ManualModeIsStart == 0) { OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; } else { OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; } } else { ManualMode.Text = "切换自动模式"; ModeLable.Text = "手动模式"; if (AutoModeIsStart == 0) { OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; } else { OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; } } } public DataKeyValue GetDataNameValue(string dmValue) { return new DataKeyValue(DmName + dmValue); } private void DMChange_SelectedIndexChanged(object sender, EventArgs e) { switch (DMChange.Text) { case "二级除尘器除尘风机": DmName = "DM1GDP01"; break; case "大A组除尘风机": DmName = "DM1ASIG01"; break; case "大仓B组除尘风机": DmName = "DM1BSIG01"; break; case "大仓C组除尘风机": DmName = "DM1CSIG01"; break; case "大仓D组除尘风机": DmName = "DM1DSIG01"; break; case "磨粉分析机电机": DmName = "DM1GDS01"; break; case "磨粉除尘风机电机": DmName = "DM1GDS02"; break; case "磨粉罗茨风机电机": DmName = "DM1GDS03"; break; case "磨粉皮带正转电机": DmName = "DM1GDS04"; break; case "磨粉皮带反转电机": DmName = "DM1GDS05"; break; } } private void ManualMode_Click(object sender, EventArgs e) { if(ManualModeIsOpen == 0) { Plc.PlcWriteByDataKey(GetDataNameValue("_ManualMode"), new Object[] { 1 }); Plc.PlcWriteByDataKey(GetDataNameValue("_AutoMode"), new Object[] { 0 }); ManualMode.Text = "切换自动模式"; ModeLable.Text = "手动模式"; ManualModeIsOpen = 1; if (ManualModeIsStart == 0) { OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; } else { OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; } } else { Plc.PlcWriteByDataKey(GetDataNameValue("_ManualMode"), new Object[] { 0 }); Plc.PlcWriteByDataKey(GetDataNameValue("_AutoMode"), new Object[] { 1 }); ManualMode.Text = "切换手动模式"; ModeLable.Text = "自动模式"; ManualModeIsOpen = 0; if (AutoModeIsStart == 0) { OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; } else { OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; } } } private void OnOffControl_Click(object sender, EventArgs e) { if (ManualModeIsOpen == 0) { if (AutoModeIsStart == 0) { Plc.PlcWriteByDataKey(GetDataNameValue("_StartAuto"), new Object[] { 1 }); Plc.PlcWriteByDataKey(GetDataNameValue("_StopAuto"), new Object[] { 0 }); OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; AutoModeIsStart = 1; } else { Plc.PlcWriteByDataKey(GetDataNameValue("_StartAuto"), new Object[] { 0 }); Plc.PlcWriteByDataKey(GetDataNameValue("_StopAuto"), new Object[] { 1 }); OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; AutoModeIsStart = 0; } } else { if (ManualModeIsStart == 0) { Plc.PlcWriteByDataKey(GetDataNameValue("_StartManual"), new Object[] { 1 }); Plc.PlcWriteByDataKey(GetDataNameValue("_StopManual"), new Object[] { 0 }); OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; ManualModeIsStart = 1; } else { Plc.PlcWriteByDataKey(GetDataNameValue("_StartManual"), new Object[] { 0 }); Plc.PlcWriteByDataKey(GetDataNameValue("_StopManual"), new Object[] { 1 }); OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; ManualModeIsStart = 0; } } } private void AlarmReset_Click(object sender, EventArgs e) { Plc.PlcWriteByDataKey(GetDataNameValue("_AlarmReset"), new Object[] { 1 }); } private void Running_Click(object sender, EventArgs e) { Plc.PlcWriteByDataKey(GetDataNameValue("_Running"), new Object[] { 1 }); } private void Run_Click(object sender, EventArgs e) { Plc.PlcWriteByDataKey(GetDataNameValue("_Run"), new Object[] { 1 }); } /*Plc.PlcWriteByDataKey(GetDataKeyValue(""), new Object[] { 1 }); GetDataKeyValue("").LastValue*/ } }