71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
using TBF.Rig.GenericDevices;
|
|
|
|
namespace TBF.Rig.Uni.FlowMeter
|
|
{
|
|
public class ReadFlowOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ReadFlowOp));
|
|
public override string ToString() { return string.Format("ReadFlowOp({0},.,.,{1})", flowMeter.Idx1, eventDone); }
|
|
|
|
/// Set by the constructor
|
|
readonly IFlowMeter flowMeter;
|
|
readonly DoubleBox flowBox;
|
|
readonly Event eventDone;
|
|
|
|
/// <summary>
|
|
/// Events: FlowInDone, FlowOutDone or Error
|
|
/// </summary>
|
|
/// <param name="flowMeter">Flow meter reference</param>
|
|
/// <param name="flowBox">Reference to the measured flow variable, value is in bar</param>
|
|
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
|
public ReadFlowOp(IFlowMeter flowMeter, ref DoubleBox flowBox, Event eventDone)
|
|
{
|
|
if (flowMeter == null) throw new ArgumentNullException();
|
|
|
|
this.flowMeter = flowMeter;
|
|
this.eventDone = eventDone;
|
|
this.flowBox = flowBox;
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
public ReadFlowOp(IFlowMeter flowMeter, ref DoubleBox flowBox)
|
|
: this(flowMeter, ref flowBox, Event.FlowMeasurementDone)
|
|
{
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
if (flowMeter.MsrmntAvailable && flowBox != null)
|
|
{
|
|
flowBox.Val = flowMeter.ReadFlow();
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>
|
|
/// Event.FlowInDone or Event.FlowOutDone
|
|
/// </returns>
|
|
public Event Run()
|
|
{
|
|
if (flowMeter.MsrmntAvailable)
|
|
{
|
|
if (flowBox != null) flowBox.Val = flowMeter.ReadFlow();
|
|
return eventDone;
|
|
}
|
|
|
|
return Event.Error;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop() { }
|
|
}
|
|
}
|