From 061ab99486e0e952935fe612ba61ad057bb6b045 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 23 Mar 2021 08:25:33 +0100 Subject: [PATCH] Prolonged method fixed, ver. 3.1.1603 --- TBF/Properties/AssemblyInfo.cs | 4 +- TBF/Rig/Dummy/Balance/Component.cs | 2 +- TBF/Rig/Events.cs | 1 + TBF/Rig/GenericDevices/IScale.cs | 4 +- TBF/Rig/MettlerToledo/Multi/BalanceDev.cs | 4 +- .../MettlerToledo/Multi/ReadStableMassOp.cs | 62 +++-- TBF/Rig/MettlerToledo/Standard/BalanceDev.cs | 4 +- .../Standard/ReadStableMassOp.cs | 68 +++-- .../CombinedWithDetectionSeq.cs | 4 +- .../DiverterTest/DiverterTestSeq.cs | 4 +- .../FixedStartAdvancedSeq.cs | 4 +- .../FixedStartMassCollAdvancedSeq.cs | 4 +- .../FixedStartMassCollDeferredEvalSeq.cs | 4 +- .../FixedStartMassCollectionSeq.cs | 4 +- .../FlyingStartFirstRepetWithMassCollSeq.cs | 4 +- .../FlyingStartMassCollComparativeSeq.cs | 6 +- .../FlyingStartMassCollProlongedSeq.cs | 246 ++++-------------- .../FlyingStartMassCollectionSeq.cs | 4 +- TBF/Rig/TestMethods/LeakTest/LeakTestSeq.cs | 4 +- 19 files changed, 165 insertions(+), 272 deletions(-) diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index b04bfa3cb..9ace58492 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("3.1.1602.0")] -[assembly: AssemblyFileVersion("3.1.1602.0")] +[assembly: AssemblyVersion("3.1.1603.0")] +[assembly: AssemblyFileVersion("3.1.1603.0")] diff --git a/TBF/Rig/Dummy/Balance/Component.cs b/TBF/Rig/Dummy/Balance/Component.cs index 7cd1657a0..cc303ed9a 100644 --- a/TBF/Rig/Dummy/Balance/Component.cs +++ b/TBF/Rig/Dummy/Balance/Component.cs @@ -51,7 +51,7 @@ namespace TBF.Rig.Dummy.Balance return this; } - public IOperation ReadStableMassOp(ref Boxes.DoubleBox mass, int readingsCount, double maxSpread, Config.Entities.MassMethod method) + public IOperation ReadStableMassOp(ref Boxes.DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread) { mass.Val = 0; return this; diff --git a/TBF/Rig/Events.cs b/TBF/Rig/Events.cs index efec3ad00..013971faf 100644 --- a/TBF/Rig/Events.cs +++ b/TBF/Rig/Events.cs @@ -86,6 +86,7 @@ namespace TBF.Rig AmbientDone, BalanceDone, BalanceOverload, + ScaleTimeout, PressureDone, PressureInDone, PressureOutDone, diff --git a/TBF/Rig/GenericDevices/IScale.cs b/TBF/Rig/GenericDevices/IScale.cs index cd58e1a23..df4777922 100644 --- a/TBF/Rig/GenericDevices/IScale.cs +++ b/TBF/Rig/GenericDevices/IScale.cs @@ -28,14 +28,14 @@ namespace TBF.Rig.GenericDevices IOperation ReadMassOp(ref DoubleBox mass); /// - /// Events: BalanceDone, Error + /// Events: BalanceDone, Timeout, Error /// /// Reference to a variable for the measured mass in kg /// Required mass readings count (>= 3) /// Maximum spread of measurements in kg (otherwise the measurement continues) /// Method: false = slow (precise), true = fast (immediate) /// ReadMassAverageOp instance reference casted to IOperaton - IOperation ReadStableMassOp(ref DoubleBox mass, int readingsCount, double maxSpread, Config.Entities.MassMethod method); + IOperation ReadStableMassOp(ref DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread); /// /// Events: Done, Error diff --git a/TBF/Rig/MettlerToledo/Multi/BalanceDev.cs b/TBF/Rig/MettlerToledo/Multi/BalanceDev.cs index b281d5a38..ca9c3822e 100644 --- a/TBF/Rig/MettlerToledo/Multi/BalanceDev.cs +++ b/TBF/Rig/MettlerToledo/Multi/BalanceDev.cs @@ -335,9 +335,9 @@ namespace TBF.Rig.MettlerToledo.Multi /// Maximum spread of measurements in kg (otherwise the measurement continues) /// Method: false = slow (precise), true = fast (immediate) /// ReadMassAverageOp instance reference casted to IOperaton - public IOperation ReadStableMassOp(ref DoubleBox mass, int readingsCount, double maxSpread, Config.Entities.MassMethod method) + public IOperation ReadStableMassOp(ref DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread) { - return new ReadStableMassOp(this, ref mass, readingsCount, maxSpread, method); + return new ReadStableMassOp(this, ref mass, delayBefore, method, readingsCount, maxSpread); } /// diff --git a/TBF/Rig/MettlerToledo/Multi/ReadStableMassOp.cs b/TBF/Rig/MettlerToledo/Multi/ReadStableMassOp.cs index 6e12604f8..dd7bfc72e 100644 --- a/TBF/Rig/MettlerToledo/Multi/ReadStableMassOp.cs +++ b/TBF/Rig/MettlerToledo/Multi/ReadStableMassOp.cs @@ -3,6 +3,7 @@ /// using System; using log4net; +using Config.Entities; using TBF.Boxes; namespace TBF.Rig.MettlerToledo.Multi @@ -20,32 +21,35 @@ namespace TBF.Rig.MettlerToledo.Multi int currentReadingsCount; /// Set by the constructor - BalanceDev balanceDev; - int totalReadingsCount; - double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues) - Config.Entities.MassMethod method; /// false = slow (precise), true = fast (immediate) - DoubleBox result; + readonly BalanceDev scale; + readonly DoubleBox result; + readonly int delayBefore; + readonly MassMethod method; /// false = slow (precise), true = fast (immediate) + readonly int totalReadingsCount; + readonly double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues) bool started; + int startTime; /// /// Events: BalanceDone, Error /// - /// Balance device instance + /// Balance device instance /// Reference to the measured mass in kg /// Required mass readings count (>= 3) /// Maximum spread of measurements in kg (otherwise the measurement continues) /// Method: false = slow (precise), true = fast (immediate) - public ReadStableMassOp(BalanceDev balanceDev, ref DoubleBox result, int readingsCount, double maxSpread, Config.Entities.MassMethod method) + public ReadStableMassOp(BalanceDev scale, ref DoubleBox result, int delayBefore, MassMethod method, + int readingsCount, double maxSpread) { - if (balanceDev == null) throw new ArgumentNullException("balanceDev"); - this.balanceDev = balanceDev; + this.scale = scale; + if (this.scale == null) throw new ArgumentNullException("balanceDev"); - this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4 - this.maxSpread = (maxSpread == 0) ? (balanceDev.Capacity / 20000.0) : maxSpread; - this.method = method; - - this.result = result; + this.result = result; + this.delayBefore = delayBefore; + this.method = method; + this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4 + this.maxSpread = (maxSpread == 0) ? (scale.Capacity / 20000.0) : maxSpread; log.Debug(this.ToString()); } @@ -54,11 +58,18 @@ namespace TBF.Rig.MettlerToledo.Multi /// Start this operation public void Start() { - started = false; + startTime = StateMachine.Time; currentReadingsCount = 0; massReadings = new double[totalReadingsCount]; - started = BalanceDev.GetImmediateMassMeasurement(balanceDev.IdNr, balanceDev.Name); - } + if (delayBefore == 0) + { + started = BalanceDev.GetImmediateMassMeasurement(scale.IdNr, scale.Name); + } + else + { + started = false; + } + } /// Run this operation /// @@ -68,13 +79,22 @@ namespace TBF.Rig.MettlerToledo.Multi /// public Event Run() { + if (!started) + { + if (StateMachine.Time >= startTime + delayBefore) + { + started = BalanceDev.GetImmediateMassMeasurement(scale.IdNr, scale.Name); + } + return Event.None; + } + if (currentReadingsCount >= totalReadingsCount) return Event.BalanceDone; /// Mass has already been calculated - if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.None; + if (scale.MsrmntState == MsrmntState.Busy) return Event.None; - if (balanceDev.MsrmntState == MsrmntState.Valid) + if (scale.MsrmntState == MsrmntState.Valid) { - massReadings[currentReadingsCount++] = balanceDev.Mass; + massReadings[currentReadingsCount++] = scale.Mass; if (currentReadingsCount == totalReadingsCount) { @@ -124,7 +144,7 @@ namespace TBF.Rig.MettlerToledo.Multi } } - BalanceDev.GetImmediateMassMeasurement(balanceDev.IdNr, balanceDev.Name); + BalanceDev.GetImmediateMassMeasurement(scale.IdNr, scale.Name); return Event.None; } diff --git a/TBF/Rig/MettlerToledo/Standard/BalanceDev.cs b/TBF/Rig/MettlerToledo/Standard/BalanceDev.cs index f4eb8479e..035cb49d5 100644 --- a/TBF/Rig/MettlerToledo/Standard/BalanceDev.cs +++ b/TBF/Rig/MettlerToledo/Standard/BalanceDev.cs @@ -579,9 +579,9 @@ namespace TBF.Rig.MettlerToledo.Standard /// Maximum spread of measurements in kg (otherwise the measurement continues) /// Method: false = slow (precise), true = fast (immediate) /// ReadMassAverageOp instance reference casted to IOperaton - public IOperation ReadStableMassOp(ref DoubleBox mass, int readingsCount, double maxSpread, Config.Entities.MassMethod method) + public IOperation ReadStableMassOp(ref DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread) { - return new ReadStableMassOp(this, ref mass, readingsCount, maxSpread, method); + return new ReadStableMassOp(this, ref mass, delayBefore, method, readingsCount, maxSpread); } /// diff --git a/TBF/Rig/MettlerToledo/Standard/ReadStableMassOp.cs b/TBF/Rig/MettlerToledo/Standard/ReadStableMassOp.cs index d1d4cd5da..ba33bf0a4 100644 --- a/TBF/Rig/MettlerToledo/Standard/ReadStableMassOp.cs +++ b/TBF/Rig/MettlerToledo/Standard/ReadStableMassOp.cs @@ -3,6 +3,7 @@ /// using System; using log4net; +using Config.Entities; using TBF.Boxes; namespace TBF.Rig.MettlerToledo.Standard @@ -16,17 +17,19 @@ namespace TBF.Rig.MettlerToledo.Standard public override string ToString() { return string.Format("ReadStableMassOp(.,{0},.)", totalReadingsCount); } /// Set by the constructor - BalanceDev scale; - int totalReadingsCount; - double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues) - Config.Entities.MassMethod method; /// by the scale, mass spread threshold or mass standard deviation threshold - DoubleBox result; + readonly BalanceDev scale; + readonly DoubleBox result; + readonly int delayBefore; + readonly MassMethod method; /// by the scale, mass spread threshold or mass standard deviation threshold + readonly int totalReadingsCount; + readonly double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues) /// Operation specific double[] massReadings; double[] sortedMassReadings; int currentReadingsCount; + int startTime; bool activityStarted; bool measurementCompleted; int timeout; @@ -39,15 +42,17 @@ namespace TBF.Rig.MettlerToledo.Standard /// Required mass readings count (>= 4) /// Maximum spread of measurements in kg (otherwise the measurement continues) /// Method: false = slow (precise), true = fast (immediate) - public ReadStableMassOp(BalanceDev scale, ref DoubleBox result, int readingsCount, double maxSpread, Config.Entities.MassMethod method) + public ReadStableMassOp(GenericDevices.IScale scale, ref DoubleBox result, int delayBefore, MassMethod method, + int readingsCount, double maxSpread) { - if (scale == null) throw new ArgumentNullException("balanceDev"); - this.scale = scale; + this.scale = scale as BalanceDev; + if (this.scale == null) throw new ArgumentNullException("balanceDev"); - this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4 + this.result = result; + this.delayBefore = delayBefore; + this.method = method; + this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4 this.maxSpread = (maxSpread == 0) ? (scale.Capacity / 20000.0) : maxSpread; - this.method = method; - this.result = result; massReadings = new double[totalReadingsCount]; sortedMassReadings = new double[totalReadingsCount]; @@ -59,6 +64,15 @@ namespace TBF.Rig.MettlerToledo.Standard log.Debug(this.ToString()); } + /// Internal states of this operation + enum OpState + { + WaitingBeforeMeasurment, + MassMeasurement, + } + + OpState opState; + /// /// Call scale.XYStartMeasurement() function and set measurementStarted flag. /// @@ -73,18 +87,21 @@ namespace TBF.Rig.MettlerToledo.Standard /// Start this operation public void Start() { + startTime = StateMachine.Time; currentReadingsCount = 0; measurementCompleted = false; - if (scale.Activity == Activity.Idle) + if (delayBefore == 0 && scale.Activity == Activity.Idle) { StartMeasurement(); activityStarted = true; scale.Activity = Activity.RunningOperation; + opState = OpState.MassMeasurement; } else { activityStarted = false; + opState = OpState.WaitingBeforeMeasurment; } } @@ -96,16 +113,21 @@ namespace TBF.Rig.MettlerToledo.Standard /// public Event Run() { - scale.MsrmntTime++; - - if (!activityStarted && scale.Activity == Activity.Idle) + if (opState == OpState.WaitingBeforeMeasurment) { - StartMeasurement(); - activityStarted = true; - scale.Activity = Activity.RunningOperation; + if (StateMachine.Time >= startTime + delayBefore && scale.Activity == Activity.Idle) + { + StartMeasurement(); + activityStarted = true; + scale.Activity = Activity.RunningOperation; + opState = OpState.MassMeasurement; + } + return Event.None; } + scale.MsrmntTime++; + if (measurementCompleted) { return Event.BalanceDone; @@ -153,7 +175,7 @@ namespace TBF.Rig.MettlerToledo.Standard result.Val = (massSum / (totalReadingsCount - 2)); log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", result.Val); - measurementCompleted = true; + measurementCompleted = true; return Event.BalanceDone; /// Mass has just been calculated } } @@ -172,8 +194,8 @@ namespace TBF.Rig.MettlerToledo.Standard result.Val = ave; log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", result.Val); - measurementCompleted = true; - return Event.BalanceDone; /// Mass has just been calculated + measurementCompleted = true; + return Event.BalanceDone; /// Mass has just been calculated } } else @@ -187,8 +209,8 @@ namespace TBF.Rig.MettlerToledo.Standard result.Val = (massSum / (totalReadingsCount - 2)); log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", result.Val); - measurementCompleted = true; - return Event.BalanceDone; /// Mass has just been calculated + measurementCompleted = true; + return Event.BalanceDone; /// Mass has just been calculated } } diff --git a/TBF/Rig/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs b/TBF/Rig/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs index 0e8844e4b..ccb95e006 100644 --- a/TBF/Rig/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs +++ b/TBF/Rig/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs @@ -540,7 +540,7 @@ namespace TBF.Rig.TestMethods.CombinedWithDetection .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperations(measureOperations) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .EnterState(); do { @@ -638,7 +638,7 @@ namespace TBF.Rig.TestMethods.CombinedWithDetection State.Create(string.Format("{0}({1}) : Measuring the mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .EnterState(); do { diff --git a/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs b/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs index ef295a961..1bf593548 100644 --- a/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs +++ b/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs @@ -459,7 +459,7 @@ namespace TBF.Rig.TestMethods.DiverterTest .AddOperation(checkUiOp) .AddOperations(measureOperations) .AddOperation(processDataLoggingOp) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperations(readTempPressOps) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .EnterState(); @@ -664,7 +664,7 @@ namespace TBF.Rig.TestMethods.DiverterTest State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); diff --git a/TBF/Rig/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs b/TBF/Rig/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs index 8abd43129..f67274e2f 100644 --- a/TBF/Rig/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs +++ b/TBF/Rig/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs @@ -372,7 +372,7 @@ namespace TBF.Rig.TestMethods.FixedStartAdvanced .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperations(measureOperations) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); @@ -503,7 +503,7 @@ namespace TBF.Rig.TestMethods.FixedStartAdvanced State.Create("FixedStartAdvanced : Measuring the end mass") .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); diff --git a/TBF/Rig/TestMethods/FixedStartMassCollAdvanced/FixedStartMassCollAdvancedSeq.cs b/TBF/Rig/TestMethods/FixedStartMassCollAdvanced/FixedStartMassCollAdvancedSeq.cs index 6ee5bf1e7..763693d43 100644 --- a/TBF/Rig/TestMethods/FixedStartMassCollAdvanced/FixedStartMassCollAdvancedSeq.cs +++ b/TBF/Rig/TestMethods/FixedStartMassCollAdvanced/FixedStartMassCollAdvancedSeq.cs @@ -272,7 +272,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollAdvanced State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); @@ -649,7 +649,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollAdvanced State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); diff --git a/TBF/Rig/TestMethods/FixedStartMassCollDeferredEval/FixedStartMassCollDeferredEvalSeq.cs b/TBF/Rig/TestMethods/FixedStartMassCollDeferredEval/FixedStartMassCollDeferredEvalSeq.cs index 86f24a370..ee43e8693 100644 --- a/TBF/Rig/TestMethods/FixedStartMassCollDeferredEval/FixedStartMassCollDeferredEvalSeq.cs +++ b/TBF/Rig/TestMethods/FixedStartMassCollDeferredEval/FixedStartMassCollDeferredEvalSeq.cs @@ -534,7 +534,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollDeferredEval State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); @@ -817,7 +817,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollDeferredEval State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); diff --git a/TBF/Rig/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs b/TBF/Rig/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs index 62280cc04..7abff6869 100644 --- a/TBF/Rig/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs +++ b/TBF/Rig/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs @@ -510,7 +510,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollection State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); @@ -811,7 +811,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollection State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); diff --git a/TBF/Rig/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs b/TBF/Rig/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs index 3e4f43b2e..5cad61ef6 100644 --- a/TBF/Rig/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs @@ -550,7 +550,7 @@ namespace TBF.Rig.TestMethods.FlyingStartFirstRepetWithMassColl .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperations(cameraMeasurementOps) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); @@ -691,7 +691,7 @@ namespace TBF.Rig.TestMethods.FlyingStartFirstRepetWithMassColl State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); diff --git a/TBF/Rig/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs b/TBF/Rig/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs index 8184ce3af..7b57d7b43 100644 --- a/TBF/Rig/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs @@ -581,7 +581,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperations(cameraMeasurementOps) - .AddOperation(scale.ReadStableMassOp(ref measuredRefMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); @@ -649,7 +649,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperations(cameraMeasurementOps) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); @@ -797,7 +797,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); diff --git a/TBF/Rig/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs b/TBF/Rig/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs index 54cc9162b..6f0ee225e 100644 --- a/TBF/Rig/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs @@ -519,21 +519,6 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged Bridge.OnActivity(this, Strings.Measuring_the_weight); //------------------------------------------------ - if (test.TimeFlow2Mass > 0) - { - State.Create(string.Format("{0}({1}) : Waiting before 1st mass measurement", test.Method, test.Name)) - .AddOperation(checkUiOp) - .AddOperations(readTempPressOps) - .AddOperation(new Operations.TimerOp(test.TimeFlow2Mass)) - .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } - } - while (!e.Contains(Event.TimerExpired)); - } - LogProcessDataTestInfo(processDataLogger, test.Procedure.Name, test.Name); if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Start mass"); @@ -543,7 +528,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged .AddOperation(checkUiOp) .AddOperations(cameraMeasurementOps) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, test.TimeFlow2Mass, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); @@ -574,31 +559,19 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged /// Measurement loop preparation int estimtdEndTime = StateMachine.Time + (int)test.TestTime; - int remainingTime; StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, 0); - bool isTestPart2Completed = false; - var prolongedTest = cBrd.FlyingStartStopTestOp(test, test.Qfrom, test.Qto, targetTotalPulses, true, true, targetMassPulses); - IList testInProgressOps = new List(); - testInProgressOps.Add(checkUiOp); - foreach (var op in readTempPressOps) - testInProgressOps.Add(op); - foreach (var op in cameraMeasurementOps) - testInProgressOps.Add(op); - testInProgressOps.Add(prolongedTest); /// Event.MeasurementCompleted - testInProgressOps.Add(processDataLoggingOp); - - IList testCompletedOps = new List(); - testCompletedOps.Add(checkUiOp); - foreach (var op in readTempPressOps) - testCompletedOps.Add(op); - testCompletedOps.Add(processDataLoggingOp); - + /// /// Measurement loop - 1st part + /// State.Create(string.Format("{0}({1}) : Starting the test", test.Method, test.Name)) - .AddOperations(testInProgressOps) + .AddOperation(checkUiOp) + .AddOperations(readTempPressOps) + .AddOperations(cameraMeasurementOps) + .AddOperation(prolongedTest) + .AddOperation(processDataLoggingOp) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); @@ -607,179 +580,56 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime); + /// Proceed to 2nd part of the test when diverter turns back to sink, 'Next' button can be used in Debug version } - /// Proceed to 2nd part of test when diverter turns back to sink, 'Next' button can be used in Debug version while (!e.Contains(Event.TestPart2InProgress) && !e.Contains(Event.Next)); - - /// - /// Waiting before the 2nd mass measurement - /// - bool waitingBeforeEndMassMeasurementCompleted = false; - IOperation stop2MassTimerOp = new Operations.TimerOp(test.TimeStop2Mass); - do { - State.Create(string.Format("{0}({1}) : Waiting before the 2nd mass measurement", test.Method, test.Name)) - .AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps) - .AddOperation(stop2MassTimerOp) - .EnterState(); - - if (!isTestPart2Completed) - { - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true; - waitingBeforeEndMassMeasurementCompleted = (e.Contains(Event.TimerExpired) && e.Contains(Event.BalanceDone)); - DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime); - } - while (!isTestPart2Completed && !waitingBeforeEndMassMeasurementCompleted); - } - else - { - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - waitingBeforeEndMassMeasurementCompleted = (e.Contains(Event.TimerExpired) && e.Contains(Event.BalanceDone)); - } - while (!waitingBeforeEndMassMeasurementCompleted); - } - } - while (!waitingBeforeEndMassMeasurementCompleted); - - if (heatMetersPath == null) - LogProcessDataHeader(processDataLogger, "End mass"); - else - LogProcessDataHeaderHeatMeters(processDataLogger, "End mass"); /// - /// Measuring the end mass + /// 2nd part of the test and simultaneous measurement the end mass /// - Bridge.OnActivity(this, Strings.Measuring_the_weight); - IOperation readStableMassOp = scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod); - IOperation massMsrmntTimerOp = new Operations.TimerOp(StableMassMsrmntTimeoutSec); - bool measuringEndMassCompleted = false; - do - { - State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) - .AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps) - .AddOperation(readStableMassOp) - .AddOperation(massMsrmntTimerOp) - .EnterState(); - - if (!isTestPart2Completed) - { - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - if (e.Contains(Event.TimerExpired)) - { - Bridge.OnError(this, Strings.Mass_measurement_timeout); - retVal = Event.RecoverableError; - goto stopTest; - } - if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true; - measuringEndMassCompleted = e.Contains(Event.BalanceDone); - DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime, false); - } - while (!isTestPart2Completed && !measuringEndMassCompleted); - } - else - { - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - if (e.Contains(Event.TimerExpired)) - { - Bridge.OnError(this, Strings.Mass_measurement_timeout); - retVal = Event.RecoverableError; - goto stopTest; - } - measuringEndMassCompleted = e.Contains(Event.BalanceDone); - } - while (!measuringEndMassCompleted); - } - } - while (!measuringEndMassCompleted); - /// - tMass2 = StateMachine.Time; - log.WarnFormat("End mass = {0}kg", EndMass); - TestEndTime = DateTime.Now; - - if (test.DoDrainingAfter) - { - /// - /// Draining after the 2nd mass measurement enabled, empty the tank - /// - IOperation setValvesOp = cBrd.SetValvesOp(scale.DrainValve, null); - bool openingDrainValveCompleted = false; - do { - State.Create(string.Format("{0}({1}) : Open the drain valve", test.Method, test.Name)) - .AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps) - .AddOperation(setValvesOp) - .EnterState(); - - if (!isTestPart2Completed) - { - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true; - openingDrainValveCompleted = !e.Contains(Event.ValvesBusy); - DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime); - } - while (!isTestPart2Completed && !openingDrainValveCompleted); - } - else - { - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - openingDrainValveCompleted = !e.Contains(Event.ValvesBusy); - } - while (!openingDrainValveCompleted); - } - } - while (!openingDrainValveCompleted); - } - - if (!isTestPart2Completed) - { - /// - /// Measurement loop - 2nd part, diverter is in state 'To sink' - /// - State.Create(string.Format("{0}({1}) : Reading watermeters", test.Method, test.Name)) - .AddOperations(testInProgressOps) - .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime); - } - while (!e.Contains(Event.TestCompleted) && !e.Contains(Event.Next)); /// Quit the measurement loop when there is Event.MeasurementCompleted - /// 'Next' button can be used in Debug version - } - - test_completed: - - StopRecordingStatistics(); - - State.Create(string.Format("{0}({1}) : Stopping flow regulation", test.Method, test.Name)) + State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(cBrd.StopFlowRegulationOp()) + .AddOperations(cameraMeasurementOps) + .AddOperation(prolongedTest) + .AddOperation(scale.ReadStableMassOp(ref EndMass, test.TimeStop2Mass, test.MassMethod, test.MassRepeats, test.MassSpread)) + .AddOperation(processDataLoggingOp) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + + DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime); + /// Continue in 2nd part of the test when mass measurement is completed, 'Next' button can be used in Debug version } - while (!e.Contains(Event.FlowRegulationStopped)); + while (!e.Contains(Event.BalanceDone) && !e.Contains(Event.ScaleTimeout) && !e.Contains(Event.Next)); + + /// + /// 2nd part of the test and optional opening of the drain valve + /// + State.Create(string.Format("{0}({1}) : 2nd part of the test is running", test.Method, test.Name)) + .AddOperation(checkUiOp) + .AddOperations(readTempPressOps) + .AddOperations(cameraMeasurementOps) + .AddOperation(prolongedTest) + .AddOperation(test.DoDrainingAfter ? cBrd.SetValvesOp(scale.DrainValve, null) : null) + .AddOperation(processDataLoggingOp) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + + DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime); + } + while (!e.Contains(Event.TestCompleted) && !e.Contains(Event.Next)); + + StopRecordingStatistics(); /// /// (Berlin:) Water is stopped immediately after the test and before the 2nd mass measurement in case: diff --git a/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs b/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs index 581120d4d..6b23bf869 100644 --- a/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs @@ -539,7 +539,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection .AddOperation(checkUiOp) .AddOperations(cameraMeasurementOps) .AddOperation(processDataLoggingOp) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperations(readTempPressOps) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .EnterState(); @@ -684,7 +684,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); diff --git a/TBF/Rig/TestMethods/LeakTest/LeakTestSeq.cs b/TBF/Rig/TestMethods/LeakTest/LeakTestSeq.cs index 92e101cc6..a9f8ebb55 100644 --- a/TBF/Rig/TestMethods/LeakTest/LeakTestSeq.cs +++ b/TBF/Rig/TestMethods/LeakTest/LeakTestSeq.cs @@ -257,7 +257,7 @@ namespace TBF.Rig.TestMethods.LeakTest State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .EnterState(); do { @@ -315,7 +315,7 @@ namespace TBF.Rig.TestMethods.LeakTest State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .EnterState(); do {