118 lines
2.9 KiB
C#
118 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
|
|
namespace TBF.BenchControl.Elde.PumpWithFM
|
|
{
|
|
public class Pump : Generic.IComponent, GenericDevices.IPumpFM, GenericDevices.IValve, IOperation
|
|
{
|
|
/// <summary>
|
|
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
|
|
/// Warn: Start measurement when busy is true
|
|
/// </summary>
|
|
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<Generic.IComponent> 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());
|
|
}
|
|
|
|
/// <summary>
|
|
/// The currently running operation.
|
|
/// </summary>
|
|
public enum CurrentOp
|
|
{
|
|
None,
|
|
TurnOn,
|
|
TurnOff,
|
|
}
|
|
///
|
|
CurrentOp currentOp;
|
|
|
|
/// <summary>
|
|
/// Turn the pump frequency inverter on.
|
|
/// </summary>
|
|
public IOperation TurnOn()
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.TurnOn;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Turn the pump frequency inverter on.
|
|
/// </summary>
|
|
public IOperation TurnOff()
|
|
{
|
|
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:
|
|
controlBoard.SetFMFreq(FMIndex, 50.0f);
|
|
return;
|
|
case CurrentOp.TurnOff:
|
|
default:
|
|
controlBoard.SetFMFreq(FMIndex, 0.0f);
|
|
return;
|
|
}
|
|
}
|
|
|
|
/// <summary>Run the operation</summary>
|
|
public Event Run()
|
|
{
|
|
return Event.TurnPumpOnOffDone;
|
|
}
|
|
|
|
/// <summary>Stop the operation</summary>
|
|
public void Stop()
|
|
{
|
|
currentOp = CurrentOp.None;
|
|
}
|
|
}
|
|
}
|