149 lines
3.7 KiB
C#
149 lines
3.7 KiB
C#
///
|
|
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Dirichlet.Numerics;
|
|
using log4net;
|
|
|
|
namespace TBF.BenchControl.Elde.PumpWithFM
|
|
{
|
|
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("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
|
|
|
readonly PumpCfg pumpCfg;
|
|
|
|
public int Delay { get { return pumpCfg.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; } }
|
|
|
|
readonly ControlBoardDev controlBoard;
|
|
|
|
int bitNr; /// 0 .. 127
|
|
int FMIndex; /// 0 .. FMPumpsCount-1
|
|
public UInt128 Mask; /// derived from bitPosition in the constructor
|
|
|
|
public bool State
|
|
{
|
|
get { return (controlBoard.Route & Mask) != 0; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Pump power in [%] in range 0 .. 100.0f
|
|
/// </summary>
|
|
private float power;
|
|
public float Power
|
|
{
|
|
get { return power; }
|
|
}
|
|
|
|
|
|
public Pump() { }
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="cfg">Pump configuration object</param>
|
|
/// <param name="components">List of all components (used to find the control board)</param>
|
|
public Pump(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
pumpCfg = cfg as PumpCfg;
|
|
|
|
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
|
|
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
bitNr = pumpCfg.BitPosition;
|
|
Mask = (((UInt128)1) << pumpCfg.BitPosition);
|
|
FMIndex = pumpCfg.FMIndex;
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
|
}
|
|
|
|
|
|
public void TurnOn(float powerArg)
|
|
{
|
|
log.InfoFormat("{0}.TurnOn({1})", Name, powerArg);
|
|
this.power = powerArg;
|
|
controlBoard.SetFMFreq(FMIndex, powerArg);
|
|
}
|
|
|
|
public void TurnOff()
|
|
{
|
|
log.InfoFormat("{0}.TurnOff()", Name);
|
|
this.power = 0.0f;
|
|
controlBoard.SetFMFreq(FMIndex, 0.0f);
|
|
}
|
|
|
|
|
|
/// <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;
|
|
}
|
|
}
|
|
}
|