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

92 lines
2.7 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 _aoOffset == null ? 0 : (_isFloatAioType ? _aoOffset.FloatValue : _aoOffset.Value);
2023-04-13 11:51:03 +08:00
}
set
{
if (_aoOffset != null)
2023-04-13 11:51:03 +08:00
{
if (_isFloatAioType)
_aoOffset.FloatValue = (float)value;
2023-04-13 11:51:03 +08:00
else
_aoOffset.Value = (short)value;
2023-04-13 11:51:03 +08:00
}
}
}
private AOAccessor _aoOffset = null;
2023-04-13 11:51:03 +08:00
private bool _isFloatAioType = false;
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");
_isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
_aoOffset = ParseAoNode("aoOffset", node, ioModule);
2023-04-13 11:51:03 +08:00
}
public bool Initialize()
{
DATA.Subscribe($"{Module}.AllOffset.{Name}", () => PTOffset);
OP.Subscribe($"{Module}.{Display}.{Name}", (function, args) =>
2023-04-13 11:51:03 +08:00
{
Set_Callback();
2023-04-13 11:51:03 +08:00
return true;
});
SC.RegisterValueChangedCallback($"PM.{Module}.{Display}.{Name}", (o) => { Set_Callback(o.ToString()); });
2023-04-13 11:51:03 +08:00
return true;
}
public void Set_Callback(string str ="")
2023-04-13 11:51:03 +08:00
{
try
{
double scValue = SC.GetValue<double>($"PM.{Module}.{Display}.{Name}");
PTOffset = scValue;
EV.PostInfoLog(Module, $"Set PM.{Module}.{Display}.{Name} = {scValue}OK.");
2023-04-13 11:51:03 +08:00
}
catch (Exception ex)
2023-04-13 11:51:03 +08:00
{
EV.PostAlarmLog(Module, $"Set PM.{Module}.{Display}.{Name} Error:" + ex.Message);
2023-04-13 11:51:03 +08:00
}
}
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()
{
}
}
}