2023-04-23 16:43:08 +08:00
|
|
|
using System;
|
2023-08-17 15:44:38 +08:00
|
|
|
using SciChart.Core.Extensions;
|
2023-04-23 16:43:08 +08:00
|
|
|
|
2023-08-17 09:43:24 +08:00
|
|
|
namespace Aitex.Core.RT.IOCore.Interlock.Utils;
|
2023-04-23 16:43:08 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-04-24 11:53:56 +08:00
|
|
|
else
|
|
|
|
throw new InvalidCastException($"unable to convert {value} to double range.");
|
2023-04-23 16:43:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-08-17 15:44:38 +08:00
|
|
|
if (double.IsNaN(currentValue))
|
|
|
|
return false;
|
|
|
|
|
2023-04-23 16:43:08 +08:00
|
|
|
return currentValue >= Min && currentValue <= Max;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return $"{Min:F2} - {Max:F2}";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|