using Mesnac.Action.ChemicalWeighing.Entity;
using Mesnac.PlcUtils;
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;
namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode.ValveStateControl
{
public partial class ValveStateControl : Form
{
BasePlcHelper Plc = BasePlcHelper.Instance;
string DmName = "BU3DBT06";
int ManualModeIsOpen;
int ManualModeIsStart;
int AutoModeIsStart;
public ValveStateControl()
{
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("_SetManual");
AutoModeIsStart = GetDataToInt("_SetAuto");
if (ManualModeIsOpen == 0)
{
ControlMode.Text = "切换手动模式";
ModeStateLable.Text = "自动模式";
if (AutoModeIsStart == 0)
{
OnOffControl.Text = "启动";
OnOffLable.Text = "状态:关";
}
else
{
OnOffControl.Text = "关闭";
OnOffLable.Text = "状态:开";
}
}
else
{
ControlMode.Text = "切换自动模式";
ModeStateLable.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)
{
DmName = dmNameValue[DmChange.Text];
StateMonitor();
}
private void ControlMode_Click(object sender, EventArgs e)
{
if (ManualModeIsOpen == 0)
{
SetDataValue("_ManualMode", 1);
SetDataValue("_AutoMode", 0);
ControlMode.Text = "切换自动模式";
ModeStateLable.Text = "手动模式";
ManualModeIsOpen = 1;
if (ManualModeIsStart == 0)
{
OnOffControl.Text = "启动";
OnOffLable.Text = "状态:关";
}
else
{
OnOffControl.Text = "关闭";
OnOffLable.Text = "状态:开";
}
}
else
{
SetDataValue("_ManualMode", 0);
SetDataValue("_AutoMode", 1);
ControlMode.Text = "切换手动模式";
ModeStateLable.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("_SetAuto", 1);
OnOffControl.Text = "关闭";
OnOffLable.Text = "状态:开";
AutoModeIsStart = 1;
}
else
{
SetDataValue("_SetAuto", 0);
OnOffControl.Text = "启动";
OnOffLable.Text = "状态:关";
AutoModeIsStart = 0;
}
}
else
{
if (ManualModeIsStart == 0)
{
SetDataValue("_SetManual", 1);
OnOffControl.Text = "关闭";
OnOffLable.Text = "状态:开";
ManualModeIsStart = 1;
}
else
{
SetDataValue("_SetManual", 0);
OnOffControl.Text = "启动";
OnOffLable.Text = "状态:关";
ManualModeIsStart = 0;
}
}
}
///
/// 报警
///
///
///
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 AlarmSet_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 Set_Click(object sender, EventArgs e)
{
SetDataValue("_Set", 1);
}
///
/// 窗口关闭 重置报警灯
///
///
///
private void ValveStateControl_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();
}
private IDictionary dmNameValue = new Dictionary()
{
["输送线C1号压送罐出料蝶阀电磁阀"] = "BU3DBT06",
["输送线C2号压送罐出料蝶阀电磁阀"] = "BU3DBT07",
["输送线A1号压送罐进料蝶阀电磁阀"] = "BU1DBT01",
["输送线A1号压送罐返气蝶阀电磁阀"] = "BU1DBT03",
["输送线A2号压送罐进料蝶阀电磁阀"] = "BU1DBT02",
["输送线A2号压送罐返气蝶阀电磁阀"] = "BU1DBT04",
["输送线B1号压送罐进料蝶阀电磁阀"] = "BU2DBT01",
["输送线B1号压送罐返气蝶阀电磁阀"] = "BU2DBT03",
["输送线B2号压送罐进料蝶阀电磁阀"] = "BU2DBT02",
["输送线B2号压送罐返气蝶阀电磁阀"] = "BU2DBT04",
["输送线C1号压送罐进料蝶阀电磁阀"] = "BU3DBT01",
["输送线C1号压送罐返气蝶阀电磁阀"] = "BU3DBT03",
["输送线C2号压送罐进料蝶阀电磁阀"] = "BU3DBT02",
["输送线C2号压送罐返气蝶阀电磁阀"] = "BU3DBT04",
["输送线A1号压送罐出料蝶阀电磁阀"] = "BU1DBT06",
["输送线A2号压送罐出料蝶阀电磁阀"] = "BU1DBT07",
["输送线B1号压送罐出料蝶阀电磁阀"] = "BU2DBT06",
["输送线B2号压送罐出料蝶阀电磁阀"] = "BU2DBT07",
["输送线A1号压送罐充气角座阀"] = "AS1DBT01",
["输送线A2号压送罐充气角座阀"] = "AS1DBT02",
["输送线A清扫角座阀"] = "AS1DBT03",
["输送线A1号压送罐流态化角座阀"] = "AS1DBT04",
["输送线A2号压送罐流态化角座阀"] = "AS1DBT05",
["输送线A压送罐出料主管角座阀"] = "AS1DBT06",
["输送线A压送罐出料辅管角座阀"] = "AS1DBT07",
["输送线B1号压送罐充气角座阀"] = "AS2DBT01",
["输送线B2号压送罐充气角座阀"] = "AS2DBT02",
["输送线B清扫角座阀"] = "AS2DBT03",
["输送线B1号压送罐流态化角座阀"] = "AS2DBT04",
["输送线B2号压送罐流态化角座阀"] = "AS2DBT05",
["输送线B压送罐出料主管角座阀"] = "AS2DBT06",
["输送线B压送罐出料辅管角座阀"] = "AS2DBT07",
["输送线C1号压送罐充气角座阀"] = "AS3DBT01",
["输送线C2号压送罐充气角座阀"] = "AS3DBT02",
["输送线C清扫角座阀"] = "AS3DBT03",
["输送线C1号压送罐流态化角座阀"] = "AS3DBT04",
["输送线C2号压送罐流态化角座阀"] = "AS3DBT05",
["输送线C压送罐出料主管角座阀"] = "AS3DBT06",
["输送线C压送罐出料辅管角座阀"] = "AS3DBT07",
["输送线A辅管角座阀"] = "AS1PCP01",
["输送线B辅管角座阀"] = "AS1PCP02",
["输送线C辅管角座阀"] = "AS1PCP03",
["大仓A外喷淋阀门"] = "AS1ASI01",
["大仓B外喷淋阀门"] = "AS1BSI01",
["大仓C外喷淋阀门"] = "AS1CSI01",
["大仓D外喷淋阀门"] = "AS1DSI01",
["大仓E外喷淋阀门"] = "AS1ESI01",
["大仓F外喷淋阀门"] = "AS1FSI01",
["大仓G外喷淋阀门"] = "AS1GSI01",
["大仓H外喷淋阀门"] = "AS1HSI01",
["大仓I外喷淋阀门"] = "AS1ISI01",
["大仓J外喷淋阀门"] = "AS1JSI01",
["大仓O外喷淋阀门"] = "AS1OSI01",
["输送线A滚筒筛分机侧吹阀"] = "SV1DSM01",
["输送线A滚筒筛分机振动阀"] = "SV1DSM02",
["输送线B滚筒筛分机侧吹阀"] = "SV2DSM01",
["输送线B滚筒筛分机振动阀"] = "SV2DSM02",
["输送线C滚筒筛分机侧吹阀"] = "SV3DSM01",
["输送线C滚筒筛分机振动阀"] = "SV3DSM02",
["二级除尘器侧吹脉冲阀1"] = "PV1GDC01",
["二级除尘器侧吹脉冲阀2"] = "PV1GDC02",
["分配阀1直通电磁阀"] = "DV1PCP01",
["分配阀2直通电磁阀"] = "DV1PCP02",
["分配阀3直通电磁阀"] = "DV1PCP03",
["分配阀4直通电磁阀"] = "DV1PCP04",
["分配阀5直通电磁阀"] = "DV1PCP05",
["分配阀6直通电磁阀"] = "DV1PCP06",
["分配阀7直通电磁阀"] = "DV1PCP07",
["分配阀8直通电磁阀"] = "DV1PCP08",
["分配阀9直通电磁阀"] = "DV1PCP09",
["分配阀10直通电磁阀"] = "DV1PCP10",
["分配阀11直通电磁阀"] = "DV1PCP11",
["分配阀12直通电磁阀"] = "DV1PCP12",
["分配阀13直通电磁阀"] = "DV1PCP13",
["分配阀14直通电磁阀"] = "DV1PCP14",
["分配阀15直通电磁阀"] = "DV1PCP15",
["磨粉系统旋转阀气密封电磁阀"] = "SV1GDS01"
};
}
}