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.PressureMeter.Meret
|
|
{
|
|
public enum Pr
|
|
{
|
|
IsGT,
|
|
IsLT,
|
|
}
|
|
|
|
public class WaitUntilPressureIsOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(WaitUntilPressureIsOp));
|
|
public override string ToString() { return string.Format("WaitUntilPressureIsOp({0}, {1}, {2:F1}bar)", meter.Name, condition, pressureLimit); }
|
|
|
|
/// Set by the constructor
|
|
readonly PressureMeter meter;
|
|
readonly double pressureLimit;
|
|
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 WaitUntilPressureIsOp(PressureMeter meter, Pr condition, double pressureLimit)
|
|
{
|
|
if (meter == null) throw new ArgumentNullException("tempControl");
|
|
this.meter = meter;
|
|
this.pressureLimit = pressureLimit;
|
|
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() > pressureLimit)
|
|
{
|
|
return Event.ConditionMet;
|
|
}
|
|
else if (condition == Pr.IsLT && meter.ReadPressure() < pressureLimit)
|
|
{
|
|
return Event.ConditionMet;
|
|
}
|
|
|
|
return Event.ConditionNotMet;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop() { }
|
|
}
|
|
}
|