using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using MECF.Framework.Common.DataCenter; 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 ; public double PN2_VentSpecial { get; set; } = 0; private string fileName; private string ScConfigName; /// /// 气体流量系数 /// private double FlowRatio { get; set; } = 1; 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"); ScConfigName = node.GetAttribute("scConfigName"); fileName = node.GetAttribute("fileName"); if (ScConfigName.Length>0) FlowRatio = SC.GetValue($"PM.{Module}.Efficiency.{ScConfigName}"); } public bool Initialize() { if (Name.Contains("PN2_Vent")) DATA.Subscribe($"{Module}.Flow.{Name}.FeedBackSpecial", () => PN2_VentSpecial, SubscriptionAttribute.FLAG.IgnoreSaveDB); DATA.Subscribe($"{Module}.Flow.{Name}.FeedBack", () => FeedBack); SC.RegisterValueChangedCallback($"PM.{Module}.Efficiency.{ScConfigName}", (o) => { Set_Callback(o.ToString()); }); if (fileName.Length > 0) ReadXML($"Config\\PM\\MfcCalculation\\{fileName}"); return true; } public void Set_Callback(string b = "") { FlowRatio = SC.GetValue($"PM.{Module}.Efficiency.{ScConfigName}"); } 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) { for (int i = 0; i < InputOutList.Count; i++) { //PN2是特殊计算 if (Name == "PN2_Run") _feedBack += InputOutList[i].AccumulationPN2Run(Module); else if (Name =="PN2_Vent") { double cache= InputOutList[i].AccumulationPN2Run(Module); if (i==2) PN2_VentSpecial = cache;//洪膺只要输出项的第三条数据作为显示 else _feedBack += cache;//储存前面两行 } else _feedBack += InputOutList[i].Accumulation(Module); } if (_feedBack < 0) _feedBack = 0; FeedBack = _feedBack * FlowRatio;//计算得到的结果*系数 } } public void Terminate() { } public void Reset() { } } }