Sic.Framework-Nanjing-Baishi/MECF.Framework.Common/Aitex/Core/RT/IOCore/Interlock/Limits/BoolDataPollLimit.cs

63 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<BoolDataPollProvider, bool>
{
#region Constructors
public BoolDataPollLimit(IInterlockLimitDataProvider dataProvider, string value, string tip,
Dictionary<string, string> 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
/// <summary>
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.CurrentValue"/>
/// </summary>
public override bool CurrentValue
{
get
{
if (DataProvider.GetValue() is bool value)
return value;
// 如果Poll不到值始终返回LimitValue相反的值避免当前Limit被命中
return !LimitValue;
}
}
/// <summary>
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.LimitReason"/>
/// </summary>
public override string LimitReason =>
$"{DataProvider.Name} = [{(CurrentValue ? "ON" : "OFF")}]{(string.IsNullOrEmpty(Tip) ? "" : $",{Tip}")}";
/// <summary>
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.DaemonReason"/>
/// </summary>
public override string DaemonReason =>
$"{DataProvider.Name} = [{(LimitValue ? "ON" : "OFF")}]{(string.IsNullOrEmpty(Tip) ? "" : $",{Tip}")}";
#endregion
/// <summary>
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.CheckInRange"/>
/// </summary>
/// <returns></returns>
protected override bool CheckInRange()
{
return CurrentValue == LimitValue;
}
}