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

167 lines
4.8 KiB
C#
Raw Normal View History

2023-04-13 11:51:03 +08:00
using System;
using System.Xml;
using Aitex.Core.Common.DeviceData;
using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.Device;
using Aitex.Core.RT.Device.Unit;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.IOCore;
using Aitex.Core.RT.OperationCenter;
using Aitex.Core.RT.SCCore;
using Aitex.Core.RT.Tolerance;
using Aitex.Core.Util;
using MECF.Framework.Common.Event;
namespace Aitex.Core.RT.Device.Devices
{
public partial class IoPTOffsetAndK : BaseDevice, IDevice, IPressureMeter
{
2023-04-13 11:51:03 +08:00
public double PTOffset
{
get
{
return _aoPTOffset == null ? 0 : (_isFloatAioType ? _aoPTOffset.FloatValue : _aoPTOffset.Value);
2023-04-13 11:51:03 +08:00
}
set
{
if (_aoPTOffset != null)
{
if (_isFloatAioType)
_aoPTOffset.FloatValue = (float)value;
else
_aoPTOffset.Value = (short)value;
}
}
}
public double PTK
{
get
{
return _aoPTK == null ? 0 : (_isFloatAioType ? _aoPTK.FloatValue : _aoPTK.Value);
}
set
{
if (_aoPTK != null)
{
if (_isFloatAioType)
_aoPTK.FloatValue = (float)value;
else
_aoPTK.Value = (short)value;
}
}
}
private AOAccessor _aoPTOffset = null;
private AOAccessor _aoPTK = null;
2023-04-13 11:51:03 +08:00
private bool _isFloatAioType = false;
private string _offsetName;
private string _kName;
2023-04-13 11:51:03 +08:00
public IoPTOffsetAndK(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");
DeviceID = node.GetAttribute("schematicId");
Unit = node.GetAttribute("unit");
_isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
_aoPTOffset = ParseAoNode("aoOffset", node, ioModule);
_aoPTK = ParseAoNode("aoK", node, ioModule);
_offsetName = Display + "_Offset";
_kName = Display + "_K";
}
public bool Initialize()
{
if (Name.Contains("Water"))
{
DATA.Subscribe($"{Module}.AllOffset.{Name}", () => PTOffset);
}
else
{
DATA.Subscribe($"{Module}.AllOffset.{Name}.PTOffset", () => PTOffset);
DATA.Subscribe($"{Module}.AllOffset.{Name}.PTK", () => PTK);
}
2023-04-13 11:51:03 +08:00
OP.Subscribe($"{Module}.{Display}.SetPTOffset", (function, args) =>
{
SetPTOffset();
return true;
2023-04-13 11:51:03 +08:00
});
OP.Subscribe($"{Module}.{Display}.SetPTK", (function, args) =>
{
SetPTK();
return true;
});
OP.Subscribe($"{Module}.{Name}", (function, args) =>
2023-04-13 11:51:03 +08:00
{
SetTempOffset();
return true;
});
return true;
}
public void SetTempOffset()
{
try
{
PTOffset = SC.GetValue<double>($"PM.{Module}.WaterTemp.{Name}");
EV.PostInfoLog(Module, $"Set PM.{Module}.WaterTemp.{Name} OK.");
2023-04-13 11:51:03 +08:00
}
catch (Exception ex)
{
EV.PostAlarmLog(Module, $"Set PM.{Module}.WaterTemp.{Name} Error:" + ex.Message);
2023-04-13 11:51:03 +08:00
}
}
public void SetPTOffset()
{
try
{
PTOffset = SC.GetValue<double>($"PM.{Module}.PT.{Display}.{_offsetName}");
EV.PostInfoLog(Module, $"Set PM..{Module}.PT.{Display}.{_offsetName} OK.");
}
catch (Exception ex)
2023-04-13 11:51:03 +08:00
{
EV.PostAlarmLog(Module, $"Set PM..{Module}.PT.{Display}.{_offsetName} Error:" + ex.Message);
2023-04-13 11:51:03 +08:00
}
}
public void SetPTK()
{
try
{
PTK = SC.GetValue<double>($"PM.{Module}.PT.{Display}.{_kName}");
EV.PostInfoLog(Module, $"Set PM..{Module}.PT.{Display}.{_kName} OK.");
}
catch (Exception ex)
{
EV.PostAlarmLog(Module, $"Set PM..{Module}.PT.{Display}.{_kName} Error:" + ex.Message);
}
}
public void Terminate()
{
2023-04-13 11:51:03 +08:00
}
public void Monitor()
{
2023-04-13 11:51:03 +08:00
}
public void Reset()
{
}
}
}