138 lines
4.2 KiB
C#
138 lines
4.2 KiB
C#
///
|
|
/// 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 easytherm;
|
|
readonly Elde.ControlBoardDev controlBoard;
|
|
|
|
|
|
IList<string> sequenceConditionNames;
|
|
IList<IOperation> sequenceConditions;
|
|
|
|
|
|
/// <summary>
|
|
/// Quido digital out board outputs assignment
|
|
/// </summary>
|
|
private enum QuidoInputs
|
|
{
|
|
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<Generic.IComponent> 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));
|
|
|
|
controlBoard = (Elde.ControlBoardDev)TbfComponents.FindComponent(tankSelectorCfg.ControlBoard, components);
|
|
if (controlBoard == null) throw new Exception(string.Format("Cannot find control board '{0}' for the component {1}", tankSelectorCfg.ControlBoard, Name));
|
|
|
|
CreateConditions(true);
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
public void Initialize() { SetOutputs(0); }
|
|
public void RunDeviceBefore() { }
|
|
public void RunDeviceAfter() { }
|
|
public void StopDevice() { SetOutputs(0); }
|
|
|
|
void CreateConditions(bool createAll)
|
|
{
|
|
sequenceConditionNames = new List<string>();
|
|
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<IOperation>();
|
|
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));
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Set outputs of QuidoRS board
|
|
/// </summary>
|
|
/// <param name="outputs">output value</param>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|