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

52 lines
1.1 KiB
C#

using System;
namespace Aitex.Core.RT.IOCore;
public class InterlockLimitRangeDouble : IAnalogInterlockLimitRange<double>
{
#region Constructors
public InterlockLimitRangeDouble(string value)
{
var strValues = value.Split(':');
if (strValues.Length == 2
&& double.TryParse(strValues[0], out var min)
&& double.TryParse(strValues[1], out var max))
{
Min = min;
Max = max;
}
else
throw new InvalidCastException($"unable to convert {value} to double range.");
}
public InterlockLimitRangeDouble(double min, double max)
{
Min = min;
Max = max;
}
#endregion
#region Properties
public double Min { get; }
public double Max { get; }
#endregion
#region Methods
public virtual bool CheckIsInRange(double currentValue)
{
return currentValue >= Min && currentValue <= Max;
}
public override string ToString()
{
return $"{Min:F2} - {Max:F2}";
}
#endregion
}