using System; using System.Collections.Generic; using log4net; namespace TBF.BenchControl.Elde.PumpWithFM { public class Pump : Generic.IComponent, GenericDevices.IPumpFM, GenericDevices.IValve, IOperation { /// /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." /// Warn: Start measurement when busy is true /// private static readonly ILog log = LogManager.GetLogger(typeof(Pump)); public override string ToString() { return string.Format("Pump(name={0}, bit={1}, idx={2})", Name, bitPosition, FMIndex); } public static void ResetStaticProperties() { } private readonly PumpCfg pumpCfg; public Generic.IComponentCfg Cfg { get { return pumpCfg; } } public string Name { get { return pumpCfg.Name; } } public GenericDevices.IValve CoupledTo { get { return null; } } public bool Invert { get { return false; } } public int LagOpening { get { return 0; } } public int LagClosing { get { return 0; } } readonly ControlBoardDev controlBoard; readonly int bitPosition; /// 0 .. 63 int FMIndex; /// 0 .. FMPumpsCount-1 public readonly ulong Mask; /// derived from bitPosition in the constructor public bool State { get { return (controlBoard.Route & Mask) != 0; } } public Pump(PumpCfg cfg, IList components) { if (cfg == null) throw new ArgumentNullException("cfg"); this.pumpCfg = cfg; controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); this.bitPosition = cfg.BitPosition; this.Mask = (((ulong)1) << bitPosition); this.FMIndex = cfg.FMIndex; log.Debug(this.ToString()); } /// /// The currently running operation. /// public enum CurrentOp { None, TurnOn, TurnOff, } /// CurrentOp currentOp; /// /// Turn the pump frequency inverter on. /// public IOperation TurnOn() { if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); currentOp = CurrentOp.TurnOn; return this; } /// /// Turn the pump frequency inverter on. /// public IOperation TurnOff() { 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: controlBoard.SetFMFreq(FMIndex, 50.0f); return; case CurrentOp.TurnOff: default: controlBoard.SetFMFreq(FMIndex, 0.0f); return; } } /// Run the operation public Event Run() { return Event.TurnPumpOnOffDone; } /// Stop the operation public void Stop() { currentOp = CurrentOp.None; } } }