You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
7.2 KiB
C#
214 lines
7.2 KiB
C#
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
using Mesnac.DoUtils;
|
|
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_2 : Form
|
|
{
|
|
BasePlcHelper Plc = BasePlcHelper.Instance;
|
|
|
|
int ManualModeIsOpen;
|
|
int ManualModeIsStart;
|
|
int AutoModeIsStart;
|
|
string DmName = "DM1GDS06";
|
|
public ElectronicMachinery_2()
|
|
{
|
|
InitializeComponent();
|
|
DoControl AlarmLight = DoControl.Instance;
|
|
DoControl.Instance.ComOn();
|
|
DoControl.Instance.DOControl(DoUtils.enumInfo.DOName.Green, DoUtils.enumInfo.DOOnOff.On);
|
|
StateMonitor();
|
|
}
|
|
|
|
private void ModeControl_Click(object sender, EventArgs e)
|
|
{
|
|
if (ManualModeIsOpen == 0)
|
|
{
|
|
SetDataValue("_ManualMode", 1);
|
|
SetDataValue("_AutoMode", 0);
|
|
ModeControl.Text = "切换自动模式";
|
|
ModeStateLable.Text = "手动模式";
|
|
ManualModeIsOpen = 1;
|
|
if (ManualModeIsStart == 0)
|
|
{
|
|
OnOffControl.Text = "启动";
|
|
OnOffStateLable.Text = "状态:关";
|
|
}
|
|
else
|
|
{
|
|
OnOffControl.Text = "关闭";
|
|
OnOffStateLable.Text = "状态:开";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SetDataValue("_ManualMode", 0);
|
|
SetDataValue("_AutoMode", 1);
|
|
ModeControl.Text = "切换手动模式";
|
|
ModeStateLable.Text = "自动模式";
|
|
ManualModeIsOpen = 0;
|
|
if (AutoModeIsStart == 0)
|
|
{
|
|
OnOffControl.Text = "启动";
|
|
OnOffStateLable.Text = "状态:关";
|
|
}
|
|
else
|
|
{
|
|
OnOffControl.Text = "关闭";
|
|
OnOffStateLable.Text = "状态:开";
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnOffControl_Click(object sender, EventArgs e)
|
|
{
|
|
if (ManualModeIsOpen == 0)
|
|
{
|
|
if (AutoModeIsStart == 0)
|
|
{
|
|
SetDataValue("_StartAuto", 1);
|
|
SetDataValue("_StopAuto", 0);
|
|
OnOffControl.Text = "关闭";
|
|
OnOffStateLable.Text = "状态:开";
|
|
AutoModeIsStart = 1;
|
|
}
|
|
else
|
|
{
|
|
SetDataValue("_StartAuto", 0);
|
|
SetDataValue("_StopAuto", 1);
|
|
OnOffControl.Text = "启动";
|
|
OnOffStateLable.Text = "状态:关";
|
|
AutoModeIsStart = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (ManualModeIsStart == 0)
|
|
{
|
|
SetDataValue("_StartManual", 1);
|
|
SetDataValue("_StopManual", 0);
|
|
OnOffControl.Text = "关闭";
|
|
OnOffStateLable.Text = "状态:开";
|
|
ManualModeIsStart = 1;
|
|
}
|
|
else
|
|
{
|
|
SetDataValue("_StartManual", 0);
|
|
SetDataValue("_StopManual", 1);
|
|
OnOffControl.Text = "启动";
|
|
OnOffStateLable.Text = "状态:关";
|
|
ManualModeIsStart = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DmChange_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
switch (DmChange.Text)
|
|
{
|
|
case "磨粉主机电机":
|
|
DmName = "DM1GDS06";
|
|
break;
|
|
case "磨粉风机电机":
|
|
DmName = "DM1GDS07";
|
|
break;
|
|
}
|
|
StateMonitor();
|
|
ICSharpCode.Core.LoggingService<ElectronicMachinery>.Debug(DmChange.Text + "电机切换成功!");
|
|
}
|
|
|
|
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 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据属性名和现在选择的数据块名得到PLC数据块的具体引用
|
|
/// </summary>
|
|
/// <param name="dmValue">数据块属性名</param>
|
|
/// <returns></returns>
|
|
private DataKeyValue GetDataNameValue(string dmValue)
|
|
{
|
|
return new DataKeyValue(DmName + dmValue);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从PLC中读取值
|
|
/// </summary>
|
|
/// <param name="dmValue">要读取的属性</param>
|
|
/// <returns></returns>
|
|
private int GetDataToInt(String dmValue)
|
|
{
|
|
return GetDataNameValue(dmValue).NowValue.ToInt();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 向PLC中写入值
|
|
/// </summary>
|
|
/// <param name="dmValue">要写入的属性</param>
|
|
/// <param name="value">写入的值</param>
|
|
private void SetDataValue(String dmValue, int value)
|
|
{
|
|
Plc.PlcWriteByDataKey(GetDataNameValue(dmValue), new Object[] { value });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 状态监测类
|
|
/// </summary>
|
|
private void StateMonitor()
|
|
{
|
|
ManualModeIsOpen = GetDataToInt("_ManualMode");
|
|
ManualModeIsStart = GetDataToInt("_StartManual");
|
|
AutoModeIsStart = GetDataToInt("_StartAuto");
|
|
if (ManualModeIsOpen == 0)
|
|
{
|
|
ModeControl.Text = "切换手动模式";
|
|
ModeStateLable.Text = "自动模式";
|
|
if (AutoModeIsStart == 0)
|
|
{
|
|
OnOffControl.Text = "启动";
|
|
OnOffStateLable.Text = "状态:关";
|
|
}
|
|
else
|
|
{
|
|
OnOffControl.Text = "关闭";
|
|
OnOffStateLable.Text = "状态:开";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ModeControl.Text = "切换自动模式";
|
|
ModeStateLable.Text = "手动模式";
|
|
if (ManualModeIsStart == 0)
|
|
{
|
|
OnOffControl.Text = "启动";
|
|
OnOffStateLable.Text = "状态:关";
|
|
}
|
|
else
|
|
{
|
|
OnOffControl.Text = "关闭";
|
|
OnOffStateLable.Text = "状态:开";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|