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

121 lines
3.5 KiB
C#
Raw Normal View History

using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.Device;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.OperationCenter;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MfcCalculation
{
public class MfcManager : BaseDevice, IDevice
{
public List<string> NameList = new List<string>()
{
"Ar",
"H2",
"C2H4",
"SiH4",
"HCL",
"PN2",
"TCS",
"TMA"
};
private DateTime start;
private DateTime end;
public List<DataFlow> DataFlowList;
private readonly object locker = new object();
public MfcManager(string module, XmlElement node, string ioModule = "")
{
var attrModule = node.GetAttribute("module");
base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
base.Name = node.GetAttribute("id");
base.Display = node.GetAttribute("display");
base.DeviceID = node.GetAttribute("schematicId");
}
public bool Initialize()
{
DataFlowList = new List<DataFlow>();
foreach (var item in NameList)
{
DataFlowList.Add(new DataFlow()
{
Name = item,
});
}
DATA.Subscribe($"{Module}.MfcManager.DataFlow", () => GetDataFlowJsonString());
OP.Subscribe($"{Module}.FlowName.Query", (string cmd, object[] args) => Query(args));
return true;
}
public void Terminate()
{
}
public void Reset()
{
}
private string GetDataFlowJsonString()
{
return JsonConvert.SerializeObject(DataFlowList);
}
private bool Query(object[] objects)
{
Task.Run(() =>
{
string flowName = objects[0].ToString();
start = Convert.ToDateTime(objects[1]);
end = Convert.ToDateTime(objects[2]);
if (flowName == "All")
{
foreach (var item in NameList)
{
QueryRunVentVolume("Flow." + item + "_Run");
QueryRunVentVolume("Flow." + item + "_Vent");
}
}
else
{
QueryRunVentVolume("Flow." + flowName + "_Run");
QueryRunVentVolume("Flow." + flowName + "_Vent");
}
});
return true;
}
private void QueryRunVentVolume(string flowName)
{
Task.Run(() =>
{
double values = MfcSqlHelp.Query(Module, flowName, start, end);
foreach (var item in DataFlowList)
{
if (flowName.Contains(item.Name))
{
if (flowName.Contains("Run"))
item.RunVolume = values * 1.66667 * Math.Pow(10, -7);
else
item.VentVolume = values * 1.66667 * Math.Pow(10, -7);
return;
}
}
});
}
}
}