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 { public double PTOffset { get { return _aoPTOffset == null ? 0 : (_isFloatAioType ? _aoPTOffset.FloatValue : _aoPTOffset.Value); } 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; private bool _isFloatAioType = false; private string _offsetName; private string _kName; 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); } OP.Subscribe($"{Module}.{Display}.SetPTOffset", (function, args) => { SetPTOffset(); return true; }); OP.Subscribe($"{Module}.{Display}.SetPTK", (function, args) => { SetPTK(); return true; }); OP.Subscribe($"{Module}.{Name}", (function, args) => { SetTempOffset(); return true; }); return true; } public void SetTempOffset() { try { PTOffset = SC.GetValue($"PM.{Module}.WaterTemp.{Name}"); EV.PostInfoLog(Module, $"Set PM.{Module}.WaterTemp.{Name} OK."); } catch (Exception ex) { EV.PostAlarmLog(Module, $"Set PM.{Module}.WaterTemp.{Name} Error:" + ex.Message); } } public void SetPTOffset() { try { PTOffset = SC.GetValue($"PM.{Module}.PT.{Display}.{_offsetName}"); EV.PostInfoLog(Module, $"Set PM..{Module}.PT.{Display}.{_offsetName} OK."); } catch (Exception ex) { EV.PostAlarmLog(Module, $"Set PM..{Module}.PT.{Display}.{_offsetName} Error:" + ex.Message); } } public void SetPTK() { try { PTK = SC.GetValue($"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() { } public void Monitor() { } public void Reset() { } } }