using System; using System.Collections.Generic; using log4net; using TBF.BenchControl.GenericDevices; namespace TBF.BenchControl.Elde.Valve { public class Valve : GenericDevices.ValveBase, IValve { private static readonly ILog log = LogManager.GetLogger(typeof(Valve)); public override string ToString() { return string.Format("Valve({0})", Cfg.ToString(1)); } readonly ValveCfg valveCfg; readonly ControlBoardDev controlBoard; 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; } } readonly IValve 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 components) : base(cfg) { valveCfg = cfg; controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); if (valveCfg.BitPosition < 0 || valveCfg.BitPosition >= 64) { throw new ArgumentOutOfRangeException("position"); } this.Mask = (((ulong)1) << valveCfg.BitPosition); if (cfg.CoupledToName != null) { coupledTo = (IValve)TbfComponents.FindComponent(cfg.CoupledToName, components); } log.Debug(this.ToString()); } public bool State { get { return (controlBoard.Route & Mask) != 0; } } } }