121 lines
2.8 KiB
C#
121 lines
2.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.QuidoRS.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 QuidoRS quidoRS;
|
|
|
|
|
|
public enum CurrentOp
|
|
{
|
|
None,
|
|
SelectTank,
|
|
}
|
|
|
|
CurrentOp currentOp;
|
|
|
|
|
|
public TankSelector()
|
|
{
|
|
}
|
|
|
|
public TankSelector(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
tankSelectorCfg = cfg as TankSelectorCfg;
|
|
|
|
quidoRS = (QuidoRS)TbfComponents.FindComponent(cfg.ParentName, components);
|
|
if (quidoRS == null) throw new Exception("Cannot find " + Name + " parent");
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|