/// /// Copyright (c) 2013-2015 Sensus Metering Systems /// using System; using System.Collections.Generic; using Dirichlet.Numerics; using log4net; namespace TBF.BenchControl.Elde.PumpTandem { public class Pump : ComponentBase, GenericDevices.IPumpFM, GenericDevices.IValve, IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(Pump)); public override string ToString() { return string.Format("PumpTandem({0})", Cfg.ToString(1)); } readonly PumpCfg pumpCfg; readonly GenericDevices.IPump pump1; readonly GenericDevices.IPump pump2; readonly GenericDevices.IPumpFM pumpFm1; readonly GenericDevices.IPumpFM pumpFm2; public bool State { get { return pump1.State || pump2.State; } } public int Delay { get { return Math.Max(pump1.Delay, pump2.Delay); } } public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding public GenericDevices.IValve CoupledTo { get { return null; } } public bool InvertCouple { get { return false; } } public int LagOpening { get { return 0; } } public int LagClosing { get { return 0; } } /// /// Pump power in [%] in range 0 .. 100.0f /// public float Power { get { return (pump1.Power + pump2.Power) / 2.0f; } } readonly UInt128 mask1; readonly UInt128 mask2; public UInt128 Mask { get { return mask1 | mask2; } } /// derived from masks of two pumps public Pump() { } public Pump(Generic.IComponentCfg cfg, IList components) : base(cfg) { pumpCfg = cfg as PumpCfg; pump1 = (GenericDevices.IPump)TbfComponents.FindComponent(pumpCfg.Pump1, components); if (pump1 == null) throw new Exception("Cannot find component Pump 1"); pump2 = (GenericDevices.IPump)TbfComponents.FindComponent(pumpCfg.Pump2, components); if (pump2 == null) throw new Exception("Cannot find component Pump 2"); pumpFm1 = pump1 as GenericDevices.IPumpFM; pumpFm2 = pump2 as GenericDevices.IPumpFM; if (pump1 is Elde.Pump.Pump) { mask1 = (pump1 as Elde.Pump.Pump).Mask; } else if (pump1 is Elde.PumpWithFM.Pump) { mask1 = (pump1 as Elde.PumpWithFM.Pump).Mask; } else if (pump1 is Danfoss.VLT2800.Pump) { mask1 = (pump1 as Danfoss.VLT2800.Pump).Mask; } else { mask1 = 0; } if (pump2 is Elde.Pump.Pump) { mask2 = (pump2 as Elde.Pump.Pump).Mask; } else if (pump2 is Elde.PumpWithFM.Pump) { mask2 = (pump2 as Elde.PumpWithFM.Pump).Mask; } else if (pump2 is Danfoss.VLT2800.Pump) { mask2 = (pump2 as Danfoss.VLT2800.Pump).Mask; } else { mask2 = 0; } log.Debug(this.ToString()); } public void TurnOn(float powerArg) { if ((pumpFm1 != null) && (pumpFm2 != null)) { pumpFm1.TurnOn(powerArg); pumpFm2.TurnOn(powerArg); } else if ((pumpFm1 != null) && (pumpFm2 == null)) { // TODO if (powerArg >= 50) { pumpFm1.TurnOn(2 * (powerArg - 50.0f)); //pump2. } else { pumpFm1.TurnOn(2 * powerArg); //pump2. } // TODO } } public void TurnOff() { if ((pumpFm1 != null) && (pumpFm2 != null)) { pumpFm1.TurnOff(); pumpFm2.TurnOff(); } else { // TODO } } /// /// The currently running operation. /// public enum CurrentOp { None, TurnOn, TurnOff, } /// CurrentOp currentOp; float powerForOp; /// /// Turn the pump frequency inverter on. /// public IOperation TurnOnOp(float powerArg) { if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); currentOp = CurrentOp.TurnOn; powerForOp = powerArg; return this; } /// /// Turn the pump frequency inverter on. /// public IOperation TurnOffOp() { if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); currentOp = CurrentOp.TurnOff; return this; } /// Start the operation public void Start() { switch (currentOp) { case CurrentOp.TurnOn: TurnOn(powerForOp); return; case CurrentOp.TurnOff: default: TurnOff(); return; } } /// Run the operation public Event Run() { return Event.TurnPumpOnOffDone; } /// Stop the operation public void Stop() { currentOp = CurrentOp.None; } } }