tbf/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs
Milan Hanajik 36f2842b01 - Fixed a bug in valves inversion
- Changes in ProcessTabPageCtrl
2014-09-06 13:32:38 +02:00

67 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl.GenericDevices;
namespace TBF.BenchControl.Elde.Valve
{
public class Valve : GenericDevices.ValveBase, Generic.IComponent, IValve
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(Valve));
public override string ToString()
{
return string.Format("Valve({0},{1},{2})", Name, bitPosition, (CoupledTo != null ? CoupledTo.Cfg.Name : "-"));
}
public static void ResetStaticProperties() { }
readonly ValveCfg valveCfg;
public Generic.IComponentCfg Cfg { get { return valveCfg; } }
readonly IValve coupledTo;
readonly ControlBoardDev controlBoard;
readonly int bitPosition; /// 0 .. 63
public string Name { get { return valveCfg.Name; } }
public ValveCategory Category { get { return valveCfg.Category; } }
public int Delay { get { return valveCfg.OpenCloseTime; } }
public bool Inverted { get { return valveCfg.Inverted; } }
public IValve CoupledTo { get { return coupledTo; } }
public bool InvertCouple { get { return valveCfg.InvertCouple; } }
public int LagOpening { get { return valveCfg.LagOpening; } }
public int LagClosing { get { return valveCfg.LagClosing; } }
public readonly ulong Mask; /// derived from bitPosition in the constructor
public Valve(ValveCfg cfg, IList<Generic.IComponent> components)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.valveCfg = cfg;
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
if (bitPosition < 0 || bitPosition >= 64) throw new ArgumentOutOfRangeException("position");
this.bitPosition = cfg.BitPosition;
this.Mask = (((ulong)1) << bitPosition);
if (cfg.CoupledToName != null)
{
this.coupledTo = (IValve)TbfComponents.FindComponent(cfg.CoupledToName, components);
}
log.Debug(this.ToString());
}
public bool State
{
get { return (controlBoard.Route & Mask) != 0; }
}
}
}