From bedbecbcc31a446b8ad23242a3fd46fc7cecd4fe Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 13 Nov 2019 16:27:18 +0100 Subject: [PATCH] TestMethods.FixedStart.FixedStartSeq code cleanup, references to scale/tank/draining/mass measurement removed. --- .../TestMethods/FixedStart/FixedStartSeq.cs | 152 +++++------------- .../FixedStartMassCollectionSeq.cs | 7 +- 2 files changed, 45 insertions(+), 114 deletions(-) diff --git a/TBF/BenchControl/TestMethods/FixedStart/FixedStartSeq.cs b/TBF/BenchControl/TestMethods/FixedStart/FixedStartSeq.cs index 01317dc8d..582b33cc8 100644 --- a/TBF/BenchControl/TestMethods/FixedStart/FixedStartSeq.cs +++ b/TBF/BenchControl/TestMethods/FixedStart/FixedStartSeq.cs @@ -31,13 +31,6 @@ namespace TBF.BenchControl.TestMethods.FixedStart HeatMeters.TestParams heatMetersTestParams, Config.Entities.DebugMode debugLevel) { - IScale scale = outPath.Scale as IScale; - if (scale == null) - { - Bridge.OnError(this, Strings.Missing_a_scale); - new List { Event.ConfigurationError }; /// or Event.UiCmdStop - } - int rangeIx = 0; /// Default range, used for non-Elde flowmeters if (outPath.FlowMeter is Elde.FlowMeter.FlowMeter) { @@ -138,61 +131,6 @@ namespace TBF.BenchControl.TestMethods.FixedStart } - if (!test.DoDraining) - { - /// - /// Measure the weight in case there is no unconditional draining - /// - State.Create(string.Format("{0}({1}) : Measuring mass of water in the tank", test.Method, test.Name)) - .AddOperation(checkUiOp) - .AddOperations(readTempPressOps) - .AddOperation(scale.ReadMassOp(ref Mass)) - .AddOperation(heatMetersPromptOp) - .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.JustStarted)); - - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - } - while (!e.Contains(Event.BalanceDone)); - } - /// - /// Skip draining in case there is enough room in the tank - /// - if (test.DoDraining || (Mass.Val + test.Volume >= scale.Capacity * Constants.TankFullFactor)) - { - /// - /// Drain the water tank - /// - switch (DrainTheTank(scale, heatMetersPromptOp)) - { - case Event.Error: { retVal = Event.Error; goto stopTest; } - case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } - } - } - /// - /// Make sure the drain valve is closed - /// - State.Create(string.Format("{0}({1}) : Make sure the drain valve is closed", test.Method, test.Name)) - .AddOperation(checkUiOp) - .AddOperations(readTempPressOps) - .AddOperation(scale.ReadMassOp(ref Mass)) - .AddOperation(heatMetersPromptOp) - .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, scale.DrainValve)) - .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.JustStarted)); - - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - } - while (!e.Contains(Event.ValvesSet) || !e.Contains(Event.BalanceDone)); - - - //------------------------------------------------ Bridge.OnActivity(this, Strings.Starting_the_pump); //------------------------------------------------ @@ -371,12 +309,12 @@ namespace TBF.BenchControl.TestMethods.FixedStart { double Tw = (TempRefHi1.Val + TempRefHi2.Val) / 2; double Tc = (TempRefLo1.Val + TempRefLo2.Val) / 2; - if (heatMetersTestParams.TempWarmLo <= Tw && Tw <= heatMetersTestParams.TempWarmHi && - heatMetersTestParams.TempColdLo <= Tc && Tc <= heatMetersTestParams.TempColdHi && - Math.Abs(Tw - Tw_last) <= heatMetersTestParams.ChangeInTimeWarm && - Math.Abs(Tc - Tc_last) <= heatMetersTestParams.ChangeInTimeCold && - Math.Abs(TempRefHi1.Val - TempRefHi2.Val) <= heatMetersTestParams.DeltaTempWarm && - Math.Abs(TempRefLo1.Val - TempRefLo2.Val) <= heatMetersTestParams.DeltaTempCold) + if ((heatMetersTestParams.TempWarmLo <= Tw) && (Tw <= heatMetersTestParams.TempWarmHi) && + (heatMetersTestParams.TempColdLo <= Tc) && (Tc <= heatMetersTestParams.TempColdHi) && + (Math.Abs(Tw - Tw_last) <= heatMetersTestParams.ChangeInTimeWarm) && + (Math.Abs(Tc - Tc_last) <= heatMetersTestParams.ChangeInTimeCold) && + (Math.Abs(TempRefHi1.Val - TempRefHi2.Val) <= heatMetersTestParams.DeltaTempWarm) && + (Math.Abs(TempRefLo1.Val - TempRefLo2.Val) <= heatMetersTestParams.DeltaTempCold)) { goto temperature_set; } @@ -434,26 +372,6 @@ namespace TBF.BenchControl.TestMethods.FixedStart double currentFlow = RefFlow.Val; - //------------------------------------------------ - Bridge.OnActivity(this, Strings.Measuring_the_weight); - //------------------------------------------------ - - if (test.TimeFlow2Mass > 0) - { - State.Create(string.Format("{0}({1}) : Waiting before 1st 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)); - } - - TestStartTime = DateTime.Now; LogProcessDataTestInfo(processDataLogger, test.Procedure.Name, test.Name); int startPulses = 0; @@ -486,8 +404,7 @@ namespace TBF.BenchControl.TestMethods.FixedStart } } state2.EnterState(); - do - { + do { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); @@ -553,12 +470,19 @@ namespace TBF.BenchControl.TestMethods.FixedStart { string srcDir = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString()); string destDir = Path.Combine(Program.ImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString()); - if (File.Exists(Path.Combine(srcDir, fileName))) - { - Directory.CreateDirectory(destDir); - File.Copy(Path.Combine(srcDir, fileName), Path.Combine(destDir, fileName), true); + try + { + if (File.Exists(Path.Combine(srcDir, fileName))) + { + Directory.CreateDirectory(destDir); + File.Copy(Path.Combine(srcDir, fileName), Path.Combine(destDir, fileName), true); + } } - } + catch (Exception exc) + { + log.ErrorFormat("Failed to copy image {0} to {1}: {2}", fileName, destDir, exc.Message); + } + } } } } @@ -603,7 +527,7 @@ namespace TBF.BenchControl.TestMethods.FixedStart queryEnd1 = cBrd.QueryMeasurementEndOp(); queryEnd2 = cBrd.QueryMeasurementEndOp(); - StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, Math.Max((int)(test.TstTime/10), 5)); + StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, Math.Max((int)(test.TstTime / 10), 5)); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; /// Measurement loop - begin @@ -696,22 +620,22 @@ namespace TBF.BenchControl.TestMethods.FixedStart } while (e.Contains(Event.ValvesBusy)); - switchTimeEnd = 0.001f * cBrd.ValveOpenCloseTime; - log.WarnFormat("Start valve switch time on test end = {0} ms", cBrd.ValveOpenCloseTime); - State.Create(string.Format("{0}({1}) : Waiting before 2nd measurement", test.Method, test.Name)) + State.Create(string.Format("{0}({1}) : Stopping flow regulation", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(scale.ReadMassOp(ref Mass)) - .AddOperation(new Operations.TimerOp(test.TimeStop2Mass)) - .AddOperation(processDataLoggingOp) + .AddOperation(cBrd.StopFlowRegulationOp(outPath)) .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)); + while (!e.Contains(Event.FlowRegulationStopped)); + + + switchTimeEnd = 0.001f * cBrd.ValveOpenCloseTime; + log.WarnFormat("Start valve switch time on test end = {0} ms", cBrd.ValveOpenCloseTime); TestEndTime = DateTime.Now; @@ -780,7 +704,8 @@ namespace TBF.BenchControl.TestMethods.FixedStart State state = State.Create(string.Format("{0}({1}) : Entering the end-state", test.Method, test.Name)); if (heatMetersTestParams != null && dataEntryCmpnt is GenericDevices.IHasHeatMtrStatesForm) { - state.AddOperation((dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).ShowTestEndFormOp(sensPath.RegisterReaders, + state.AddOperation((dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm). + ShowTestEndFormOp(sensPath.RegisterReaders, volumeCTV, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty, refEnergy, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty)); } @@ -840,11 +765,18 @@ namespace TBF.BenchControl.TestMethods.FixedStart { string srcDir = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString()); string destDir = Path.Combine(Program.ImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString()); - if (File.Exists(Path.Combine(srcDir, fileName))) - { - Directory.CreateDirectory(destDir); - File.Copy(Path.Combine(srcDir, fileName), Path.Combine(destDir, fileName), true); - } + try + { + if (File.Exists(Path.Combine(srcDir, fileName))) + { + Directory.CreateDirectory(destDir); + File.Copy(Path.Combine(srcDir, fileName), Path.Combine(destDir, fileName), true); + } + } + catch (Exception exc) + { + log.ErrorFormat("Failed to copy image {0} to {1}: {2}", fileName, destDir, exc.Message); + } } } } @@ -1060,7 +992,7 @@ namespace TBF.BenchControl.TestMethods.FixedStart (BenchInfo != null) ? BenchInfo.TestBenchName : "testbench", inPath.Pump != null ? inPath.Pump.Name : string.Empty, outPath.FlowMeter != null ? outPath.FlowMeter.Name : string.Empty, - scale != null ? scale.Name : string.Empty, + string.Empty, outPath.RegulValve != null ? outPath.RegulValve.Name : string.Empty, outPath.Diverter != null ? outPath.Diverter.Name : string.Empty)); diff --git a/TBF/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs b/TBF/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs index e62d384d6..ac6aec7c9 100644 --- a/TBF/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs +++ b/TBF/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs @@ -80,7 +80,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection foreach (var rr in sensPath.RegisterReaders) { TBF.BenchControl.Elde.RegisterReader.RegisterReader eldeRR = rr as TBF.BenchControl.Elde.RegisterReader.RegisterReader; - if (eldeRR != null && eldeRR.Position >= 1 && eldeRR.Position <= 8) + if ((eldeRR != null) && (eldeRR.Position >= 1) && (eldeRR.Position <= 8)) { filters[eldeRR.Position - 1] = eldeRR.Filter; } @@ -618,7 +618,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperation(cBrd.StartMeasurementOp(outPath, (Elde.TestMethods.Diverter | Elde.TestMethods.FixedStart), - test.Qfrom, test.Qto, (2 * totalPulses))) + test.Qfrom, test.Qto, 2 * totalPulses)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); @@ -868,8 +868,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection } } state2.EnterState(); - do - { + do { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test));