147 lines
3.8 KiB
C#
147 lines
3.8 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Modbus.TankSelector
|
|
{
|
|
public class TankSelector : ComponentBase, IOperation
|
|
{
|
|
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;
|
|
|
|
|
|
public enum CurrentOp
|
|
{
|
|
None,
|
|
SelectTank,
|
|
}
|
|
|
|
CurrentOp currentOp;
|
|
|
|
|
|
/// <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()
|
|
{
|
|
}
|
|
|
|
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));
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set outputs of QuidoRS board
|
|
/// </summary>
|
|
/// <param name="outputs">output value</param>
|
|
public void SetOutputs(uint outputs)
|
|
{
|
|
quidoRS.SetOutputs((ushort)outputs);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Events: SetOpututsDone, Error
|
|
/// </summary>
|
|
/// <param name="outValue">Reference to a variable for the pressure in Bar</param>
|
|
/// <returns>SetOutputsOp instance reference casted to IOperaton</returns>
|
|
//public IOperation SetOutputsOp(ushort outValue)
|
|
//{
|
|
// return new SetOutputsOp(this, outValue);
|
|
//}
|
|
|
|
/// <summary>
|
|
/// Events: pressureDone, Error
|
|
/// </summary>
|
|
/// <param name="outValue">Reference to a variable for the pressure in Bar</param>
|
|
/// <param name="setOutputsDone">Event returned when SetOutput is done</param>
|
|
/// <returns>SetOutputsOp instance reference casted to IOperaton</returns>
|
|
//public IOperation ReadPressureOp(ushort outValue, Event setOutputsDone)
|
|
//{
|
|
// return new SetOutputsOp(this, outValue, setOutputsDone);
|
|
//}
|
|
|
|
int tankNo;
|
|
///
|
|
public IOperation SelectTankOp(int tankNo)
|
|
{
|
|
if (currentOp != CurrentOp.None)
|
|
{
|
|
throw new Exception("Cannot start operation 'SelectTankOp'");
|
|
}
|
|
this.tankNo = tankNo;
|
|
currentOp = CurrentOp.SelectTank;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
switch (currentOp)
|
|
{
|
|
case CurrentOp.SelectTank:
|
|
SetOutputs((tankNo==1) ? 1u : ((tankNo==2) ? 2u : ((tankNo==3) ? 3u : 0)));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
public Event Run()
|
|
{
|
|
switch (currentOp)
|
|
{
|
|
case CurrentOp.SelectTank:
|
|
return Event.Done;
|
|
default:
|
|
return Event.Done;
|
|
}
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
currentOp = CurrentOp.None;
|
|
}
|
|
}
|
|
}
|