using System; using System.Collections.Generic; using Aitex.Core.RT.IOCore.Interlock.DataProvider; using DocumentFormat.OpenXml.Math; namespace Aitex.Core.RT.IOCore.Interlock.Limits; public class BoolDataPollLimit : InterlockLimitBase { #region Constructors public BoolDataPollLimit(IInterlockLimitDataProvider dataProvider, string value, string tip, Dictionary cultureTip,bool ignoreReverse) : base(dataProvider, value, tip, cultureTip, ignoreReverse) { if (bool.TryParse(value, out var limitValue)) LimitValue = limitValue; else throw new InvalidCastException($"unable to convert {value} to boolean."); } #endregion #region Properties /// /// /// public override bool CurrentValue { get { if (DataProvider.GetValue() is bool value) return value; // 如果Poll不到值,始终返回LimitValue相反的值,避免当前Limit被命中 return !LimitValue; } } /// /// /// public override string LimitReason => $"{DataProvider.Name} = [{(CurrentValue ? "ON" : "OFF")}]{(string.IsNullOrEmpty(Tip) ? "" : $",{Tip}")}"; /// /// /// public override string DaemonReason => $"{DataProvider.Name} = [{(LimitValue ? "ON" : "OFF")}]{(string.IsNullOrEmpty(Tip) ? "" : $",{Tip}")}"; #endregion /// /// /// /// protected override bool CheckInRange() { return CurrentValue == LimitValue; } }