Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Dirichlet.Numerics;
|
||||
using log4net;
|
||||
using TBF.Rig.ControlBoard.Legacy;
|
||||
|
||||
namespace TBF.Rig.BuiltIn.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.0
|
||||
/// </summary>
|
||||
public double Power
|
||||
{
|
||||
get { return (pump1.Power + pump2.Power) / 2; }
|
||||
}
|
||||
|
||||
|
||||
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<Generic.IComponent> 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 BuiltIn.Pump.Pump) { mask1 = (pump1 as BuiltIn.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 BuiltIn.Pump.Pump) { mask2 = (pump2 as BuiltIn.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.Warn(this.ToString());
|
||||
}
|
||||
|
||||
|
||||
public void TurnOn(double 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.0));
|
||||
//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;
|
||||
|
||||
double powerForOp;
|
||||
|
||||
/// <summary>
|
||||
/// Turn the pump frequency inverter on.
|
||||
/// </summary>
|
||||
public IOperation TurnOnOp(double 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user