2023-08-17 15:44:38 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-08-10 16:44:46 +08:00
|
|
|
|
using Aitex.Core.RT.IOCore.Interlock.DataProvider;
|
2023-08-17 09:43:24 +08:00
|
|
|
|
using Aitex.Core.RT.IOCore.Interlock.Utils;
|
2023-08-10 16:44:46 +08:00
|
|
|
|
|
2023-08-17 09:43:24 +08:00
|
|
|
|
namespace Aitex.Core.RT.IOCore.Interlock.Limits;
|
2023-08-10 16:44:46 +08:00
|
|
|
|
|
2023-08-17 09:43:24 +08:00
|
|
|
|
public class DoubleDataPollLimit : InterlockLimitBase<DoubleDataPollProvider, double>
|
2023-08-10 16:44:46 +08:00
|
|
|
|
{
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
public DoubleDataPollLimit(IInterlockLimitDataProvider dataProvider, string value, string tip,
|
2023-09-01 17:47:09 +08:00
|
|
|
|
Dictionary<string, string> cultureTip,bool ignoreReverse) : base(dataProvider, value, tip, cultureTip, ignoreReverse)
|
2023-08-10 16:44:46 +08:00
|
|
|
|
{
|
|
|
|
|
LimitRange = new InterlockLimitRangeDouble(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
private InterlockLimitRangeDouble LimitRange { get; }
|
|
|
|
|
|
2023-08-17 15:44:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.CurrentValue"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override double CurrentValue
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (DataProvider.GetValue() is double value)
|
|
|
|
|
return value;
|
|
|
|
|
|
|
|
|
|
// 如果Poll不到值,始终返回LimitValue相反的值,避免当前Limit被命中
|
|
|
|
|
return double.NaN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.LimitReason"/>
|
|
|
|
|
/// </summary>
|
2023-08-10 16:44:46 +08:00
|
|
|
|
public override string LimitReason =>
|
|
|
|
|
$"{DataProvider.Name} = {CurrentValue:F1}, in the range [{LimitRange}]{(string.IsNullOrEmpty(Tip) ? "" : $",{Tip}")}";
|
2023-08-17 15:44:38 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.DaemonReason"/>
|
|
|
|
|
/// </summary>
|
2023-08-10 16:44:46 +08:00
|
|
|
|
public override string DaemonReason =>
|
|
|
|
|
$"{DataProvider.Name} = {CurrentValue:F1}, in the range [{LimitRange}]{(string.IsNullOrEmpty(Tip) ? "" : $",{Tip}")}";
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
2023-08-17 15:44:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.CheckInRange"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-08-10 16:44:46 +08:00
|
|
|
|
protected override bool CheckInRange()
|
|
|
|
|
{
|
|
|
|
|
return LimitRange.CheckIsInRange(CurrentValue);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 15:44:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <inheritdoc cref="InterlockLimitBase{TAccessor,TValue}.ToString"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-08-10 16:44:46 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{Name}, Limit={LimitRange}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|