62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
///
|
|
/// Copyright (c) 2022 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using log4net;
|
|
|
|
namespace TBF.Rig.Modbus.Meret.AdjustableScale
|
|
{
|
|
public enum Pr
|
|
{
|
|
IsGT,
|
|
IsLT,
|
|
}
|
|
|
|
public class WaitUntilValueIsOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(WaitUntilValueIsOp));
|
|
public override string ToString() { return string.Format("WaitUntilPressureIsOp({0}, {1}, {2:F1}bar)", meter.Name, condition, valueLimit); }
|
|
|
|
/// Set by the constructor
|
|
readonly AdjustableMeter meter;
|
|
readonly double valueLimit;
|
|
readonly Pr condition;
|
|
|
|
/// <summary>
|
|
/// Events: PressureInDone, PressureOutDone or Error
|
|
/// </summary>
|
|
/// <param name="meter">Temp. controller reference</param>
|
|
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
|
public WaitUntilValueIsOp(AdjustableMeter meter, Pr condition, double valueLimit)
|
|
{
|
|
if (meter == null) throw new ArgumentNullException("tempControl");
|
|
this.meter = meter;
|
|
this.valueLimit = valueLimit;
|
|
this.condition = condition;
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start() { }
|
|
|
|
/// <summary>Run this operation</summary>
|
|
public Event Run()
|
|
{
|
|
if (condition == Pr.IsGT && meter.ReadPressure() > valueLimit)
|
|
{
|
|
return Event.ConditionMet;
|
|
}
|
|
else if (condition == Pr.IsLT && meter.ReadPressure() < valueLimit)
|
|
{
|
|
return Event.ConditionMet;
|
|
}
|
|
|
|
return Event.ConditionNotMet;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop() { }
|
|
}
|
|
}
|