From edf35edfba666c61bf727c6626693e02f97bda99 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Fri, 22 May 2015 12:31:10 +0200 Subject: [PATCH] EndCondition in transition steps is checked. Transition steps are finished when tank is empty. --- .../BenchControl/GenericDevices/IBalance.cs | 5 ++ .../MettlerToledo/KeepReadingMassesOp.cs | 61 +++++++++++++++++++ .../MettlerToledo/Multi/BalanceDev.cs | 5 ++ .../MettlerToledo/Standard/BalanceDev.cs | 5 ++ .../BenchControl/Sequences/SequenceBase.cs | 57 +++++++++++++---- TestBenchFramework/TBF.csproj | 1 + 6 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 TestBenchFramework/BenchControl/MettlerToledo/KeepReadingMassesOp.cs diff --git a/TestBenchFramework/BenchControl/GenericDevices/IBalance.cs b/TestBenchFramework/BenchControl/GenericDevices/IBalance.cs index 487751c31..d3eecadd7 100644 --- a/TestBenchFramework/BenchControl/GenericDevices/IBalance.cs +++ b/TestBenchFramework/BenchControl/GenericDevices/IBalance.cs @@ -27,6 +27,11 @@ namespace TBF.BenchControl.GenericDevices /// bool IsEmpty(float mass); + /// + /// Returns true if tank s empty, the last measured mass is less then some threshold + /// + bool IsEmpty(); + /// /// Format string to be used as ToString() argument (e.g. "F3" to obtain resolution 1g) /// diff --git a/TestBenchFramework/BenchControl/MettlerToledo/KeepReadingMassesOp.cs b/TestBenchFramework/BenchControl/MettlerToledo/KeepReadingMassesOp.cs new file mode 100644 index 000000000..f81fe8d73 --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/KeepReadingMassesOp.cs @@ -0,0 +1,61 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using log4net; + +namespace TBF.BenchControl.MettlerToledo +{ + public class KeepReadingMassesOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(KeepReadingMassesOp)); + public override string ToString() { return string.Format("KeepReadingMassesOp()"); } + + bool done; + + /// + /// Events: BalanceDone, Error + /// + /// Balance device instance + /// Required mass readings count (>= 3) + /// Reference to the measured mass in kg + public KeepReadingMassesOp() + { + log.Debug(this.ToString()); + } + + /// Start this operation + public void Start() + { + done = false; + + for (int i = 0; i < Standard.BalanceDev.BalancesCount; i++) + { + Standard.BalanceDev.Balances[i].GetImmediateMassMeasurement(); + } + } + + /// Run this operation + /// + /// Event.None + /// + public Event Run() + { + if (done) return Event.BalanceDone; /// Mass has already been read + + for (int i = 0; i < Standard.BalanceDev.BalancesCount; i++) + { + if (Standard.BalanceDev.Balances[i].MsrmntState != MsrmntState.Busy) + { + Standard.BalanceDev.Balances[i].GetImmediateMassMeasurement(); + } + } + return Event.None; + } + + /// Stop this operation + public void Stop() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceDev.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceDev.cs index d9e0ef8e3..3815e87de 100644 --- a/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceDev.cs +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceDev.cs @@ -106,6 +106,11 @@ namespace TBF.BenchControl.MettlerToledo.Multi log.FatalFormat("Successfully initialized device {0}", ToString()); } + public bool IsEmpty() + { + return (Mass <= balanceCfg.Empty); + } + public bool IsEmpty(float mass) { return (mass <= balanceCfg.Empty); diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Standard/BalanceDev.cs b/TestBenchFramework/BenchControl/MettlerToledo/Standard/BalanceDev.cs index 38b73c17b..e02923a3f 100644 --- a/TestBenchFramework/BenchControl/MettlerToledo/Standard/BalanceDev.cs +++ b/TestBenchFramework/BenchControl/MettlerToledo/Standard/BalanceDev.cs @@ -104,6 +104,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard log.FatalFormat("Successfully initialized device {0}", ToString()); } + public bool IsEmpty() + { + return (this.mass <= balanceCfg.Empty); + } + public bool IsEmpty(float mass) { return (mass <= balanceCfg.Empty); diff --git a/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs b/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs index 49bc0b48e..49877772d 100644 --- a/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs +++ b/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs @@ -400,9 +400,12 @@ namespace TBF.BenchControl.Sequences if (context == TransitionContext.BeforeTest) { State.Create("SequenceBase : Transition : TestStart - Default action") - .AddOperation(checkUiOp).AddOperation(StateMachine.ControlBoard - .SetValvesOp(GenericDevices.ValveBase.Merge(inPath.ValvesOpen, benchPath.ValvesOpen, outPath.ValvesOpen), - GenericDevices.ValveBase.Merge(inPath.ValvesClose, benchPath.ValvesClose, outPath.ValvesClose))) + .AddOperation(checkUiOp) + .AddOperation(new MettlerToledo.KeepReadingMassesOp()) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .AddOperation(StateMachine.ControlBoard + .SetValvesOp(GenericDevices.ValveBase.Merge(inPath.ValvesOpen, benchPath.ValvesOpen, outPath.ValvesOpen), + GenericDevices.ValveBase.Merge(inPath.ValvesClose, benchPath.ValvesClose, outPath.ValvesClose))) .EnterState(); do { @@ -414,8 +417,11 @@ namespace TBF.BenchControl.Sequences else if (context == TransitionContext.AfterTest) { State.Create("SequenceBase : Transition : TestEnd - Default action") - .AddOperation(checkUiOp).AddOperation(StateMachine.ControlBoard - .SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose)) + .AddOperation(checkUiOp) + .AddOperation(new MettlerToledo.KeepReadingMassesOp()) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, + StateMachine.DefaultValvesClose)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); @@ -488,8 +494,11 @@ namespace TBF.BenchControl.Sequences for (int i = 0; i < rvPosOps.Count; i++) { log.DebugFormat("SequenceBase.Transition() : Step {0} start, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose); - State stepStrt = State.Create(string.Format("SequenceBase.Transition() : Step {0} start, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose)) + State stepStrt = State + .Create(string.Format("SequenceBase.Transition() : Step {0} start, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose)) .AddOperation(checkUiOp) + .AddOperation(new MettlerToledo.KeepReadingMassesOp()) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step))); for (int j = 0; j <= i; j++) { @@ -507,9 +516,12 @@ namespace TBF.BenchControl.Sequences if (!(stopFlag || errorFlag)) { log.DebugFormat("SequenceBase.Transition() : Step {0} delay {1}s, opening={2}, closing={3}", step.ItemNr + 1, delay, step.ValvesOpen, step.ValvesClose); - State stepDelay = State.Create(string.Format("SequenceBase.Transition() : Step {0} delay {1}s, opening={2}, closing={3}", step.ItemNr + 1, delay, step.ValvesOpen, step.ValvesClose)) + State stepDelay = State + .Create(string.Format("SequenceBase.Transition() : Step {0} delay {1}s, opening={2}, closing={3}", step.ItemNr + 1, delay, step.ValvesOpen, step.ValvesClose)) .AddOperation(checkUiOp) - .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step))) + .AddOperation(new MettlerToledo.KeepReadingMassesOp()) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step))) .AddOperation(new TimerOp(delay)); for (int j = 0; j <= lastStartedRV; j++) { @@ -517,13 +529,32 @@ namespace TBF.BenchControl.Sequences log.Debug(rvPosStr[j]); } stepDelay.EnterState(); - do + bool endContitionFulfilled = false; + do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error) || e.Contains(Event.RegulValveTimeOut)) { errorFlag = true; break; } if (e.Contains(Event.UiCmdStop)) { stopFlag = true; break; } + + switch (step.EndCondition) + { + case Entities.StepCondition.Scale1Empty: + endContitionFulfilled = (StateMachine.Balance1 == null) || StateMachine.Balance1.IsEmpty(); + break; + case Entities.StepCondition.Scale2Empty: + endContitionFulfilled = (StateMachine.Balance2 == null) || StateMachine.Balance2.IsEmpty(); + break; + case Entities.StepCondition.Scale3Empty: + endContitionFulfilled = (StateMachine.Balance3 == null) || StateMachine.Balance3.IsEmpty(); + break; + case Entities.StepCondition.AllScalesEmpty: + endContitionFulfilled = ((StateMachine.Balance1 == null) || StateMachine.Balance1.IsEmpty()) && + ((StateMachine.Balance2 == null) || StateMachine.Balance2.IsEmpty()) && + ((StateMachine.Balance3 == null) || StateMachine.Balance3.IsEmpty()); + break; + } } - while (e.Contains(Event.TimerBusy) || e.Contains(Event.ValvesBusy)); + while (e.Contains(Event.ValvesBusy) || (!endContitionFulfilled && e.Contains(Event.TimerBusy))); } for (int first = 1; first <= lastStartedRV; first++) @@ -531,7 +562,9 @@ namespace TBF.BenchControl.Sequences log.DebugFormat("SequenceBase.Transition() : Step {0} stop, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose); State stepStop = State.Create(string.Format("SequenceBase.Transition() : Step {0} stop, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose)) .AddOperation(checkUiOp) - .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step))); + .AddOperation(new MettlerToledo.KeepReadingMassesOp()) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step))); for (int j = first; j <= lastStartedRV; j++) { stepStop.AddOperation(rvPosOps[j]); @@ -556,9 +589,9 @@ namespace TBF.BenchControl.Sequences foreach (var fmPump in PumpsWithFM) fmPump.TurnOff(); State.Create("SequenceBase : Test(s) completed -> Stopping the pump") .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) .AddOperation((inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOffOp() : null) .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, inPath.Pump)) - .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) .EnterState(); do { diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 3575f31aa..0f31871cc 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -204,6 +204,7 @@ TempMeterCfgCtrl.cs + UserControl