tbf/TestBenchFramework/BenchControl/Elde/PumpTandem/Pump.cs

178 lines
4.5 KiB
C#

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
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; } }
/// <summary>
/// Pump power in [%] in range 0 .. 100.0f
/// </summary>
public float Power
{
get { return (pump1.Power + pump2.Power) / 2.0f; }
}
readonly ulong mask1;
readonly ulong mask2;
public ulong Mask { get { return mask1 | mask2; } } /// derived from masks of two pumps
public Pump()
{
}
public Pump(PumpCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
pumpCfg = cfg;
pump1 = (GenericDevices.IPump)TbfComponents.FindComponent(cfg.Pump1, components);
if (pump1 == null) throw new Exception("Cannot find component Pump 1");
pump2 = (GenericDevices.IPump)TbfComponents.FindComponent(cfg.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
}
}
/// <summary>
/// The currently running operation.
/// </summary>
public enum CurrentOp
{
None,
TurnOn,
TurnOff,
}
///
CurrentOp currentOp;
float powerForOp;
/// <summary>
/// Turn the pump frequency inverter on.
/// </summary>
public IOperation TurnOnOp(float powerArg)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.TurnOn;
powerForOp = powerArg;
return this;
}
/// <summary>
/// Turn the pump frequency inverter on.
/// </summary>
public IOperation TurnOffOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.TurnOff;
return this;
}
/// <summary>Start the operation</summary>
public void Start()
{
switch (currentOp)
{
case CurrentOp.TurnOn:
TurnOn(powerForOp);
return;
case CurrentOp.TurnOff:
default:
TurnOff();
return;
}
}
/// <summary>Run the operation</summary>
public Event Run()
{
return Event.TurnPumpOnOffDone;
}
/// <summary>Stop the operation</summary>
public void Stop()
{
currentOp = CurrentOp.None;
}
}
}