/// /// Copyright (c) 2017 Sensus Metering Systems /// 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}, PID={3})", regulValve.Name, reqFlowLo, reqFlowHi, pidCoef); } const int CoaxValveNr = 7; /// Coax. valve has number 7 /// Set by the constructor readonly RegulValve regulValve; readonly int flowMeterNr; readonly float reqFlowLo; readonly float reqFlowHi; readonly float reqFlowAve; readonly float pidCoef; readonly int timeout; readonly bool leaveMeasurementRunning; readonly bool reTryCommands; readonly float nominalFlow; float targetPositionLo; float targetPositionHi; int expireTime; DoubleBox measuredFlow; int flowWithinBoundsTime; /// /// Set required water flow. Conditionally leave the measurement running. /// Events: FlowSet, FlowTimeOut /// /// Regulation valve component /// Flowmeter component /// Lower limit of the flow to be achieved in [m3/h] /// Upper limit of the flow to be achieved in [m3/h] /// PID coefficient (float) /// Timeout for the flow setting in [s] /// true = Leave the measurement running after op. stop /// Only Elde.Valve flow are used, other flow on the lists are ignored public SetFlowOp(IRegulValve regulValve, IFlowMeter flowMeter, float requiredFlowLo, float 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; this.reqFlowLo = requiredFlowLo; this.reqFlowHi = requiredFlowHi; this.reqFlowAve = (reqFlowLo + reqFlowHi) / 2.0f; this.measuredFlow = measuredFlow; this.timeout = timeout; this.leaveMeasurementRunning = leaveMeasurementRunning; log.Debug(this.ToString()); } /// /// Set required water flow - Do not leave the measurement running. /// Events: FlowSet /// public SetFlowOp(IRegulValve regValve, IFlowMeter flowMeter, float requiredFlowLo, float requiredFlowHi, float pidCoef, DoubleBox measuredFlow, int timeout) : this(regValve, flowMeter, requiredFlowLo, requiredFlowHi, pidCoef, measuredFlow, timeout, false) { } /// /// Set required water flow - No timeout. /// Events: FlowSet /// public SetFlowOp(IRegulValve regValve, IFlowMeter flowMeter, float requiredFlowLo, float requiredFlowHi, float pidCoef, DoubleBox measuredFlow) : this(regValve, flowMeter, requiredFlowLo, requiredFlowHi, pidCoef, measuredFlow, int.MaxValue, false) { } /// Start this operation public void Start() { expireTime = StateMachine.Time + timeout; if (expireTime < 0) expireTime = int.MaxValue; } /// Run this operation /// /// Event.None, Event.FlowReached, Event.RegulValveTimeOut, Event.OpArgumentError /// public Event Run() { measuredFlow.Val = reqFlowAve; return Event.FlowReached; } /// Start this operation public void Stop() { } } }