/// /// Copyright (c) 2017 Sensus Metering Systems /// using System; using System.Collections.Generic; using log4net; using TBF.BenchControl.Generic; using TBF.BenchControl.GenericDevices; using TBF.Boxes; using TBF.Resources; namespace TBF.BenchControl.Modbus.TankSelector { public class TankSelector : ComponentBase, ISequenceCondition, IDevice { private static readonly ILog log = LogManager.GetLogger(typeof(TankSelector)); public override string ToString() { return string.Format("TankSelector({0})", Cfg.ToString(1)); } readonly TankSelectorCfg tankSelectorCfg; readonly TBF.BenchControl.Modbus.QuidoRS.QuidoRS quidoRS; readonly TBF.BenchControl.Modbus.Easytherm.Easytherm hotHeating; readonly TBF.BenchControl.Modbus.Easytherm.Easytherm hotCooling; readonly TBF.BenchControl.Modbus.Easytherm.Easytherm warmHeating; readonly TBF.BenchControl.Modbus.Easytherm.Easytherm warmCooling; readonly TBF.BenchControl.Modbus.Easytherm.Easytherm coldCooling; IList sequenceConditionNames; IList sequenceConditions; /// /// Quido digital out board outputs assignment /// private enum QuidoOutputs { None = 0, SelectColdTank = 0x0001, SelectWarmTank = 0x0002, SelectHotTank = 0x0004, PumpToColdTank = 0x0008, PumpToWarmTank = 0x0010, PumpToHotTank = 0x0020, Mixing = 0x0040, HeatingHotTank = 0x0080, HeatingWarmTank = 0x0100, CoolingHotTank = 0x0200, CoolingWarmTank = 0x0400, CoolingColdTank = 0x0800, } public TankSelector() { CreateConditions(false); } public TankSelector(Generic.IComponentCfg cfg, IList components) : base(cfg) { tankSelectorCfg = cfg as TankSelectorCfg; quidoRS = (TBF.BenchControl.Modbus.QuidoRS.QuidoRS)TbfComponents.FindComponent(cfg.ParentName, components); if (quidoRS == null) throw new Exception(string.Format("Cannot find parent '{0}' of the component {1}", cfg.ParentName, Name)); hotHeating = (TBF.BenchControl.Modbus.Easytherm.Easytherm)TbfComponents.FindComponent(tankSelectorCfg.HotWaterHeating, components); hotCooling = (TBF.BenchControl.Modbus.Easytherm.Easytherm)TbfComponents.FindComponent(tankSelectorCfg.HotWaterCooling, components); warmHeating = (TBF.BenchControl.Modbus.Easytherm.Easytherm)TbfComponents.FindComponent(tankSelectorCfg.WarmWaterHeating, components); warmCooling = (TBF.BenchControl.Modbus.Easytherm.Easytherm)TbfComponents.FindComponent(tankSelectorCfg.WarmWaterCooling, components); coldCooling = (TBF.BenchControl.Modbus.Easytherm.Easytherm)TbfComponents.FindComponent(tankSelectorCfg.ColdWaterCooling, components); if (hotHeating == null) throw new Exception(string.Format("Component '{0}' cannot find temperature controller '{1}'", Name, tankSelectorCfg.HotWaterHeating)); if (hotCooling == null) throw new Exception(string.Format("Component '{0}' cannot find temperature controller '{1}'", Name, tankSelectorCfg.HotWaterCooling)); if (warmHeating == null) throw new Exception(string.Format("Component '{0}' cannot find temperature controller '{1}'", Name, tankSelectorCfg.WarmWaterHeating)); if (warmCooling == null) throw new Exception(string.Format("Component '{0}' cannot find temperature controller '{1}'", Name, tankSelectorCfg.WarmWaterCooling)); if (coldCooling == null) throw new Exception(string.Format("Component '{0}' cannot find temperature controller '{1}'", Name, tankSelectorCfg.ColdWaterCooling)); CreateConditions(true); log.Debug(this.ToString()); } public void Initialize() { SetOutputs(0); } public void RunDeviceBefore() {} public void RunDeviceAfter() {} public void StopDevice() {} void CreateConditions(bool createAll) { sequenceConditionNames = new List(); sequenceConditionNames.Add(Strings.Select_COLD_tank); sequenceConditionNames.Add(Strings.Select_WARM_tank); sequenceConditionNames.Add(Strings.Select_HOT_tank); sequenceConditionNames.Add(Strings.Unselect_COLD_tank); sequenceConditionNames.Add(Strings.Unselect_WARM_tank); sequenceConditionNames.Add(Strings.Unselect_HOT_tank); if (createAll) { sequenceConditions = new List(); sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.SelectTank, 1)); sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.SelectTank, 2)); sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.SelectTank, 3)); sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.UnselectTank, 1)); sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.UnselectTank, 2)); sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.UnselectTank, 3)); } } /// /// Set outputs of QuidoRS board /// /// output value public void SetOutputs(uint outputs) { quidoRS.SetOutputs((ushort)outputs); } public int ConditionsCount { get { return sequenceConditions != null ? sequenceConditions.Count : 0; } } /// Returned strings are added to the combo-box public string ConditionName(int i) { if (sequenceConditionNames != null && i < sequenceConditionNames.Count && i >= 0) { return sequenceConditionNames[i]; } else { return string.Empty; } } public IOperation ConditionOp(int i) { if (sequenceConditions != null && i < sequenceConditions.Count && i >= 0) { return sequenceConditions[i]; } else { return null; } } } }