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.

312 lines
10 KiB
C#

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();
}
/// <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)
{
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 = "状态:开";
}
}
}
/// <summary>
/// 列表框,选择设备对应数据块
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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<ElectronicMachinery>.Debug(DMChange.Text + "电机切换成功!");
}
/// <summary>
/// 模式切换
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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 = "状态:开";
}
}
}
/// <summary>
/// 模式开关切换
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
}
/// <summary>
/// 报警灯重置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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>
/// 运行监测
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Running_Click(object sender, EventArgs e)
{
SetDataValue("_Running", 1);
}
/// <summary>
/// 运行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Run_Click(object sender, EventArgs e)
{
SetDataValue("_Run", 1);
}
/// <summary>
/// 报警
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
/// <summary>
/// 窗口关闭 重置报警灯
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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*/
}
}