using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.SCCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MfcCalculation { public class MfcCalculation : BaseDevice,IDevice { List InputOutList = new List(); public double FeedBack { get; set; } = 0 ; private string fileName; 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"); } public bool Initialize() { DATA.Subscribe($"{Module}.Flow.{Name}.FeedBack", () => FeedBack); if (fileName.Length > 0) ReadXML($"Config\\MfcCalculation\\{fileName}"); return true; } 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) { MfcInputOutRow inputOutRow = new MfcInputOutRow(); 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")), 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")), ControlName = xmlBlock.GetAttribute("ControlName") }; inputOutRow.OutputList.Add(keyValue); } } InputOutList.Add(inputOutRow); } } catch (Exception ex) { } } protected override void HandleMonitor() { double _feedBack = 0; //循环检测气阀状态 if (InputOutList.Count>0) { foreach (var item in InputOutList) { _feedBack += item.Accumulation(Module); } FeedBack = _feedBack; } } public void Terminate() { } public void Reset() { } } }