|
|
using DataBlockHelper;
|
|
|
using DataBlockHelper.DBHelpers;
|
|
|
using Mesnac.Action.Base;
|
|
|
using Mesnac.Action.ChemicalWeighing.LjDeliverControlBoard.Entity;
|
|
|
using Mesnac.Action.ChemicalWeighing.Util;
|
|
|
using Mesnac.Controls.ChemicalWeighing;
|
|
|
using Mesnac.Controls.Default;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.LjDeliverControlBoard
|
|
|
{
|
|
|
public class ControlBoardButtonAction : ChemicalWeighingAction, IAction
|
|
|
{
|
|
|
DB191Helper DB191 = new DB191Helper();
|
|
|
|
|
|
List<Control> Controls;
|
|
|
MCButtonEntity ButtonE = new MCButtonEntity();
|
|
|
MCRadioButtonEntity RadioButtonE = new MCRadioButtonEntity();
|
|
|
MCCombobox MotorSelect;
|
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
{
|
|
|
RunIni(runtime);
|
|
|
Controls = GetAllControls();
|
|
|
|
|
|
MotorSelect = Controls.FirstOrDefault(x => x != null && x.Name == "MotorSelect") as MCCombobox;
|
|
|
|
|
|
SetAllControls();
|
|
|
|
|
|
ButtonSelect(runtime);
|
|
|
}
|
|
|
|
|
|
private void ButtonSelect(RuntimeParameter runtime)
|
|
|
{
|
|
|
if (runtime.Sender == ButtonE.BoardOnA)
|
|
|
{
|
|
|
if (!DB191.GetPanelOnOff()[0])
|
|
|
{
|
|
|
if (MessageBox.Show("确认要启动操作面板A?", "操作面板启动确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
DB191WriteHelper.SetPanelOnOffA(true);
|
|
|
ButtonE.BoardOnA.Text = "关闭面板";
|
|
|
ButtonE.BoardOnA.BackColor = System.Drawing.Color.LightGreen;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DB191WriteHelper.SetPanelOnOffA(false);
|
|
|
ButtonE.BoardOnA.Text = "面板启用";
|
|
|
ButtonE.BoardOnA.BackColor = System.Drawing.Color.Yellow;
|
|
|
MessageBox.Show("面板已关闭");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.BoardOnB)
|
|
|
{
|
|
|
if (!DB191.GetPanelOnOff()[1])
|
|
|
{
|
|
|
if (MessageBox.Show("确认要启动操作面板B?", "操作面板启动确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
DB191WriteHelper.SetPanelOnOffB(true);
|
|
|
ButtonE.BoardOnB.Text = "关闭面板";
|
|
|
ButtonE.BoardOnB.BackColor = System.Drawing.Color.LightGreen;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DB191WriteHelper.SetPanelOnOffB(false);
|
|
|
ButtonE.BoardOnB.Text = "面板启用";
|
|
|
ButtonE.BoardOnB.BackColor = System.Drawing.Color.Yellow;
|
|
|
MessageBox.Show("面板已关闭");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.BoardOnC)
|
|
|
{
|
|
|
if (!DB191.GetPanelOnOff()[2])
|
|
|
{
|
|
|
if (MessageBox.Show("确认要启动操作面板C?", "操作面板启动确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
DB191WriteHelper.SetPanelOnOffC(true);
|
|
|
ButtonE.BoardOnC.Text = "关闭面板";
|
|
|
ButtonE.BoardOnC.BackColor = System.Drawing.Color.LightGreen;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DB191WriteHelper.SetPanelOnOffC(false);
|
|
|
ButtonE.BoardOnC.Text = "面板启用";
|
|
|
ButtonE.BoardOnC.BackColor = System.Drawing.Color.Yellow;
|
|
|
MessageBox.Show("面板已关闭");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.DownLoadBoardA)
|
|
|
{
|
|
|
if (MessageBox.Show("确认下发A面板数据?", "数据下发确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
switch (ControlsHelper.BottleSelectA(RadioButtonE))
|
|
|
{
|
|
|
case 1: DB191WriteHelper.SetVesselModeA(true, false); break;
|
|
|
case 2: DB191WriteHelper.SetVesselModeA(false, true); break;
|
|
|
case 3: DB191WriteHelper.SetVesselModeA(false, false); break;
|
|
|
default: MessageBox.Show("请先选择压送罐模式!"); return;
|
|
|
}
|
|
|
|
|
|
DB191WriteHelper.SetSiloGroupA(
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupAA.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupBA.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupCA.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupDA.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupEA.MCValue)
|
|
|
);
|
|
|
|
|
|
DB191WriteHelper.SetSiloA(
|
|
|
Convert.ToBoolean(RadioButtonE.StoreAA.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreBA.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreCA.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreDA.MCValue)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.DownLoadBoardB)
|
|
|
{
|
|
|
if (MessageBox.Show("确认下发B面板数据?", "数据下发确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
switch (ControlsHelper.BottleSelectB(RadioButtonE))
|
|
|
{
|
|
|
case 1: DB191WriteHelper.SetVesselModeB(true, false); break;
|
|
|
case 2: DB191WriteHelper.SetVesselModeB(false, true); break;
|
|
|
case 3: DB191WriteHelper.SetVesselModeB(false, false); break;
|
|
|
default: MessageBox.Show("请先选择压送罐模式!"); return;
|
|
|
}
|
|
|
|
|
|
DB191WriteHelper.SetSiloGroupB(
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupAB.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupBB.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupCB.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupDB.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupEB.MCValue)
|
|
|
);
|
|
|
|
|
|
DB191WriteHelper.SetSiloB(
|
|
|
Convert.ToBoolean(RadioButtonE.StoreAB.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreBB.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreCB.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreDB.MCValue)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.DownLoadBoardC)
|
|
|
{
|
|
|
if (MessageBox.Show("确认下发C面板数据?", "数据下发确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
switch (ControlsHelper.BottleSelectC(RadioButtonE))
|
|
|
{
|
|
|
case 1: DB191WriteHelper.SetVesselModeC(true, false); break;
|
|
|
case 2: DB191WriteHelper.SetVesselModeC(false, true); break;
|
|
|
case 3: DB191WriteHelper.SetVesselModeC(false, false); break;
|
|
|
default: MessageBox.Show("请先选择压送罐模式!"); return;
|
|
|
}
|
|
|
|
|
|
DB191WriteHelper.SetSiloGroupC(
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupAC.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupBC.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupCC.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupDC.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreGroupEC.MCValue)
|
|
|
);
|
|
|
|
|
|
DB191WriteHelper.SetSiloC(
|
|
|
Convert.ToBoolean(RadioButtonE.StoreAC.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreBC.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreCC.MCValue),
|
|
|
Convert.ToBoolean(RadioButtonE.StoreDC.MCValue)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.SwitchAutoMode)
|
|
|
{
|
|
|
string name = MotorSelect.Text;
|
|
|
if (MessageBox.Show($"确认将{name}切换到自动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
string str = MotorSelect.MCValue.ToString();
|
|
|
int value = Convert.ToInt32(str);
|
|
|
if (value <= 32)
|
|
|
{
|
|
|
ControlsHelper.WriteMode(str, false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ControlsHelper.WriteMode(str, true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.SwitchManualMode)
|
|
|
{
|
|
|
string name = MotorSelect.Text;
|
|
|
if (MessageBox.Show($"确认将{name}切换到手动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
string str = MotorSelect.MCValue.ToString();
|
|
|
int value = Convert.ToInt32(str);
|
|
|
if (value <= 32)
|
|
|
{
|
|
|
ControlsHelper.WriteMode(str, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ControlsHelper.WriteMode(str, false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.ManualModeOnOff)
|
|
|
{
|
|
|
string name = MotorSelect.Text;
|
|
|
string str = MotorSelect.MCValue.ToString();
|
|
|
byte byt = ControlsHelper.ReadMode(name);
|
|
|
int value = Convert.ToInt32(str);
|
|
|
if (value <= 32)
|
|
|
{
|
|
|
if (byt.GetBit(3))
|
|
|
{
|
|
|
if (MessageBox.Show($"确认开启{name}的手动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ControlsHelper.WriteModeP1(str, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (MessageBox.Show($"确认关闭{name}的手动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ControlsHelper.WriteModeP1(str, false);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (byt.GetBit(5))
|
|
|
{
|
|
|
if (MessageBox.Show($"确认开启{name}的手动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ControlsHelper.WriteModeP2(str, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (MessageBox.Show($"确认关闭{name}的手动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ControlsHelper.WriteModeP2(str, false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (runtime.Sender == ButtonE.AutoModeOnOff)
|
|
|
{
|
|
|
string name = MotorSelect.Text;
|
|
|
string str = MotorSelect.MCValue.ToString();
|
|
|
byte byt = ControlsHelper.ReadMode(name);
|
|
|
int value = Convert.ToInt32(str);
|
|
|
if (value <= 32)
|
|
|
{
|
|
|
if (byt.GetBit(5))
|
|
|
{
|
|
|
if (MessageBox.Show($"确认开启{name}的自动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ControlsHelper.WriteModeP2(str, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (MessageBox.Show($"确认关闭{name}的自动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ControlsHelper.WriteModeP2(str, false);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (byt.GetBit(3))
|
|
|
{
|
|
|
if (MessageBox.Show($"确认开启{name}的自动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ControlsHelper.WriteModeP1(str, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (MessageBox.Show($"确认关闭{name}的自动模式?", "电机模式切换确认", MessageBoxButtons.YesNo) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ControlsHelper.WriteModeP1(str, false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void SetAllControls()
|
|
|
{
|
|
|
ControlsImprot.ControlImport<MCButton>(ButtonE, Controls);
|
|
|
ControlsImprot.ControlImport<MCRadioButton>(RadioButtonE, Controls);
|
|
|
}
|
|
|
}
|
|
|
}
|