using DevExpress.DataAccess.Native.ExpressionEditor; 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; using Mesnac.DoUtils; using Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper; namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ElectronicMachinery { public partial class ElectronicMachinery : Form { BasePlcHelper Plc = BasePlcHelper.Instance; int ManualModeIsOpen; int ManualModeIsStart; int AutoModeIsStart; string DmName = "DM1GDP01"; public ElectronicMachinery() { InitializeComponent(); DoControl AlarmLight = DoControl.Instance; DoControl.Instance.ComOn(); DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On); StateMonitor(); } /// /// 状态监测类 /// private void StateMonitor() { ManualModeIsOpen = GetDataToInt("_ManualMode"); ManualModeIsStart = GetDataToInt("_StartManual"); AutoModeIsStart = GetDataToInt("_StartAuto"); if (ManualModeIsOpen == 0) { ManualMode.Text = "切换手动模式"; ModeLable.Text = "自动模式"; if (AutoModeIsStart == 0) { OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; } else { OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; } } else { ManualMode.Text = "切换自动模式"; ModeLable.Text = "手动模式"; if (ManualModeIsStart == 0) { OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; } else { OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; } } } /// /// 根据属性名和现在选择的数据块名得到PLC数据块的具体引用 /// /// 数据块属性名 /// private DataKeyValue GetDataNameValue(string dmValue) { return new DataKeyValue(DmName + dmValue); } /// /// 从PLC中读取值 /// /// 要读取的属性 /// private int GetDataToInt(String dmValue) { return GetDataNameValue(dmValue).NowValue.ToInt(); } /// /// 向PLC中写入值 /// /// 要写入的属性 /// 写入的值 private void SetDataValue(String dmValue, int value) { Plc.PlcWriteByDataKey(GetDataNameValue(dmValue), new Object[] { value }); } /// /// 列表框,选择设备对应数据块 /// /// /// 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; } StateMonitor(); ICSharpCode.Core.LoggingService.Debug(DMChange.Text + "电机切换成功!"); } /// /// 模式切换 /// /// /// private void ManualMode_Click(object sender, EventArgs e) { if(ManualModeIsOpen == 0) { SetDataValue("_ManualMode", 1); SetDataValue("_AutoMode", 0 ); ManualMode.Text = "切换自动模式"; ModeLable.Text = "手动模式"; ManualModeIsOpen = 1; if (ManualModeIsStart == 0) { OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; } else { OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; } } else { SetDataValue("_ManualMode", 0); SetDataValue("_AutoMode", 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) { SetDataValue("_StartAuto", 1); SetDataValue("_StopAuto", 0); OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; AutoModeIsStart = 1; } else { SetDataValue("_StartAuto", 0); SetDataValue("_StopAuto", 1); OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; AutoModeIsStart = 0; } } else { if (ManualModeIsStart == 0) { SetDataValue("_StartManual", 1); SetDataValue("_StopManual", 0); OnOffControl.Text = "关闭"; OnOffLable.Text = "状态:开"; ManualModeIsStart = 1; } else { SetDataValue("_StartManual", 0); SetDataValue("_StopManual", 1); OnOffControl.Text = "启动"; OnOffLable.Text = "状态:关"; ManualModeIsStart = 0; } } } /// /// 报警灯重置 /// /// /// private void AlarmReset_Click(object sender, EventArgs e) { SetDataValue("_Alarm", 0); DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On); DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off); } /// /// 运行监测 /// /// /// private void Running_Click(object sender, EventArgs e) { SetDataValue("_Running", 1); } /// /// 运行 /// /// /// private void Run_Click(object sender, EventArgs e) { SetDataValue("_Run", 1); } /// /// 报警 /// /// /// private void Alarm_Click(object sender, EventArgs e) { SetDataValue("_Alarm", 1); DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.On); DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off); } /// /// 窗口关闭 重置报警灯 /// /// /// private void ElectronicMachinery_FormClosing(object sender, FormClosingEventArgs e) { DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.Off); DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Red, DoUtils.enumInfo.DOOnOff.Off); DoControl.Instance.ComOff(); } /*Plc.PlcWriteByDataKey(GetDataKeyValue(""), new Object[] { 1 }); GetDataKeyValue("").LastValue*/ } }