Draining management under construction
This commit is contained in:
@@ -2,25 +2,153 @@
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using log4net;
|
||||
using TBF.BenchControl.GenericDevices;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.MettlerToledo
|
||||
{
|
||||
public class TankDraining : ComponentBase
|
||||
public enum DrainState
|
||||
{
|
||||
public GenericDevices.IValve DrainValve;
|
||||
None,
|
||||
OpeningDV_Start,
|
||||
OpeningDV_Run,
|
||||
OpeningDV_Stop,
|
||||
Draining,
|
||||
ClosingDV_Start,
|
||||
ClosingDV_Run,
|
||||
ClosingDV_Stop,
|
||||
TankClosed,
|
||||
}
|
||||
|
||||
public class TankDraining : ComponentBase, ITankDraining
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(TankDraining));
|
||||
|
||||
|
||||
readonly GenericDevices.ITankDrainingCfg tankDrainingCfg;
|
||||
|
||||
private IValve drainValve;
|
||||
private IOperation openDrainValveOp;
|
||||
private IOperation closeDrainValveOp;
|
||||
|
||||
|
||||
DrainState drainState;
|
||||
|
||||
GenericDevices.ITankDrainingCfg tankManagementCfg;
|
||||
|
||||
public TankDraining()
|
||||
: base()
|
||||
{
|
||||
CreateConditions(false);
|
||||
}
|
||||
|
||||
public TankDraining(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
tankManagementCfg = cfg as GenericDevices.ITankDrainingCfg;
|
||||
if (tankManagementCfg == null) throw new Exception(string.Format("Cannot create component {0}", cfg.Name));
|
||||
tankDrainingCfg = cfg as GenericDevices.ITankDrainingCfg;
|
||||
if (tankDrainingCfg == null) throw new Exception(string.Format("Cannot create component {0}", cfg.Name));
|
||||
CreateConditions(true);
|
||||
}
|
||||
|
||||
protected void Initalize(IValve drainValve)
|
||||
{
|
||||
this.drainValve = drainValve;
|
||||
openDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, drainValve, null);
|
||||
closeDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, null, drainValve);
|
||||
}
|
||||
|
||||
protected void RunBefore()
|
||||
{
|
||||
switch (drainState)
|
||||
{
|
||||
case DrainState.OpeningDV_Start:
|
||||
openDrainValveOp.Start();
|
||||
drainState = DrainState.OpeningDV_Run;
|
||||
return;
|
||||
|
||||
case DrainState.OpeningDV_Run:
|
||||
if (openDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.OpeningDV_Stop;
|
||||
return;
|
||||
|
||||
case DrainState.OpeningDV_Stop:
|
||||
openDrainValveOp.Stop();
|
||||
return;
|
||||
|
||||
case DrainState.Draining:
|
||||
if (IsEmpty()) drainState = DrainState.ClosingDV_Start;
|
||||
return;
|
||||
|
||||
case DrainState.ClosingDV_Start:
|
||||
closeDrainValveOp.Start();
|
||||
drainState = DrainState.ClosingDV_Run;
|
||||
return;
|
||||
|
||||
case DrainState.ClosingDV_Run:
|
||||
if (closeDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.ClosingDV_Stop;
|
||||
return;
|
||||
|
||||
case DrainState.ClosingDV_Stop:
|
||||
closeDrainValveOp.Stop();
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected void RunAfter() { } /// Not used
|
||||
|
||||
|
||||
public virtual string GetName() { return string.Empty; }
|
||||
public virtual bool IsEmpty() { return false; }
|
||||
|
||||
///
|
||||
/// ISequenceCondition interface implementation (conditions in transition sequences)
|
||||
///
|
||||
IList<string> sequenceConditionNames;
|
||||
IList<IOperation> sequenceConditions;
|
||||
|
||||
public int ConditionsCount { get { return sequenceConditions != null ? sequenceConditions.Count : 0; } }
|
||||
|
||||
/// Strings are added to the combo-box for transition sequence condition selection
|
||||
public string ConditionName(int i)
|
||||
{
|
||||
if (sequenceConditionNames != null && i < sequenceConditionNames.Count && i >= 0)
|
||||
return sequenceConditionNames[i];
|
||||
else
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// Operations are executed as a part of a transition sequence
|
||||
public IOperation ConditionOp(int i)
|
||||
{
|
||||
if (sequenceConditions != null && i < sequenceConditions.Count && i >= 0)
|
||||
return sequenceConditions[i];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
void ClearConditions()
|
||||
{
|
||||
sequenceConditionNames = new List<string>();
|
||||
sequenceConditions = new List<IOperation>();
|
||||
}
|
||||
|
||||
void AddCondition(string conditionName, bool createOperation, IOperation conditionOperation)
|
||||
{
|
||||
sequenceConditionNames.Add(conditionName);
|
||||
if (createOperation) sequenceConditions.Add(conditionOperation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a list of conditions
|
||||
/// </summary>
|
||||
/// <param name="createOps">true = create names and condition operations, false = create names only</param>
|
||||
void CreateConditions(bool createOps)
|
||||
{
|
||||
ClearConditions();
|
||||
AddCondition(string.Format(Strings.Wait_until_0_tank_is_empty, GetName()), createOps, new WaitTankEmptyOp(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user