添加新的测温功能
This commit is contained in:
+45
-54
@@ -1,73 +1,74 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Xml;
|
||||
using Aitex.Core.Account;
|
||||
using Aitex.Core.RT.DataCenter;
|
||||
using Aitex.Core.RT.Device;
|
||||
using Aitex.Core.RT.Log;
|
||||
using Aitex.Core.RT.SCCore;
|
||||
using Aitex.Core.Util;
|
||||
using MECF.Framework.Common.Communications;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Xml;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Temps;
|
||||
|
||||
public abstract class TempSensorBase : BaseDevice, IDevice, IConnection, ITempSensor
|
||||
{
|
||||
#region Variables
|
||||
|
||||
|
||||
protected readonly bool IsSimMode;
|
||||
protected bool IsEnableLog;
|
||||
protected TempBasFunction TempBasFunction;
|
||||
|
||||
private readonly Random _rndTempGen = new();
|
||||
private readonly R_TRIG _rTrigReadTempFailed = new();
|
||||
protected readonly R_TRIG _rTrigReadTempFailed = new();
|
||||
private PeriodicJob _tReadTemp;
|
||||
//private Misc.FilterTypes _filterType;
|
||||
//private TempDataFilter[] _tempFilters;
|
||||
|
||||
private readonly Stopwatch _swSimSineWave = new ();
|
||||
private readonly Stopwatch _swSimSineWave = new();
|
||||
private const double SINE_T = 5.0;
|
||||
private const double SINE_F = 2.0 * Math.PI * (1 / SINE_T);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Ctor
|
||||
|
||||
protected TempSensorBase(string module, XmlElement node, string ioModule = "")
|
||||
: base(module, node, ioModule)
|
||||
{
|
||||
IsSimMode = SC.SafeGetValue("System.IsSimulatorMode", false);
|
||||
|
||||
|
||||
RTrigs.Add(_rTrigReadTempFailed);
|
||||
|
||||
|
||||
var maxChStr = node.GetAttribute("MaxChannels");
|
||||
if (!string.IsNullOrEmpty(maxChStr) && int.TryParse(maxChStr, out var maxCh))
|
||||
MaxChannels = maxCh;
|
||||
else
|
||||
MaxChannels = 4;
|
||||
|
||||
|
||||
var minTempStr = node.GetAttribute("MinimalTemp");
|
||||
if (!string.IsNullOrEmpty(minTempStr) && double.TryParse(minTempStr, out var minTemp))
|
||||
MinimalTemp = minTemp;
|
||||
else
|
||||
MinimalTemp = 600.0;
|
||||
|
||||
if(IsSimMode)
|
||||
if (IsSimMode)
|
||||
_swSimSineWave.Start();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
|
||||
public virtual string Address { get; protected set; }
|
||||
|
||||
|
||||
public virtual bool IsConnected { get; }
|
||||
|
||||
|
||||
public double MinimalTemp { get; }
|
||||
|
||||
|
||||
public int MaxChannels { get; }
|
||||
|
||||
public double[] Temp { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 硬件输出的温度
|
||||
/// </summary>
|
||||
public double[] Temp { get; protected set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -77,10 +78,10 @@ public abstract class TempSensorBase : BaseDevice, IDevice, IConnection, ITempSe
|
||||
/// 生成随机温度。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private double[] RandomTemps(double baseTemp = 800, double peakPeak = 200, double jitter = 50.0)
|
||||
protected double[] RandomTemps(int channels, double baseTemp = 800, double peakPeak = 200, double jitter = 50.0)
|
||||
{
|
||||
var rndTemps = new double[MaxChannels];
|
||||
for (var i = 0; i < MaxChannels; i++)
|
||||
var rndTemps = new double[channels];
|
||||
for (var i = 0; i < channels; i++)
|
||||
{
|
||||
var t = _swSimSineWave.Elapsed.TotalSeconds; // current moment
|
||||
var tempSine = peakPeak * Math.Sin(SINE_F * t + (i * Math.PI / 3)); //temperature following sine wave with 60 deg(π/3 rad) phase-diff per channel
|
||||
@@ -91,11 +92,13 @@ public abstract class TempSensorBase : BaseDevice, IDevice, IConnection, ITempSe
|
||||
return rndTemps;
|
||||
}
|
||||
|
||||
private bool DoTempReadThread()
|
||||
|
||||
|
||||
protected virtual bool DoTempReadThread()
|
||||
{
|
||||
// get temp. points according to the "IsSimulatorMode" system config.
|
||||
var temps = IsSimMode ? RandomTemps() : HandleReadTemp();
|
||||
|
||||
var temps = IsSimMode ? RandomTemps(MaxChannels) : HandleReadTemp();
|
||||
|
||||
_rTrigReadTempFailed.CLK = temps == null || temps.Length != MaxChannels;
|
||||
if (_rTrigReadTempFailed.Q)
|
||||
{
|
||||
@@ -112,25 +115,15 @@ public abstract class TempSensorBase : BaseDevice, IDevice, IConnection, ITempSe
|
||||
for (var i = 0; i < MaxChannels; i++)
|
||||
{
|
||||
Temp[i] = temps[i];
|
||||
|
||||
//_tempFilters[i].AddRawTemp(temps![i]);
|
||||
|
||||
//Temp[i] = _filterType switch
|
||||
//{
|
||||
// Misc.FilterTypes.None => _tempFilters[i].Raw,
|
||||
// Misc.FilterTypes.MAF => _tempFilters[i].FilteredMAF,
|
||||
// _ => _tempFilters[i].Raw
|
||||
//};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void InitTempDataFilter()
|
||||
|
||||
protected virtual void InitTempDataFilter()
|
||||
{
|
||||
//_tempFilters = new TempDataFilter[MaxChannels];
|
||||
Temp = new double[MaxChannels];
|
||||
|
||||
|
||||
for (var i = 0; i < MaxChannels; i++)
|
||||
{
|
||||
//_tempFilters[i] = new TempDataFilter(this, (i + 1).ToString(), MinimalTemp, ScBasePath);
|
||||
@@ -138,21 +131,19 @@ public abstract class TempSensorBase : BaseDevice, IDevice, IConnection, ITempSe
|
||||
|
||||
var ch = i;
|
||||
DATA.Subscribe($"TempSensor.{Name}.CH{ch + 1}", () => Temp[ch]);
|
||||
//DATA.Subscribe($"TempSensor.{Name}.CH{ch + 1}MAF", () => _tempFilters[ch].FilteredMAF);
|
||||
//DATA.Subscribe($"TempSensor.{Name}.CH{ch + 1}Raw", () => _tempFilters[ch].Raw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected virtual double[] HandleReadTemp()
|
||||
{
|
||||
return new double[MaxChannels];
|
||||
}
|
||||
|
||||
|
||||
protected virtual bool HandleInitialize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool Initialize()
|
||||
{
|
||||
try
|
||||
@@ -164,25 +155,20 @@ public abstract class TempSensorBase : BaseDevice, IDevice, IConnection, ITempSe
|
||||
}
|
||||
|
||||
IsEnableLog = SC.SafeGetValue($"TempSensors.EnableLogMessage", false);
|
||||
|
||||
//_filterType = ConvertToFilterType(SC.SafeGetStringValue($"{ScBasePath}.FilterType", "None"));
|
||||
|
||||
|
||||
var pollInvMs = SC.SafeGetValue($"{ScBasePath}.PollInterval", 100);
|
||||
|
||||
|
||||
|
||||
// 系统参数变更回调
|
||||
SC.RegisterValueChangedCallback($"{ScBasePath}.PollInterval",
|
||||
(obj) => { _tReadTemp.ChangeInterval((int)obj); });
|
||||
|
||||
//SC.RegisterValueChangedCallback($"{ScBasePath}.FilterType",
|
||||
// (obj) => { _filterType = ConvertToFilterType(obj?.ToString() ?? ""); });
|
||||
|
||||
SC.RegisterValueChangedCallback($"TempSensors.EnableLogMessage",
|
||||
(obj) =>
|
||||
{
|
||||
IsEnableLog = bool.TryParse(obj.ToString(), out var en) && en;
|
||||
});
|
||||
|
||||
|
||||
TempBasFunction = new TempBasFunction(Name, MinimalTemp, MaxChannels);
|
||||
TempBasFunction.SetPm1Pm2IoForInterlock(false);
|
||||
|
||||
@@ -200,7 +186,12 @@ public abstract class TempSensorBase : BaseDevice, IDevice, IConnection, ITempSe
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsProcess()
|
||||
{
|
||||
return DATA.Poll($"{Module}.Status").ToString() == "Process";
|
||||
}
|
||||
|
||||
public virtual bool Connect()
|
||||
{
|
||||
return true;
|
||||
@@ -210,7 +201,7 @@ public abstract class TempSensorBase : BaseDevice, IDevice, IConnection, ITempSe
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public virtual void Terminate()
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user