diff --git a/TestBenchFramework/BenchControl/MettlerToledo/TankDraining.cs b/TestBenchFramework/BenchControl/MettlerToledo/TankDraining.cs index 6cf744ed3..9b7eb4b29 100644 --- a/TestBenchFramework/BenchControl/MettlerToledo/TankDraining.cs +++ b/TestBenchFramework/BenchControl/MettlerToledo/TankDraining.cs @@ -22,7 +22,7 @@ namespace TBF.BenchControl.MettlerToledo TankClosed, } - public class TankDraining : ComponentBase, ITankDraining + public class TankDraining : ComponentBase, ITankDraining, ISequenceCondition { private static readonly ILog log = LogManager.GetLogger(typeof(TankDraining)); @@ -32,8 +32,9 @@ namespace TBF.BenchControl.MettlerToledo private IValve drainValve; public GenericDevices.IValve DrainValve { get { return drainValve; } } - private IOperation openDrainValveOp; - private IOperation closeDrainValveOp; + private IOperation openTheDrainValveOp; + private IOperation closeTheDrainValveOp; + private IOperation waitTankEmptyOp; DrainState drainState; @@ -42,7 +43,9 @@ namespace TBF.BenchControl.MettlerToledo public TankDraining() : base() { - CreateConditions(false); + openTheDrainValveOp = null; + closeTheDrainValveOp = null; + waitTankEmptyOp = null; } public TankDraining(Generic.IComponentCfg cfg) @@ -50,14 +53,19 @@ namespace TBF.BenchControl.MettlerToledo { tankDrainingCfg = cfg as GenericDevices.ITankDrainingCfg; if (tankDrainingCfg == null) throw new Exception(string.Format("Cannot create component {0}", cfg.Name)); - CreateConditions(true); + + openTheDrainValveOp = null; + closeTheDrainValveOp = null; + waitTankEmptyOp = null; } protected void Initalize() { drainValve = TbfComponents.FindComponent(tankDrainingCfg.DrainValve) as IValve; - openDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, drainValve, null); - closeDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, null, drainValve); + + openTheDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, drainValve, null); + closeTheDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, null, drainValve); + waitTankEmptyOp = new WaitTankEmptyOp(this); } protected void RunBefore() @@ -65,16 +73,16 @@ namespace TBF.BenchControl.MettlerToledo switch (drainState) { case DrainState.OpeningDV_Start: - openDrainValveOp.Start(); + openTheDrainValveOp.Start(); drainState = DrainState.OpeningDV_Run; return; case DrainState.OpeningDV_Run: - if (openDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.OpeningDV_Stop; + if (openTheDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.OpeningDV_Stop; return; case DrainState.OpeningDV_Stop: - openDrainValveOp.Stop(); + openTheDrainValveOp.Stop(); return; case DrainState.Draining: @@ -82,16 +90,16 @@ namespace TBF.BenchControl.MettlerToledo return; case DrainState.ClosingDV_Start: - closeDrainValveOp.Start(); + closeTheDrainValveOp.Start(); drainState = DrainState.ClosingDV_Run; return; case DrainState.ClosingDV_Run: - if (closeDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.ClosingDV_Stop; + if (closeTheDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.ClosingDV_Stop; return; case DrainState.ClosingDV_Stop: - closeDrainValveOp.Stop(); + closeTheDrainValveOp.Stop(); return; default: @@ -105,52 +113,32 @@ namespace TBF.BenchControl.MettlerToledo public virtual string GetName() { return string.Empty; } public virtual bool IsEmpty() { return false; } - /// - /// ISequenceCondition interface implementation (conditions in transition sequences) - /// - IList sequenceConditionNames; - IList sequenceConditions; - public int ConditionsCount { get { return sequenceConditions != null ? sequenceConditions.Count : 0; } } + + public int ConditionsCount { get { return 3; } } /// 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; + switch (i) + { + case 0: return string.Format(Strings._0_open_the_drain_valve, Name); + case 1: return string.Format(Strings._0_close_the_drain_valve, Name); + case 2: return string.Format(Strings._0_wait_until_the_tank_is_empty, Name); + default: return string.Empty; + } } - /// Operations are executed as a part of a transition sequence + /// Operation to be 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(); - sequenceConditions = new List(); - } - - void AddCondition(string conditionName, bool createOperation, IOperation conditionOperation) - { - sequenceConditionNames.Add(conditionName); - if (createOperation) sequenceConditions.Add(conditionOperation); - } - - /// - /// Create a list of conditions - /// - /// true = create names and condition operations, false = create names only - void CreateConditions(bool createOps) - { - ClearConditions(); - AddCondition(string.Format(Strings.Wait_until_0_tank_is_empty, GetName()), createOps, new WaitTankEmptyOp(this)); + switch (i) + { + case 0: return openTheDrainValveOp; + case 1: return closeTheDrainValveOp; + case 2: return waitTankEmptyOp; + default: return null; + } } } } diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index 54c457cc5..786a3f23a 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -60,6 +60,33 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to {0} - close the drain valve. + /// + internal static string _0_close_the_drain_valve { + get { + return ResourceManager.GetString("_0_close_the_drain_valve", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} - open the drain valve. + /// + internal static string _0_open_the_drain_valve { + get { + return ResourceManager.GetString("_0_open_the_drain_valve", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} - wait until the tank is empty. + /// + internal static string _0_wait_until_the_tank_is_empty { + get { + return ResourceManager.GetString("_0_wait_until_the_tank_is_empty", resourceCulture); + } + } + /// /// Looks up a localized string similar to <none>. /// diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index acbe44449..d1d732509 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -1747,4 +1747,13 @@ Close the cover + + {0} - close the drain valve + + + {0} - open the drain valve + + + {0} - wait until the tank is empty + \ No newline at end of file