|
|
using DataBlockHelper;
|
|
|
using HslCommunication;
|
|
|
using Mesnac.Action.Base;
|
|
|
using Mesnac.Controls.Base;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.ManualControl
|
|
|
{
|
|
|
public class InitAction : ChemicalWeighingAction, IAction
|
|
|
{
|
|
|
|
|
|
List<DbMCControl> McControllist;
|
|
|
OperateResult<byte[]> Read;
|
|
|
byte[] content;
|
|
|
System.Timers.Timer timer;
|
|
|
|
|
|
|
|
|
|
|
|
bool State1;
|
|
|
bool State2;
|
|
|
byte Byt;
|
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
{
|
|
|
|
|
|
base.RunIni(runtime); //必须要调用的
|
|
|
|
|
|
//ReadFromPlc();
|
|
|
|
|
|
InitTimer();
|
|
|
|
|
|
timer.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
private void ReadFromPlc(Object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
|
|
|
McControllist = GetAllDbMCControlsByOption(DbOptionTypes.InitData);//获取所有待初始化控件
|
|
|
|
|
|
|
|
|
IBaseControl WaterActualValue1 = GetBaseControl("WaterActualValue1");
|
|
|
IBaseControl WaterActualValue2 = GetBaseControl("WaterActualValue2");
|
|
|
IBaseControl WaterActualValue3 = GetBaseControl("WaterActualValue3");
|
|
|
IBaseControl WaterActualValue4 = GetBaseControl("WaterActualValue4");
|
|
|
IBaseControl WaterMetValue1 = GetBaseControl("WaterMetValue1");
|
|
|
IBaseControl WaterMetValue2 = GetBaseControl("WaterMetValue2");
|
|
|
IBaseControl WaterMetValue3 = GetBaseControl("WaterMetValue3");
|
|
|
IBaseControl WaterMetValue4 = GetBaseControl("WaterMetValue4");
|
|
|
IBaseControl SpiralActValue1 = GetBaseControl("SpiralActValue1");
|
|
|
IBaseControl SpiralActValue2 = GetBaseControl("SpiralActValue2");
|
|
|
IBaseControl SpiralActValue3 = GetBaseControl("SpiralActValue3");
|
|
|
IBaseControl SpiralActValue4 = GetBaseControl("SpiralActValue4");
|
|
|
IBaseControl MetageState1 = GetBaseControl("MetageState1");
|
|
|
IBaseControl MetageState2 = GetBaseControl("MetageState2");
|
|
|
IBaseControl MetageState3 = GetBaseControl("MetageState3");
|
|
|
IBaseControl MetageState4 = GetBaseControl("MetageState4");
|
|
|
IBaseControl WaterOutState1 = GetBaseControl("WaterOutState1");
|
|
|
IBaseControl WaterOutState2 = GetBaseControl("WaterOutState2");
|
|
|
IBaseControl WaterOutState3 = GetBaseControl("WaterOutState3");
|
|
|
IBaseControl WaterOutState4 = GetBaseControl("WaterOutState4");
|
|
|
IBaseControl SpiralState1 = GetBaseControl("SpiralState1");
|
|
|
IBaseControl SpiralState2 = GetBaseControl("SpiralState2");
|
|
|
IBaseControl SpiralState3 = GetBaseControl("SpiralState3");
|
|
|
IBaseControl SpiralState4 = GetBaseControl("SpiralState4");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.22.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
WaterActualValue1.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.2.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
WaterActualValue2.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.32.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
WaterActualValue3.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.12.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
WaterActualValue4.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.24.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
WaterMetValue1.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.4.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
WaterMetValue2.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.34.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
WaterMetValue3.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.14.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
WaterMetValue4.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.42.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
SpiralActValue1.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.64.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
SpiralActValue2.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.86.0", 2);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
SpiralActValue3.MCValue = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
|
|
|
|
|
|
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.28.0", 1);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
Byt = content[0];
|
|
|
|
|
|
State1 = Byt.GetBit(2);
|
|
|
State2 = Byt.GetBit(6);
|
|
|
|
|
|
if (State1)
|
|
|
{
|
|
|
MetageState1.MCValue = "正在称量";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MetageState1.MCValue = "停止称量";
|
|
|
}
|
|
|
|
|
|
if (State2)
|
|
|
{
|
|
|
WaterOutState1.MCValue = "正在排水";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
WaterOutState1.MCValue = "停止排水";
|
|
|
}
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.8.0", 1);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
Byt = content[0];
|
|
|
|
|
|
State1 = Byt.GetBit(2);
|
|
|
State2 = Byt.GetBit(6);
|
|
|
|
|
|
if (State1)
|
|
|
{
|
|
|
MetageState2.MCValue = "正在称量";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MetageState2.MCValue = "停止称量";
|
|
|
}
|
|
|
|
|
|
if (State2)
|
|
|
{
|
|
|
WaterOutState2.MCValue = "正在排水";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
WaterOutState2.MCValue = "停止排水";
|
|
|
}
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.38.0", 1);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
Byt = content[0];
|
|
|
|
|
|
State1 = Byt.GetBit(2);
|
|
|
State2 = Byt.GetBit(6);
|
|
|
|
|
|
if (State1)
|
|
|
{
|
|
|
MetageState3.MCValue = "正在称量";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MetageState3.MCValue = "停止称量";
|
|
|
}
|
|
|
|
|
|
if (State2)
|
|
|
{
|
|
|
WaterOutState3.MCValue = "正在排水";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
WaterOutState3.MCValue = "停止排水";
|
|
|
}
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.18.0", 1);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
Byt = content[0];
|
|
|
|
|
|
State1 = Byt.GetBit(2);
|
|
|
State2 = Byt.GetBit(6);
|
|
|
|
|
|
if (State1)
|
|
|
{
|
|
|
MetageState4.MCValue = "正在称量";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MetageState4.MCValue = "停止称量";
|
|
|
}
|
|
|
|
|
|
if (State2)
|
|
|
{
|
|
|
WaterOutState4.MCValue = "正在排水";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
WaterOutState4.MCValue = "停止排水";
|
|
|
}
|
|
|
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.60.0", 1);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
Byt = content[0];
|
|
|
|
|
|
State1 = Byt.GetBit(2);
|
|
|
|
|
|
if (State1)
|
|
|
{
|
|
|
SpiralState1.MCValue = "正在螺旋";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SpiralState1.MCValue = "停止螺旋";
|
|
|
}
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.82.0", 1);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
Byt = content[0];
|
|
|
|
|
|
State1 = Byt.GetBit(2);
|
|
|
|
|
|
if (State1)
|
|
|
{
|
|
|
SpiralState2.MCValue = "正在螺旋";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SpiralState2.MCValue = "停止螺旋";
|
|
|
}
|
|
|
|
|
|
Read = PlcConnect.Instance.Read("DB2119.104.0", 1);
|
|
|
|
|
|
content = Read.Content;
|
|
|
|
|
|
Byt = content[0];
|
|
|
|
|
|
State1 = Byt.GetBit(2);
|
|
|
|
|
|
if (State1)
|
|
|
{
|
|
|
SpiralState3.MCValue = "正在螺旋";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SpiralState3.MCValue = "停止螺旋";
|
|
|
}
|
|
|
|
|
|
//Read = PlcConnect.Instance.Read("DB2119..0", 1);
|
|
|
|
|
|
//content = Read.Content;
|
|
|
|
|
|
//Byt = content[0];
|
|
|
|
|
|
//State1 = Byt.GetBit(2);
|
|
|
|
|
|
//if (State1)
|
|
|
//{
|
|
|
// MetageState4.MCValue = "正在螺旋";
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// MetageState4.MCValue = "停止螺旋";
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private void InitTimer()
|
|
|
{
|
|
|
//设置定时间隔(毫秒为单位)
|
|
|
int interval = 900;
|
|
|
timer = new System.Timers.Timer(interval);
|
|
|
//设置执行一次(false)还是一直执行(true)
|
|
|
timer.AutoReset = true;
|
|
|
//设置是否执行System.Timers.Timer.Elapsed事件
|
|
|
timer.Enabled = true;
|
|
|
//绑定Elapsed事件
|
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(ReadFromPlc);
|
|
|
}
|
|
|
|
|
|
|
|
|
private IBaseControl GetBaseControl(string name)
|
|
|
{
|
|
|
return McControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey == name).FirstOrDefault().BaseControl;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|