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.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/AutoControl/AutoControl.cs

408 lines
17 KiB
C#

using DataBlockHelper.DBHelpers;
using DataBlockHelper.Entity.DB2104Entity;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.AutoControl.DB;
using Mesnac.Action.ChemicalWeighing.AutoControl.Entity;
using Mesnac.Action.ChemicalWeighing.LjMixManager;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Mesnac.Action.ChemicalWeighing.LjPlanning;
using IAction = Mesnac.Action.Base.IAction;
using Mesnac.Core.Service;
using static Mesnac.Action.ChemicalWeighing.AutoControl.AutoLogHelper;
using static Mesnac.Action.ChemicalWeighing.AutoControl.PlcAutoWriteHelper;
using Mesnac.Controls.Default;
using Mesnac.Action.ChemicalWeighing.Report;
namespace Mesnac.Action.ChemicalWeighing.AutoControl
{
internal class AutoControl : ChemicalWeighingAction, IAction
{
private List<Control> McControls;
MCTextBoxEntity TextE = new MCTextBoxEntity();
ButtonEntity ButtonE = new ButtonEntity();
MCLabelEntity LabelE = new MCLabelEntity();
MCComboBoxEntity ComboE = new MCComboBoxEntity();
MCRadioButtonEntity RadioE = new MCRadioButtonEntity();
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用
McControls = GetAllControls();
ControlsHelper.ControlImport<MCTextBox>(TextE, McControls);
ControlsHelper.ControlImport<System.Windows.Forms.Button>(ButtonE, McControls);
ControlsHelper.ControlImport<MCCombobox>(ComboE, McControls);
ControlsHelper.ControlImport<MCLabel>(LabelE, McControls);
ControlsHelper.ControlImport<MCRadioButton>(RadioE, McControls);
try
{
BottomSelect(runtime);
}
catch (Exception e)
{
MessageBox.Show("请检查输入内容格式是否正确!");
}
}
//按钮事件
private void BottomSelect(RuntimeParameter runtime)
{
#region 自动参数下传
#region 湿混机糊化机参数下传
if (ButtonE.Download == runtime.Sender)
{
if (MessageBox.Show("确认下传数据?", "下传确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
GelWetDownload(TextE, ComboE, RadioE);
}
#endregion
#region 水称参数下传
if (ButtonE.WaterDownload == runtime.Sender)
{
if (MessageBox.Show("确认下发水称数据?", "下发确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
WaterDownload(TextE, ComboE);
if (ComboE.CALeftOrRight.MCValue.ToString() == "1")
{
LjLogControl.ManualLogControl("冷水称A向机台1设置值", Convert.ToInt32(TextE.ColdValueA.MCValue.ToString()), 1, 1, 1);
LjLogControl.ManualLogControl("冷水称A向机台2设置值", Convert.ToInt32(TextE.ColdValueA.MCValue.ToString()), 1, 2, 1);
LjLogControl.ManualLogControl("冷水称A向机台3设置值",
Convert.ToInt32(TextE.ColdValueA.MCValue.ToString()) + Convert.ToInt32(TextE.CADeviation.MCValue.ToString()), 1, 3, 1);
LjLogControl.ManualLogControl("冷水称A向机台4设置值",
Convert.ToInt32(TextE.ColdValueA.MCValue.ToString()) + Convert.ToInt32(TextE.CADeviation.MCValue.ToString()), 1, 4, 1);
}
else if (ComboE.CALeftOrRight.MCValue.ToString() == "2")
{
LjLogControl.ManualLogControl("冷水称A向机台3设置值", Convert.ToInt32(TextE.ColdValueA.MCValue.ToString()), 1, 3, 1);
LjLogControl.ManualLogControl("冷水称A向机台4设置值", Convert.ToInt32(TextE.ColdValueA.MCValue.ToString()), 1, 4, 1);
LjLogControl.ManualLogControl("冷水称A向机台1设置值",
Convert.ToInt32(TextE.ColdValueA.MCValue.ToString()) + Convert.ToInt32(TextE.CADeviation.MCValue.ToString()), 1, 1, 1);
LjLogControl.ManualLogControl("冷水称A向机台2设置值",
Convert.ToInt32(TextE.ColdValueA.MCValue.ToString()) + Convert.ToInt32(TextE.CADeviation.MCValue.ToString()), 1, 2, 1);
}
if (ComboE.HALeftOrRight.MCValue.ToString() == "1")
{
LjLogControl.ManualLogControl("热水称A向机台1设置值", Convert.ToInt32(TextE.HotValueA.MCValue.ToString()), 1, 1, 1);
LjLogControl.ManualLogControl("热水称A向机台2设置值", Convert.ToInt32(TextE.HotValueA.MCValue.ToString()), 1, 2, 1);
LjLogControl.ManualLogControl("热水称A向机台3设置值",
Convert.ToInt32(TextE.HotValueA.MCValue.ToString()) + Convert.ToInt32(TextE.HADeviation.MCValue.ToString()), 1, 3, 1);
LjLogControl.ManualLogControl("热水称A向机台4设置值",
Convert.ToInt32(TextE.HotValueA.MCValue.ToString()) + Convert.ToInt32(TextE.HADeviation.MCValue.ToString()), 1, 4, 1);
}
else if (ComboE.HALeftOrRight.MCValue.ToString() == "2")
{
LjLogControl.ManualLogControl("热水称A向机台3设置值", Convert.ToInt32(TextE.HotValueA.MCValue.ToString()), 1, 3, 1);
LjLogControl.ManualLogControl("热水称A向机台4设置值", Convert.ToInt32(TextE.HotValueA.MCValue.ToString()), 1, 4, 1);
LjLogControl.ManualLogControl("热水称A向机台1设置值",
Convert.ToInt32(TextE.HotValueA.MCValue.ToString()) + Convert.ToInt32(TextE.HADeviation.MCValue.ToString()), 1, 1, 1);
LjLogControl.ManualLogControl("热水称A向机台2设置值",
Convert.ToInt32(TextE.HotValueA.MCValue.ToString()) + Convert.ToInt32(TextE.HADeviation.MCValue.ToString()), 1, 2, 1);
}
if (ComboE.CBLeftOrRight.MCValue.ToString() == "1")
{
LjLogControl.ManualLogControl("冷水称B向机台5设置值", Convert.ToInt32(TextE.ColdValueB.MCValue.ToString()), 1, 5, 1);
LjLogControl.ManualLogControl("冷水称B向机台6设置值", Convert.ToInt32(TextE.ColdValueB.MCValue.ToString()), 1, 6, 1);
LjLogControl.ManualLogControl("冷水称B向机台7设置值",
Convert.ToInt32(TextE.ColdValueB.MCValue.ToString()) + Convert.ToInt32(TextE.CBDeviation.MCValue.ToString()), 1, 7, 1);
LjLogControl.ManualLogControl("冷水称B向机台8设置值",
Convert.ToInt32(TextE.ColdValueB.MCValue.ToString()) + Convert.ToInt32(TextE.CBDeviation.MCValue.ToString()), 1, 8, 1);
}
else if (ComboE.CBLeftOrRight.MCValue.ToString() == "2")
{
LjLogControl.ManualLogControl("冷水称B向机台7设置值", Convert.ToInt32(TextE.ColdValueB.MCValue.ToString()), 1, 7, 1);
LjLogControl.ManualLogControl("冷水称B向机台8设置值", Convert.ToInt32(TextE.ColdValueB.MCValue.ToString()), 1, 8, 1);
LjLogControl.ManualLogControl("冷水称B向机台5设置值",
Convert.ToInt32(TextE.ColdValueB.MCValue.ToString()) + Convert.ToInt32(TextE.CBDeviation.MCValue.ToString()), 1, 5, 1);
LjLogControl.ManualLogControl("冷水称B向机台6设置值",
Convert.ToInt32(TextE.ColdValueB.MCValue.ToString()) + Convert.ToInt32(TextE.CBDeviation.MCValue.ToString()), 1, 6, 1);
}
if (ComboE.HBLeftOrRight.MCValue.ToString() == "1")
{
LjLogControl.ManualLogControl("热水称B向机台5设置值", Convert.ToInt32(TextE.HotValueB.MCValue.ToString()), 1, 5, 1);
LjLogControl.ManualLogControl("热水称B向机台6设置值", Convert.ToInt32(TextE.HotValueB.MCValue.ToString()), 1, 6, 1);
LjLogControl.ManualLogControl("热水称B向机台7设置值",
Convert.ToInt32(TextE.HotValueB.MCValue.ToString()) + Convert.ToInt32(TextE.HBDeviation.MCValue.ToString()), 1, 7, 1);
LjLogControl.ManualLogControl("热水称B向机台8设置值",
Convert.ToInt32(TextE.HotValueB.MCValue.ToString()) + Convert.ToInt32(TextE.HBDeviation.MCValue.ToString()), 1, 8, 1);
}
else if (ComboE.HBLeftOrRight.MCValue.ToString() == "2")
{
LjLogControl.ManualLogControl("热水称B向机台7设置值", Convert.ToInt32(TextE.HotValueB.MCValue.ToString()), 1, 7, 1);
LjLogControl.ManualLogControl("热水称B向机台8设置值", Convert.ToInt32(TextE.HotValueB.MCValue.ToString()), 1, 8, 1);
LjLogControl.ManualLogControl("热水称B向机台5设置值",
Convert.ToInt32(TextE.HotValueB.MCValue.ToString()) + Convert.ToInt32(TextE.HBDeviation.MCValue.ToString()), 1, 5, 1);
LjLogControl.ManualLogControl("热水称B向机台6设置值",
Convert.ToInt32(TextE.HotValueB.MCValue.ToString()) + Convert.ToInt32(TextE.HBDeviation.MCValue.ToString()), 1, 6, 1);
}
}
#endregion
#region 干混机参数下传
if (ButtonE.DryDownload == runtime.Sender)
{
if (MessageBox.Show("确认下传干混机数据?", "下传确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
DryDownload(TextE, ComboE, RadioE);
}
#endregion
#endregion
#region 手动控制
//手动粉料
if (ButtonE.GelManualPowder == runtime.Sender)
{
if (MessageBox.Show("确认手动下粉料?", "下粉确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
bool isReady = GelPowderDownload(RadioE);
if (!isReady)
{
MessageBox.Show("信号未准备好!");
}
else
{
LjLogControl.ManualLogControl("手动下粉料", ControlsHelper.SingleSelect(RadioE), 3);
MessageBox.Show("信号下达成功!");
}
}
//手动冷水
if (ButtonE.GelManualColdWater == runtime.Sender)
{
if (MessageBox.Show("确认下冷水?", "下水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
bool isReady = GelColdWaterDownload(RadioE);
if (!isReady)
{
MessageBox.Show("信号未准备好!");
}
else
{
LjLogControl.ManualLogControl("手动下冷水", ControlsHelper.SingleSelect(RadioE), 1);
MessageBox.Show("信号下达成功!");
}
}
//手动热水
if (ButtonE.GelManualHotWater == runtime.Sender)
{
if (MessageBox.Show("确认下热水?", "下水确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
bool isReady = GelHotWaterDownload(RadioE);
if (!isReady)
{
MessageBox.Show("信号未准备好!");
}
else
{
LjLogControl.ManualLogControl("手动下热水", ControlsHelper.SingleSelect(RadioE), 1);
MessageBox.Show("信号下达成功!");
}
}
//手动加糊化料
if (ButtonE.WetManualGel == runtime.Sender)
{
if (MessageBox.Show("糊化机打成手动 然后开门放料", "请使用手动加料", MessageBoxButtons.OK, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
return;
//bool isReady = WetGelatDownload(RadioE);
//if (!isReady)
//{
// MessageBox.Show("信号未准备好!");
//}
//else
//{
// SingleLog("手动下糊化料", RadioE);
// MessageBox.Show("信号下达成功!");
//}
}
//湿混机手动下粉料
if (ButtonE.WetManualControl == runtime.Sender)
{
if (MessageBox.Show("确认下传数据?", "下传确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
bool b = WetGelatDownload(TextE, RadioE);
if (b)
{
LjLogControl.ManualLogControl("手动下黑粉料", 3, Convert.ToInt32(TextE.ManualWeight.MCValue.ToString()), ControlsHelper.SingleSelect(RadioE), 2);
MessageBox.Show("数据下传成功!");
}
}
if (ButtonE.WetManualControlStop == runtime.Sender)
{
WetGelatStopDownload(RadioE);
MessageBox.Show("手动停止称量");
}
if (ButtonE.CAOnOff == runtime.Sender)
{
if(ButtonE.CAOnOff.Text == "停止称量")
{
DB2105WriteHelper.StopWater(0);
ButtonE.CAOnOff.Text = "恢复称量";
}
else if(ButtonE.CAOnOff.Text == "恢复称量")
{
DB2105WriteHelper.StartWater(0);
ButtonE.CAOnOff.Text = "停止称量";
}
}
if (ButtonE.CBOnOff == runtime.Sender)
{
if (ButtonE.CBOnOff.Text == "停止称量")
{
DB2105WriteHelper.StopWater(2);
ButtonE.CBOnOff.Text = "恢复称量";
}
else if (ButtonE.CBOnOff.Text == "恢复称量")
{
DB2105WriteHelper.StartWater(2);
ButtonE.CBOnOff.Text = "停止称量";
}
}
if (ButtonE.HAOnOff == runtime.Sender)
{
if (ButtonE.HAOnOff.Text == "停止称量")
{
DB2105WriteHelper.StopWater(1);
ButtonE.HAOnOff.Text = "恢复称量";
}
else if (ButtonE.HAOnOff.Text == "恢复称量")
{
DB2105WriteHelper.StartWater(1);
ButtonE.HAOnOff.Text = "停止称量";
}
}
if (ButtonE.HBOnOff == runtime.Sender)
{
if (ButtonE.HBOnOff.Text == "停止称量")
{
DB2105WriteHelper.StopWater(3);
ButtonE.HBOnOff.Text = "恢复称量";
}
else if (ButtonE.HBOnOff.Text == "恢复称量")
{
DB2105WriteHelper.StartWater(3);
ButtonE.HBOnOff.Text = "停止称量";
}
}
#endregion
#region 自动启停
if (ButtonE.LineStart == runtime.Sender)
{
if (MessageBox.Show("确认启动生产?", "启动确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
LineStart(RadioE);
MessageBox.Show("产线已启动!");
}
if (ButtonE.LineStop == runtime.Sender)
{
LineStop(RadioE);
MessageBox.Show("已经停止生产");
}
#endregion
#region 维修模式
if (ButtonE.RepairMode == runtime.Sender)
{
RepairOnOff(LabelE, RadioE);
}
#endregion
#region 粘贴数据
if (ButtonE.PasteWet == runtime.Sender)
{
int index = ComboE.PasteChooseWet.SelectedIndex + 1;
ControlsHelper.GWInit(index, ComboE, TextE);
}
if (ButtonE.PasteDry == runtime.Sender)
{
int index = ComboE.PasteChooseDry.SelectedIndex + 1;
ControlsHelper.DInit(index, ComboE, TextE);
}
#endregion
}
}
}