Sic.Framework-Nanjing-Baishi/MECF.Framework.RT.Equipment.../Devices/IoGasBoxTemp.cs

100 lines
3.2 KiB
C#
Raw Normal View History

using Aitex.Core.RT.Event;
using Aitex.Core.RT.IOCore;
using Aitex.Core.RT.SCCore;
using Aitex.Core.Util;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Xml;
namespace Aitex.Core.RT.Device.Devices
{
public class IoGasBoxTemp : BaseDevice, IDevice
{
//配置中标记的AI名称
protected readonly List<string> _aiGasBoxTempName = new List<string>()
{
"aiHeatTMA",
"aiHeatTCSPanel",
"aiHeatinsidePanel",
"aiHeatoutsidePanel",
"aiHeatoutsideSH",
"aiHeatLeakBypass"
};
protected readonly List<AIAccessor> _aiGasBoxTemp;
protected readonly DOAccessor _doLineHeaterEnable;
protected readonly string _scNameAlarmHigh;
protected double _alarmHigh;
protected readonly R_TRIG _trigIsAlarm = new R_TRIG();
protected int _alarmCount;
public IoGasBoxTemp(string module, XmlElement node, string ioModule = "") : base(module, node, ioModule)
{
_aiGasBoxTemp = new List<AIAccessor>();
foreach (var aiName in _aiGasBoxTempName)
{
_aiGasBoxTemp.Add(ParseAiNode(aiName, node, ioModule));
}
_doLineHeaterEnable = ParseDoNode("doLineHeaterEnable", node, ioModule);
_scNameAlarmHigh = $"PM.{module}.Heater.{node.GetAttribute("scItemName")}";
Debug.Assert(_doLineHeaterEnable != null, "doLineHeaterEnable is not defined.");
}
protected override void HandleMonitor()
{
var alarmMsg = _aiGasBoxTemp.Where(ai => _alarmHigh > 0 && ai != null && ai.FloatValue >= _alarmHigh)
.Aggregate("", (current, ai) => current + $"{ai.Name} = {ai.FloatValue} ; ");
if (_alarmCount != alarmMsg.Length)// 报警数量发生变化才复位trig防止未复位时产生新的报警不提示问题
_trigIsAlarm.RST = true;
if (alarmMsg.Length > 0)//有报警
{
_trigIsAlarm.CLK = true;
if (_trigIsAlarm.Q)
{
if (_doLineHeaterEnable == null)
{
EV.PostWarningLog(Module,
$"{alarmMsg} over temperature {_alarmHigh} but doLineHeaterEnable can not be off since it's not defined");
}
else
{
_doLineHeaterEnable.SetValue(false, out _);
EV.PostWarningLog(Module,
$"{alarmMsg} over temperature {_alarmHigh}\r\n{Module}.{_doLineHeaterEnable.Name} force off");
}
}
}
_alarmCount = alarmMsg.Length;
}
public bool Initialize()
{
_alarmHigh = SC.SafeGetValue(_scNameAlarmHigh, double.PositiveInfinity);
SC.RegisterValueChangedCallback(_scNameAlarmHigh, v => _alarmHigh = (double)v);
return true;
}
public void Reset()
{
_trigIsAlarm.RST = true;
}
public void Terminate()
{
}
}
}