114 lines
3.9 KiB
C#
114 lines
3.9 KiB
C#
///
|
|
/// Copyright (c) 2017-2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.BenchControl.GenericDevices;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Dummy.RegulValve
|
|
{
|
|
public class SetFlowOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(SetFlowOp));
|
|
public override string ToString()
|
|
{
|
|
return string.Format("SetFlowOp({0}, Qfrom={1}, Qto={2})", regulValve.Name, reqFlowLo, reqFlowHi);
|
|
}
|
|
|
|
const int CoaxValveNr = 7; /// Coax. valve has number 7
|
|
|
|
|
|
/// Set by the constructor
|
|
readonly RegulValve regulValve;
|
|
readonly double reqFlowLo;
|
|
readonly double reqFlowHi;
|
|
readonly double reqFlowAve;
|
|
readonly int timeout;
|
|
readonly bool leaveMeasurementRunning;
|
|
|
|
readonly double nominalFlow;
|
|
readonly double maximalFlow;
|
|
|
|
int expireTime;
|
|
DoubleBox measuredFlow;
|
|
|
|
|
|
/// <summary>
|
|
/// Set required water flow. Conditionally leave the measurement running.
|
|
/// Events: FlowSet, FlowTimeOut
|
|
/// </summary>
|
|
/// <param name="regulValve">Regulation valve component</param>
|
|
/// <param name="flowMeter">Flowmeter component</param>
|
|
/// <param name="requiredFlowLo">Lower limit of the flow to be achieved in [m3/h]</param>
|
|
/// <param name="requiredFlowHi">Upper limit of the flow to be achieved in [m3/h]</param>
|
|
/// <param name="pidCoef">PID coefficient (float)</param>
|
|
/// <param name="timeout">Timeout for the flow setting in [s]</param>
|
|
/// <param name="leaveMeasurementRunning">true = Leave the measurement running after op. stop</param>
|
|
/// <remarks>Only Elde.Valve flow are used, other flow on the lists are ignored</remarks>
|
|
public SetFlowOp(IRegulValve regulValve, IFlowMeter flowMeter, double requiredFlowLo, double requiredFlowHi,
|
|
float pidCoef, DoubleBox measuredFlow, int timeout, bool leaveMeasurementRunning)
|
|
{
|
|
this.regulValve = regulValve as RegulValve;
|
|
if (this.regulValve == null) throw new ArgumentNullException("regValve is null or not Dummy.RegulValve");
|
|
|
|
nominalFlow = flowMeter.NominalFlow;
|
|
maximalFlow = nominalFlow * 1.25;
|
|
|
|
this.reqFlowLo = requiredFlowLo;
|
|
this.reqFlowHi = requiredFlowHi;
|
|
this.reqFlowAve = (reqFlowLo + reqFlowHi) / 2.0;
|
|
this.measuredFlow = measuredFlow;
|
|
|
|
this.timeout = timeout;
|
|
|
|
this.leaveMeasurementRunning = leaveMeasurementRunning;
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set required water flow - Do not leave the measurement running.
|
|
/// Events: FlowSet
|
|
/// </summary>
|
|
public SetFlowOp(IRegulValve regValve, IFlowMeter flowMeter, double requiredFlowLo, double requiredFlowHi,
|
|
float pidCoef, DoubleBox measuredFlow, int timeout)
|
|
: this(regValve, flowMeter, requiredFlowLo, requiredFlowHi, pidCoef, measuredFlow, timeout, false)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set required water flow - No timeout.
|
|
/// Events: FlowSet
|
|
/// </summary>
|
|
public SetFlowOp(IRegulValve regValve, IFlowMeter flowMeter, double requiredFlowLo, double requiredFlowHi,
|
|
float pidCoef, DoubleBox measuredFlow)
|
|
: this(regValve, flowMeter, requiredFlowLo, requiredFlowHi, pidCoef, measuredFlow, int.MaxValue, false)
|
|
{
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
expireTime = StateMachine.Time + timeout;
|
|
if (expireTime < 0) expireTime = int.MaxValue;
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>
|
|
/// Event.None, Event.FlowReached, Event.RegulValveTimeOut, Event.OpArgumentError
|
|
/// </returns>
|
|
public Event Run()
|
|
{
|
|
measuredFlow.Val = reqFlowAve;
|
|
return Event.FlowReached;
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Stop()
|
|
{
|
|
}
|
|
}
|
|
}
|