首次上传

This commit is contained in:
hanqiangqiang
2026-06-15 10:56:30 +08:00
commit b0213b94d6
4160 changed files with 736101 additions and 0 deletions
@@ -0,0 +1,18 @@
using System.Xml.Serialization;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
{
[XmlType(typeName: "ControlNameValue")]
public partial class ControlNameValue
{
[XmlAttribute()]
public string Name { get; set; }
[XmlAttribute()]
public double Value { get; set; }
[XmlAttribute()]
public string ControlName { get; set; }
}
}
@@ -0,0 +1,212 @@
using MECF.Framework.Common.Aitex.Core.Common.DeviceData;
using MECF.Framework.Common.DataCenter;
using Sicentury.Core;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
{
/// <summary>
/// 气体流量统计,根据输入名称和时间来查询
/// </summary>
public class GasFlowSqlHelp
{
/// <summary>
/// 查询当天的气体体积数据
/// </summary>
/// <param name="daySlices">拆分的天</param>
/// <param name="moduleName">PM名称</param>
/// <param name="gasFlowSumList">显示列表对象</param>
/// <returns></returns>
public static List<GasFlowSum> GetDayGasFlowSum(DateRangeHelper daySlices, string moduleName, List<GasFlowSum> gasFlowSumList)
{
List<DataTable> dataTableList = GetAllGasListDaySlices(daySlices, moduleName, gasFlowSumList);
string rowStr;
List<GasFlowSum> GasFlowrRunVentList = new List<GasFlowSum>();
foreach (var item in gasFlowSumList)
{
GasFlowrRunVentList.Add(new GasFlowSum() { Name = $"{item.Name}_Run" });
GasFlowrRunVentList.Add(new GasFlowSum() { Name = $"{item.Name}_Vent" });
}
foreach (DataTable ds in dataTableList)
{
double timeDifference = 0;
for (int i = 0; i < ds.Rows.Count; i++)
{
foreach (var item in GasFlowrRunVentList)
{
//$"{moduleName}.GasRealTimeFlow.{item.Name}_Run.FeedBack"
string property = $"{moduleName}.GasRealTimeFlow.{item.Name}.FeedBack";
rowStr = ds.Rows[i][property].ToString();
if (rowStr is not null && rowStr.Length == 0)
continue;
double bd = double.Parse(ds.Rows[i][property].ToString());
if (bd > 0)
{
if (i != ds.Rows.Count - 1)//最后一个数据使用的时间差,是它前一个计算得到的
{
var startTime = new DateTime(long.Parse(ds.Rows[i]["time"].ToString()));
var endTime = new DateTime(long.Parse(ds.Rows[i + 1]["time"].ToString()));
timeDifference = (endTime - startTime).TotalSeconds;
}
item.Volume += bd * timeDifference;
}
}
}
}
return GasFlowrRunVentList;
}
/// <summary>
/// 根据拆分的天循查询数据
/// </summary>
/// <param name="daySlices">拆分的天</param>
/// <param name="moduleName">PM名称</param>
/// <param name="gasFlowSumList">显示集合列表</param>
/// <returns></returns>
private static List<DataTable> GetAllGasListDaySlices(DateRangeHelper daySlices, string moduleName, List<GasFlowSum> gasFlowSumList)
{
List<DataTable> dataTableList = new List<DataTable>();
var ts = daySlices.Diff;
for (var day = 0; day <= ts.Days; day++)
{
var tblName = $"{daySlices.Start.AddDays(day):yyyyMMdd}.{moduleName}";
var sql = new StringBuilder();
// 检查表名是否存在,否则SQL执行出错。
if (CheckTableExists(tblName))
{
sql.Append("select time AS InternalTimeStamp");
// 添加待查询的列
// 添加待查询的列
foreach (var item in gasFlowSumList)
{
sql.Append("," + $"\"{moduleName}.GasRealTimeFlow.{item.Name}_Run.FeedBack\"");
sql.Append("," + $"\"{moduleName}.GasRealTimeFlow.{item.Name}_Vent.FeedBack\"");
}
sql.Append($", \"time\"");
sql.Append($" from \"{tblName}\"");
if (day < ts.Days)
sql.Append(" UNION ");
sql.Append(
$" where time between {daySlices.Start.Ticks} and {daySlices.End.Ticks} order by InternalTimeStamp asc");
try
{
var dataSet = QueryDataClient.Instance.Service.QueryData(sql.ToString());
if (dataSet is not null && dataSet.Rows.Count > 0)
dataTableList.Add(dataSet);
}
catch (Exception ex)//查询较早日期时,可能不存在属性会报错
{
}
}
}
return dataTableList;
}
private static bool CheckTableExists(string tableName)
{
var sql =
$"SELECT EXISTS ( SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = '{tableName}' )";
var table = QueryDataClient.Instance.Service.QueryData(sql);
if (table == null)
return false;
if (table.Rows.Count <= 0)
return false;
var value = table.Rows[0]["exists"].ToString();
if (value.ToLower() == "true")
return true;
return false;
}
public static List<DataTable> GetDataSetDaySlices(DateRangeHelper daySlices, string tableName, string propertyCmd, string property)
{
List<DataTable> dataTableList = new List<DataTable>();
var ts = daySlices.Diff;
for (var day = 0; day <= ts.Days; day++)
{
var tblName = $"{daySlices.Start.AddDays(day):yyyyMMdd}.{tableName}";
var sql = new StringBuilder();
// 检查表名是否存在,否则SQL执行出错。
if (CheckTableExists(tblName))
{
sql.Append("select time AS InternalTimeStamp");
// 添加待查询的列
sql.Append(propertyCmd);
sql.Append($", \"time\"");
sql.Append($" from \"{tblName}\"");
if (day < ts.Days)
sql.Append(" UNION ");
sql.Append(
$" where time between {daySlices.Start.Ticks} and {daySlices.End.Ticks} and '{property}' is not NULL order by InternalTimeStamp asc");
try
{
var dataSet = QueryDataClient.Instance.Service.QueryData(sql.ToString());
if (dataSet is not null && dataSet.Rows.Count > 0)
dataTableList.Add(dataSet);
}
catch (Exception ex)//查询较早日期时,可能不存在属性会报错
{
}
}
}
return dataTableList;
}
public static double GetData(List<DataTable> dataTableList, string property)
{
double values = 0;
string rowStr;
foreach (DataTable ds in dataTableList)
{
double timeDifference = 0;
for (int i = 0; i < ds.Rows.Count; i++)
{
rowStr = ds.Rows[i][property].ToString();
if (rowStr is not null && rowStr.Length == 0)
continue;
double bd = double.Parse(ds.Rows[i][property].ToString());
if (bd > 0)
{
if (i != ds.Rows.Count - 1)//最后一个数据使用的时间差,是它前一个计算得到的
{
var startTime = new DateTime(long.Parse(ds.Rows[i]["time"].ToString()));
var endTime = new DateTime(long.Parse(ds.Rows[i + 1]["time"].ToString()));
timeDifference = (endTime - startTime).TotalSeconds;
}
values += bd * timeDifference;
}
}
}
return values;
}
}
}
@@ -0,0 +1,125 @@
using System;
using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
{
/// <summary>
/// 单个气体的真值表数据,所有配置行数据集合,气体需要的属性数据
/// </summary>
[XmlType(typeName: "GasFlowUnit")]
public class GasFlowUnit
{
/// <summary>
/// 单个真值表内所有的行数据
/// </summary>
[XmlElement("GasTrueTableRows")]
public List<GasTrueTableRows> GasTrueTableRowList { get; set; }
/// <summary>
/// 气体名称
/// </summary>
[XmlAttribute()]
public string GasName { get; set; }
/// <summary>
/// 气体名称显示SC配置
/// </summary>
[XmlAttribute()]
public string scBasePath { get; set; }
/// <summary>
/// 气体流量系数名称
/// </summary>
[XmlAttribute()]
public string GasFlowRatioName { get; set; }
public string ModuleName { get; set; }
/// <summary>
/// 系统中配置的气体流量系数
/// </summary>
public double GasFlowRatioValue { get; set; }
/// <summary>
/// 气体流量计算值
/// </summary>
public double GasFlowFeedBack { get; set; } = 0;
/// <summary>
/// PN2的特殊计算,仅作为界面显示用,不存储到数据库
/// </summary>
public double PN2_VentSpecial { get; set; } = 0;
private R_TRIG _trigError = new();
public void Initialize(string moduleName)
{
ModuleName = moduleName;
SC.RegisterValueChangedCallback($"PM.{ModuleName}.Efficiency.{GasFlowRatioName}", OnGasFlowRatioSCChanged);
GasFlowRatioValue = SC.SafeGetValue<double>($"PM.{ModuleName}.Efficiency.{GasFlowRatioName}", 1d);
if (GasName == "PN2_Vent")
DATA.Subscribe($"{ModuleName}.GasRealTimeFlow.{GasName}.FeedBackSpecial", () => PN2_VentSpecial, SubscriptionAttribute.FLAG.IgnoreSaveDB);//仅作为显示用,不存储数据库
DATA.Subscribe($"{ModuleName}.GasRealTimeFlow.{GasName}.FeedBack", () => GasFlowFeedBack);
foreach (var row in GasTrueTableRowList)
row.Initialize(moduleName, GasName);
}
private void OnGasFlowRatioSCChanged(object value)
{
if (value is double ratio)
GasFlowRatioValue = ratio;
else
GasFlowRatioValue = 1d;
}
public double GetGasFlowFeedBack()
{
double _feedBack = 0;
try
{
//循环检测气阀状态
if (GasTrueTableRowList.Count > 0)
{
for (int i = 0; i < GasTrueTableRowList.Count; i++)//遍历每一行配置的内容,统计气体输出
{
//PN2是特殊计算
if (GasName == "PN2_Run")
_feedBack += GasTrueTableRowList[i].AccumulationPN2Run();
else if (GasName == "PN2_Vent")
{
double cache = GasTrueTableRowList[i].AccumulationPN2Run();
if (i == 2)
PN2_VentSpecial = cache;//洪膺只要输出项的第三条数据作为显示
else
_feedBack += cache;//储存前面两行
}
else
_feedBack += GasTrueTableRowList[i].Accumulation();
}
if (_feedBack < 0)
_feedBack = 0;
GasFlowFeedBack = _feedBack * GasFlowRatioValue;//计算得到的结果*系数
}
}
catch (Exception ex)
{
_trigError.CLK = true;
if (_trigError.Q)
EV.PostWarningLog(ModuleName, $"{GasName} , The truth table calculation is error : {ex}");
}
_trigError.RST = true;
return GasFlowFeedBack;
}
}
}
@@ -0,0 +1,136 @@
using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.Device.Devices;
using Aitex.Core.RT.Device;
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Threading.Tasks;
using Aitex.Core.RT.Event;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
{
/// <summary>
/// 单行真值表对应的逻辑对象,主要执行逻辑就在这里
/// </summary>
[XmlType(typeName: "GasTrueTableRows")]
public partial class GasTrueTableRows
{
[XmlArray("Inputs")]
public List<ControlNameValue> XMLInputList { get; set; }
[XmlArray("Outputs")]
public List<ControlNameValue> XMLOutputList { get; set; }
public string ModuleName { get; set; }
public string GasName { get; set; }
private Dictionary<IoValve, double> InputIoValveList = new Dictionary<IoValve, double>();
private Dictionary<object, double> OutputMfcList = new Dictionary<object, double>();
public void Initialize(string moduleName, string gasName)
{
string strErrorMeg = "";
ModuleName = moduleName;
GasName = gasName;
try
{
foreach (var rowInputs in XMLInputList)
{
strErrorMeg = $"Name = {rowInputs.Name} Value = {rowInputs.Value} ControlName = {rowInputs.ControlName} ";
InputIoValveList.Add(DEVICE.GetDevice<IoValve>($"{ModuleName}.{rowInputs.ControlName}"), rowInputs.Value);
}
if (GasName.Contains("PN2"))//PN2是特殊计算不能在此初始化
return;
foreach (var rowOutputs in XMLOutputList)
{
strErrorMeg = $"Name = {rowOutputs.Name} Value = {rowOutputs.Value} ControlName = {rowOutputs.ControlName} ";
if (rowOutputs.ControlName.Contains("Mfc"))
OutputMfcList.Add(DEVICE.GetDevice<IoMFC>($"{ModuleName}.{rowOutputs.ControlName}"), rowOutputs.Value);
else
OutputMfcList.Add(rowOutputs.ControlName, rowOutputs.Value);
}
}
catch (Exception ex)
{
//输出打印过早,界面可能未加载,造成异常未输出到界面
Task.Delay(5000).ContinueWith(x => EV.PostAlarmLog(ModuleName, $"Truth table initialization error , {GasName}, {strErrorMeg} , Restart the software after the fault is rectified"));
}
}
private bool IsCanOut()
{
//有一个集合为空,不用循环
if (InputIoValveList.Count == 0 || XMLOutputList.Count == 0)
return false;
//一行内单元格的输入输出配置
foreach (var rowInput in InputIoValveList)
{
if (rowInput.Key.Status == true && rowInput.Value == 1)
continue;
if (rowInput.Key.Status == false && rowInput.Value == 0)
continue;
return false;
}
return true;
}
public double Accumulation()
{
double volue = 0;
if (!IsCanOut())
return 0;
foreach (var rowOutput in OutputMfcList)
{
if (rowOutput.Key is IoMFC _mfc)
volue += _mfc.FeedBack * rowOutput.Value;
else//混合气体流量
volue += Convert.ToDouble(DATA.Poll($"{ModuleName}.GasRealTimeFlow.{rowOutput.Key}_Run.FeedBack")) * rowOutput.Value;
}
return volue;
}
public double AccumulationPN2Run()
{
double volue = 0;
if (!IsCanOut())
return 0;
foreach (var rowOutputs in XMLOutputList)
{
if (rowOutputs.ControlName.Contains("Mfc5"))
{
//Output配置的单元格
var _mfc = DEVICE.GetDevice<IoMFC>($"{ModuleName}.{rowOutputs.ControlName}");
volue += _mfc.FeedBack * rowOutputs.Value;
}
else if (rowOutputs.ControlName.Contains("Mfc6"))
{
//特殊气体流量
var _mfc3 = DEVICE.GetDevice<IoMFC>($"{ModuleName}.Mfc3");
var _mfc4 = DEVICE.GetDevice<IoMFC>($"{ModuleName}.Mfc4");
var _mfc6 = DEVICE.GetDevice<IoMFC>($"{ModuleName}.Mfc6");
var m3 = _mfc3.FeedBack;
var m4 = _mfc4.FeedBack;
var m6 = _mfc6.FeedBack;
volue += (m6 * m4 / (m3 + m4)) * rowOutputs.Value;
}
}
return volue;
}
}
}
@@ -0,0 +1,75 @@
using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using MECF.Framework.Common.Aitex.Core.Common.DeviceData;
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
{
[XmlType(typeName: "PMGsaFlow")]
public class PMAllGsa
{
/// <summary>
/// PM腔体中气体
/// </summary>
[XmlElement("GasFlowUnit")]
public List<GasFlowUnit> GasFlowUnitList { get; set; }
public string ModuleName { get; set; }
public List<GasFlowSum> GasFlowSumList { get; set; }
private DateTime start;
private DateTime end;
public void Initialize(string moduleName)
{
IniGasUnit(moduleName);
DATA.Subscribe($"{ModuleName}.PMGasFlowSumList", () => GasFlowSumList);
var _thread = new PeriodicJob(1000, OnTimer, $"{moduleName}.ModuleGsaFlow", true);
}
private bool OnTimer()
{
foreach (GasFlowUnit Unit in GasFlowUnitList)
{
Unit.GetGasFlowFeedBack();
}
return true;
}
/// <summary>
/// 初始化单个气体和界面气体统计对象
/// </summary>
/// <param name="moduleName"></param>
private void IniGasUnit(string moduleName)
{
ModuleName = moduleName;
GasFlowSumList = new();
//单种气体初始化
foreach (var unit in GasFlowUnitList)
{
unit.Initialize(moduleName);
string gasName = unit.GasName.Split('_')[0];//气体格式定位为H2_Run H2_Vent,所以根据下划线来拆分
var gfs = new GasFlowSum();
gfs.Name = gasName;
gfs.Display = gasName;
if (string.IsNullOrEmpty(unit.scBasePath) == false)
{
gfs.Display = SC.GetStringValue(unit.scBasePath);
}
if (!GasFlowSumList.Exists(t => t.Name == gasName))
{
GasFlowSumList.Add(gfs);
}
}
}
}
}
@@ -0,0 +1,24 @@
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using System.IO;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.GasFlow
{
/// <summary>
/// 初始化加载PM模块中所有气体真值表逻辑
/// </summary>
public class PMGasTrueTableInitialize
{
public PMAllGsa PMAllGsa { get; set; }
public PMGasTrueTableInitialize(string pmName,string path)
{
if (!SC.GetValue<bool>($"System.SetUp.Is{pmName}Installed"))
return;
PMAllGsa = CustomXmlSerializer.Deserialize<PMAllGsa>(new FileInfo(path));//$"Config\\PM\\{pmName}\\RealtimeGasFlow{pmName}.xml"
PMAllGsa.Initialize(pmName);
}
}
}