Sic.Framework-Nanjing-Baishi/MECF.Framework.RT.Equipment.../HardwareUnits/MfcCalculation/MfcCalculation.cs

124 lines
4.1 KiB
C#
Raw Normal View History

2023-05-19 09:56:55 +08:00
using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.Device;
using Aitex.Core.RT.OperationCenter;
using Aitex.Core.RT.SCCore;
2023-05-18 19:07:16 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
2023-05-19 09:56:55 +08:00
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MfcCalculation
2023-05-18 19:07:16 +08:00
{
public class MfcCalculation : BaseDevice,IDevice
2023-05-18 19:07:16 +08:00
{
2023-05-19 09:56:55 +08:00
List<MfcInputOutRow> InputOutList = new List<MfcInputOutRow>();
public double FeedBack { get; set; } = 0 ;
private string fileName;
2023-05-19 09:56:55 +08:00
public MfcCalculation(string module, XmlElement node, string ioModule = "")
{
var attrModule = node.GetAttribute("module");
Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
Name = node.GetAttribute("id");
Display = node.GetAttribute("display");
fileName= node.GetAttribute("fileName");
2023-05-19 09:56:55 +08:00
2023-05-19 09:56:55 +08:00
}
public bool Initialize()
{
DATA.Subscribe($"{Module}.Flow.{Name}.FeedBack", () => FeedBack);
if (fileName.Length > 0)
ReadXML($"Config\\MfcCalculation\\{fileName}");
2023-05-19 09:56:55 +08:00
return true;
}
2023-05-18 19:07:16 +08:00
public void ReadXML(string fileName)
{
try
{
XmlDocument xml = new XmlDocument();//初始化一个xml实例
xml.Load(fileName);
XmlElement root = xml.DocumentElement;
XmlNodeList nodelist = root.ChildNodes;
//遍历输出.
foreach (XmlNode node in nodelist)
{
2023-05-19 09:56:55 +08:00
MfcInputOutRow inputOutRow = new MfcInputOutRow();
2023-05-18 19:07:16 +08:00
var nodeBlocks = node.SelectNodes("Condition/Inputs/Input");
if (nodeBlocks != null)
{
foreach (var nodeBlock in nodeBlocks)
{
if (!(nodeBlock is XmlElement xmlBlock))
{
continue;
}
NameValue keyValue = new NameValue()
{
Name = xmlBlock.GetAttribute("Name"),
Value =Convert.ToDouble(xmlBlock.GetAttribute("Value")),
2023-05-18 19:07:16 +08:00
ControlName = xmlBlock.GetAttribute("ControlName")
};
inputOutRow.InputList.Add(keyValue);
}
}
nodeBlocks = node.SelectNodes("Condition/Outputs/Output");
if (nodeBlocks != null)
{
foreach (var nodeBlock in nodeBlocks)
{
if (!(nodeBlock is XmlElement xmlBlock))
{
continue;
}
NameValue keyValue = new NameValue()
{
Name = xmlBlock.GetAttribute("Name"),
Value = Convert.ToDouble(xmlBlock.GetAttribute("Value")),
2023-05-18 19:07:16 +08:00
ControlName = xmlBlock.GetAttribute("ControlName")
};
inputOutRow.OutputList.Add(keyValue);
2023-05-18 19:07:16 +08:00
}
}
InputOutList.Add(inputOutRow);
}
}
catch (Exception ex)
{
2023-05-19 09:56:55 +08:00
2023-05-18 19:07:16 +08:00
}
}
2023-05-19 09:56:55 +08:00
protected override void HandleMonitor()
{
2023-05-19 13:04:54 +08:00
double _feedBack = 0;
2023-05-19 09:56:55 +08:00
//循环检测气阀状态
if (InputOutList.Count>0)
{
foreach (var item in InputOutList)
2023-05-19 09:56:55 +08:00
{
2023-05-19 13:04:54 +08:00
_feedBack += item.Accumulation(Module);
2023-05-19 09:56:55 +08:00
}
2023-05-19 13:04:54 +08:00
FeedBack = _feedBack;
2023-05-19 09:56:55 +08:00
}
2023-05-19 13:04:54 +08:00
2023-05-18 19:07:16 +08:00
}
public void Terminate()
{
}
public void Reset()
{
}
2023-05-18 19:07:16 +08:00
}
}