diff --git a/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs b/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs index c1206bd20..261e8efad 100644 --- a/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs +++ b/TBF/Rig/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs @@ -1,26 +1,28 @@ -/// +using Common; +using Config.Entities; +using log4net; +/// /// Copyright (c) 2013-2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; +using System.IO; using System.Text; -using log4net; -using Common; -using Config.Entities; -using TBF.Rig; +using System.Xml.Serialization; using TBF.Boxes; using TBF.Resources; -using TBF.UiBridge; +using TBF.Rig; using TBF.Rig.GenericDevices; using TBF.Rig.RegisterReaders.PoseidonReader; using TBF.Rig.RegisterReaders.PoseidonReader.implementations; using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication.common; +using TBF.UiBridge;  namespace TBF.Rig.TestMethods.FlyingStartMassCollection { - public class FlyingStartMassCollectionSeq : Sequences.SequenceBase + public class FlyingStartMassCollectionSeq : Sequences.SequenceBase { - private static readonly ILog log = LogManager.GetLogger(typeof(FlyingStartMassCollectionSeq)); + private static readonly ILog log = LogManager.GetLogger(typeof(FlyingStartMassCollectionSeq));  ///  /// Check capabilities of devces in the output path required for this test method @@ -44,11 +46,11 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection }  if (test.Volume > devices.Scale.Capacity * Constants.TankFullFactor) - { + { /// Scale capacity is not sufficient message = string.Format("{0}: {1}", test.Name, Strings.Test_volume_exceeds_the_scale_capacity); return false; - } + }  if (!(devices.Diverter is IDiverter)) { @@ -75,28 +77,28 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection return true; }  - ///  - /// Flying start mass collection method sequence - ///  - /// Test entity - ///  - /// Event.Done . . . . . . . OK - /// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP - /// Event.OpArgumentError . Target flow is out of range - /// Event.Error . . . . . . Unspecified error - ///  - public IList Execute(Test test, int repetitionNr, bool isLastRepetition, + ///  + /// Flying start mass collection method sequence + ///  + /// Test entity + ///  + /// Event.Done . . . . . . . OK + /// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP + /// Event.OpArgumentError . Target flow is out of range + /// Event.Error . . . . . . Unspecified error + ///  + public IList Execute(Test test, int repetitionNr, bool isLastRepetition, bool isDelayedStart, Compound.CombinedTestParams compoundTestParams, HeatMeters.TestParams heatMetersTestParams, DebugMode debugLevel) - { - if (debugLevel == Common.DebugMode.Simulate) - { - return Simulate1(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams); - } - else if (debugLevel == Common.DebugMode.Inherit) - { - return Simulate2(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams); - } + { + if (debugLevel == Common.DebugMode.Simulate) + { + return Simulate1(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams); + } + else if (debugLevel == Common.DebugMode.Inherit) + { + return Simulate2(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams); + }  ControlBoard.Uni.UniCB cBrd = StateMachine.ControlBoardMain as ControlBoard.Uni.UniCB; IScale scale = cBrd.Devices.Scale as IScale; @@ -131,30 +133,31 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection cBrd.SetFiltersPidShortPulses(filters, outPath.PidCoef, test.ShortPulses);  IList readTempPressOps = new List(); - if(benchPath.TempMtrUp != null) readTempPressOps.Add(benchPath.TempMtrUp.ReadTempOp(ref TempUp)); - if(benchPath.TempMtrDown != null) readTempPressOps.Add(benchPath.TempMtrDown.ReadTempOp(ref TempDown)); - if(outPath.TempMtrDiv != null) readTempPressOps.Add(outPath.TempMtrDiv.ReadTempOp(ref TempDiv)); - if(benchPath.PressMtrUp != null) readTempPressOps.Add(benchPath.PressMtrUp.ReadPressureOp(ref PressUp)); - if(benchPath.PressMtrDown != null) readTempPressOps.Add(benchPath.PressMtrDown.ReadPressureOp(ref PressDown)); - if(benchPath.PressMtrDelta != null) readTempPressOps.Add(benchPath.PressMtrDelta.ReadPressureOp(ref PressDelta)); - if(benchPath.ElectricMtrUp != null) readTempPressOps.Add(benchPath.ElectricMtrUp.ReadPressureOp(ref ElectricUp)); - if(benchPath.ElectricMtrDown != null) readTempPressOps.Add(benchPath.ElectricMtrDown.ReadPressureOp(ref ElectricDown)); - if(benchPath.ElectricMtrDelta != null) readTempPressOps.Add(benchPath.ElectricMtrDelta.ReadPressureOp(ref ElectricDelta)); - if(heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefWarm1.ReadTempOp(ref TempRefHi1)); - if(heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefWarm2.ReadTempOp(ref TempRefHi2)); - if(heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefCold1.ReadTempOp(ref TempRefLo1)); - if(heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefCold2.ReadTempOp(ref TempRefLo2)); + if (benchPath.TempMtrUp != null) readTempPressOps.Add(benchPath.TempMtrUp.ReadTempOp(ref TempUp)); + if (benchPath.TempMtrDown != null) readTempPressOps.Add(benchPath.TempMtrDown.ReadTempOp(ref TempDown)); + if (outPath.TempMtrDiv != null) readTempPressOps.Add(outPath.TempMtrDiv.ReadTempOp(ref TempDiv)); + if (benchPath.PressMtrUp != null) readTempPressOps.Add(benchPath.PressMtrUp.ReadPressureOp(ref PressUp)); + if (benchPath.PressMtrDown != null) readTempPressOps.Add(benchPath.PressMtrDown.ReadPressureOp(ref PressDown)); + if (benchPath.PressMtrDelta != null) readTempPressOps.Add(benchPath.PressMtrDelta.ReadPressureOp(ref PressDelta)); + if (benchPath.ElectricMtrUp != null) readTempPressOps.Add(benchPath.ElectricMtrUp.ReadPressureOp(ref ElectricUp)); + if (benchPath.ElectricMtrDown != null) readTempPressOps.Add(benchPath.ElectricMtrDown.ReadPressureOp(ref ElectricDown)); + if (benchPath.ElectricMtrDelta != null) readTempPressOps.Add(benchPath.ElectricMtrDelta.ReadPressureOp(ref ElectricDelta)); + if (heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefWarm1.ReadTempOp(ref TempRefHi1)); + if (heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefWarm2.ReadTempOp(ref TempRefHi2)); + if (heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefCold1.ReadTempOp(ref TempRefLo1)); + if (heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefCold2.ReadTempOp(ref TempRefLo2));  int totalPulses = Convert.ToInt32(test.Volume / outPath.FlowMeter.LtrPerPulse);  ///============================================================================================ -  + /// Read pressure and temperature once before calling Bridge.OnTestSelected(...) State.Create(string.Format("{0}({1}) : Measuring process data", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .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; } @@ -163,8 +166,8 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection  /// Start the test, initialize test results Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, heatMetersPath)); - string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); - TestStartTime = DateTime.Now; + string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); + TestStartTime = DateTime.Now;  //------------------------------------------------ Bridge.OnActivity(this, Strings.Checking_tank_capacity); @@ -189,35 +192,36 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection .AddOperation(cBrd.SetValvesOp(scale.DrainValve, null)) .AddOperations(readTempPressOps) .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.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } } while (e.Contains(Event.ValvesBusy)); #endif }   - /// - /// Optionally display prompt to emerge temperature meters to appropriate baths for heat meters test - /// - IOperation heatMetersPromptOp = null; - if (heatMetersTestParams != null && !string.IsNullOrEmpty(heatMetersTestParams.Prompt)) - { - /// Make sure the CycleBeginForm is closed - if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest; + /// + /// Optionally display prompt to emerge temperature meters to appropriate baths for heat meters test + /// + IOperation heatMetersPromptOp = null; + if (heatMetersTestParams != null && !string.IsNullOrEmpty(heatMetersTestParams.Prompt)) + { + /// Make sure the CycleBeginForm is closed + if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest;  - heatMetersPromptOp = new Operations.MessageBoxOp(heatMetersTestParams.Prompt); - } + heatMetersPromptOp = new Operations.MessageBoxOp(heatMetersTestParams.Prompt); + }   //------------------------------------------------ Bridge.OnActivity(this, Strings.Starting_the_pump); //------------------------------------------------  - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting)); - int flowSetTime0 = StateMachine.Time; + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting)); + int flowSetTime0 = StateMachine.Time;   if (inPath.Pump is GenericDevices.IPumpFM) @@ -227,12 +231,13 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection /// State.Create(string.Format("{0}({1}) : Starting pump {2}", test.Method, test.Name, (inPath.Pump != null) ? inPath.Pump.Name : "?")) .AddOperation(checkUiOp) -// .AddOperation(new Operations.SetAllRegulValvesOp(inPath.RegulValves, inPath.RegulValvesPct, 60)) + // .AddOperation(new Operations.SetAllRegulValvesOp(inPath.RegulValves, inPath.RegulValvesPct, 60)) .AddOperations(readTempPressOps) .AddOperation(heatMetersPromptOp) .AddOperation(inPath.Pump != null ? cBrd.SetValvesOp(inPath.Pump, null) : null) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  @@ -249,8 +254,9 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection .AddOperation(new Operations.TimerOp(test.TimePump2StartV)) .AddOperations(readTempPressOps) .AddOperation(heatMetersPromptOp) - .EnterState(); - do { + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  @@ -267,11 +273,12 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection .AddOperation(cBrd.SetValvesOp(benchPath.StopBFValve, null)) .AddOperations(readTempPressOps) .AddOperation(heatMetersPromptOp) - .EnterState(); - do { + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } } while (!e.Contains(Event.ValvesSet)); } @@ -284,8 +291,9 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection .AddOperation(new Operations.TimerOp(test.TimeBeforeFlow)) .AddOperations(readTempPressOps) .AddOperation(heatMetersPromptOp) - .EnterState(); - do { + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  @@ -302,13 +310,14 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection .AddOperation(cBrd.SetFlowOp(test.QfromM3ph(), test.QtoM3ph(), RefFlow, FlowSettingTimeoutSec)) .AddOperations(readTempPressOps) .AddOperation(heatMetersPromptOp) - .EnterState(); - do { + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  - if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.RegulValveTimeOut)) { Bridge.OnError(this, Strings.Flow_adjustment_failed); @@ -334,12 +343,13 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection double Tw_last = 0; double Tc_last = 0;  - State.Create(string.Format("{0}({1}) : Check temperature stabilized.", test.Method, test.Name)) + State.Create(string.Format("{0}({1}) : Check temperature stabilized.", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperation(heatMetersPromptOp) - .EnterState(); - do { + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.Next)) goto temperature_set; @@ -368,63 +378,64 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection } while (true); } - else if (!string.IsNullOrEmpty(test.TempControl) && benchPath.TempMtrUp != null && benchPath.TempMtrDown != null) - { - //--------------------------------------------------- - Bridge.OnActivity(this, Strings.Setting_temperature); - //--------------------------------------------------- - - State.Create(string.Format("{0}({1}) : Wait until the water temperature is within limits", test.Method, test.Name)) - .AddOperation(checkUiOp) + else if (!string.IsNullOrEmpty(test.TempControl) && benchPath.TempMtrUp != null && benchPath.TempMtrDown != null) + { + //--------------------------------------------------- + Bridge.OnActivity(this, Strings.Setting_temperature); + //--------------------------------------------------- + + State.Create(string.Format("{0}({1}) : Wait until the water temperature is within limits", test.Method, test.Name)) + .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - if (e.Contains(Event.Next)) goto temperature_set; + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.Next)) goto temperature_set;  if ((test.TempLimLo <= TempUp.Val) && (TempUp.Val <= test.TempLimHi) && (test.TempLimLo <= TempDown.Val) && (TempDown.Val <= test.TempLimHi)) { - goto temperature_set; - } - } - while (true); - } + goto temperature_set; + } + } + while (true); + }  temperature_set:  /// - /// Prepare cameras, ROI-s and measurementOperations - /// + /// Prepare cameras, ROI-s and measurementOperations + ///  - /// Find successfully detected ROI-s - IList rois = new List(); - foreach (var rr in sensPath.RegisterReaders) - { + /// Find successfully detected ROI-s + IList rois = new List(); + foreach (var rr in sensPath.RegisterReaders) + { GenericDevices.IRegReaderLiveCamera cameraRoI = rr as GenericDevices.IRegReaderLiveCamera; if ((cameraRoI != null) && cameraRoI.Detected) { rois.Add(cameraRoI); } - } + }  - /// Find cameras - IList cameras = new List(); + /// Find cameras + IList cameras = new List(); foreach (var roi in rois) { - if (roi.Camera != null && !cameras.Contains(roi.Camera)) - { - cameras.Add(roi.Camera); - roi.Camera.ClearRoiParams(); - } + if (roi.Camera != null && !cameras.Contains(roi.Camera)) + { + cameras.Add(roi.Camera); + roi.Camera.ClearRoiParams(); + } }  - /// Register ROI-parameters to cameras - foreach (var roi in rois) roi.RegisterRoiToCamera(); + /// Register ROI-parameters to cameras + foreach (var roi in rois) roi.RegisterRoiToCamera();  - /// Prepare measurementOperations - IList cameraMeasurementOps = new List(); + /// Prepare measurementOperations + IList cameraMeasurementOps = new List(); foreach (var camera in cameras) { cameraMeasurementOps.Add(camera.MeasurementOp()); @@ -446,60 +457,62 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection }   - if (drainTheTank) - { - //------------------------------------------------ - Bridge.OnActivity(this, Strings.Closing_the_tank); - //------------------------------------------------ + if (drainTheTank) + { + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Closing_the_tank); + //------------------------------------------------  - /// - /// Make sure tank draining completed - /// + /// + /// Make sure tank draining completed + /// switch (DrainTheTank(scale, readTempPressOps)) - { - case Event.Error: { retVal = Event.Error; goto stopTest; } - case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } - } + { + case Event.Error: { retVal = Event.Error; goto stopTest; } + case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } + }  - drainTheTank = false; - } - else - { - /// Close the drain valve anyway - State.Create(string.Format("{0}({1}) : Close the drain valve", test.Method, test.Name)) - .AddOperation(checkUiOp) + drainTheTank = false; + } + else + { + /// Close the drain valve anyway + State.Create(string.Format("{0}({1}) : Close the drain valve", test.Method, test.Name)) + .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperation(cBrd.SetValvesOp(null, scale.DrainValve)) .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.ValvesBusy)); - } + 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.ValvesBusy)); + }   - //---------------------------------------------------- - Bridge.OnActivity(this, Strings.Measuring_the_weight); - //---------------------------------------------------- + //---------------------------------------------------- + Bridge.OnActivity(this, Strings.Measuring_the_weight); + //----------------------------------------------------  LogProcessDataTestInfo(processDataLogger, test.Procedure.Name, test.Name);  - if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Start mass"); - else LogProcessDataHeaderHeatMeters(processDataLogger, "Start mass"); -  - State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name)) - .AddOperation(checkUiOp) + if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Start mass"); + else LogProcessDataHeaderHeatMeters(processDataLogger, "Start mass"); + + State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name)) + .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperations(cameraMeasurementOps) .AddOperation(scale.ReadStableMassOp(ref StartMass, test.TimeFlow2Mass, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(processDataLoggingOp) .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } + 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.ScaleTimeout)) { Bridge.OnError(this, Strings.Mass_measurement_timeout); @@ -513,9 +526,9 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection log.WarnFormat("Start mass = {0}kg", StartMass);   - if (heatMetersPath == null) + if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Measurement"); - else + else LogProcessDataHeaderHeatMeters(processDataLogger, "Measurement");  //------------------------------------------------ @@ -531,18 +544,19 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection  /// Measurement loop State.Create(string.Format("{0}({1}) : FlyingStartStopTestWithDivOp is running", test.Method, test.Name)) - .AddOperation(checkUiOp) + .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperations(readDatastreamOps) .AddOperations(cameraMeasurementOps) .AddOperation(cBrd.FlyingStartStopTestOp(test, test.QfromM3ph(), test.QtoM3ph(), totalPulses, true, isDelayedStart, false, 0, true, DiverterStart, DiverterEnd)) .AddOperation(processDataLoggingOp) .EnterState(); - do { + 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; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }  /// Show remaining time if ((remainingTime = Math.Max(estimtdEndTime - StateMachine.Time, 0)) > 60) @@ -602,32 +616,34 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection .AddOperations(readTempPressOps) .AddOperation(cBrd.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose)) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(e)) { retVal = Event.UiCmdStop; goto stopTest; } } while (!e.Contains(Event.ValvesSet)); }  - //------------------------------------------------ - Bridge.OnActivity(this, Strings.Measuring_the_weight); - //------------------------------------------------ + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Measuring_the_weight); + //------------------------------------------------  - if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "End mass"); - else LogProcessDataHeaderHeatMeters(processDataLogger, "End mass"); + if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "End mass"); + else LogProcessDataHeaderHeatMeters(processDataLogger, "End mass");  State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name)) - .AddOperation(checkUiOp) + .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperation(scale.ReadStableMassOp(ref EndMass, test.TimeStop2Mass, test.MassMethod, test.MassRepeats, test.MassSpread)) .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } + 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.ScaleTimeout)) { Bridge.OnError(this, Strings.Mass_measurement_timeout); @@ -639,7 +655,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection /// tMass2 = StateMachine.Time; log.WarnFormat("End mass = {0}kg", EndMass); - TestEndTime = DateTime.Now; + TestEndTime = DateTime.Now;  if (test.DoDrainingAfter) { @@ -648,47 +664,48 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection .AddOperation(cBrd.SetValvesOp(scale.DrainValve, null)) .AddOperations(readTempPressOps) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } } while (e.Contains(Event.ValvesBusy)); }  - //------------------------------------------------ - Bridge.OnActivity(this, Strings.Test_completed); - //------------------------------------------------ + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Test_completed); + //------------------------------------------------  - /// Make sure the CycleBeginForm is closed so that water meter data (s/n) can be copied into results - if (heatMetersPromptOp == null) - { - if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest; - } + /// Make sure the CycleBeginForm is closed so that water meter data (s/n) can be copied into results + if (heatMetersPromptOp == null) + { + if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest; + }  - /// - /// Populate TestResult data entity with data - ///  - Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(testName, test.Part); + /// + /// Populate TestResult data entity with data + ///  + Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(testName, test.Part);  bool stopCycle = false; if (tstRslt != null) { Results.Utils.GetCounterStates(tstRslt, Program.LocalSettings.Counters);  - /// Raw data + /// Raw data UpdateTempPressDensAmb(tstRslt); - tstRslt.MethodClass = TbfComponents.FindComponent(test.Method).ClassName; - tstRslt.StartTime = TestStartTime; - tstRslt.EndTime = TestEndTime; - tstRslt.FlowSetTime = flowSetTime; - tstRslt.TestTime = cBrd.TestTime; /// [s] measurement time - tstRslt.PulsesMaster = Convert.ToDouble(cBrd.RefPulses); /// Pulses of the master flow meter (test total) - tstRslt.MassStartRaw = StartMass.Val; - tstRslt.MassEndRaw = EndMass.Val; + tstRslt.MethodClass = TbfComponents.FindComponent(test.Method).ClassName; + tstRslt.StartTime = TestStartTime; + tstRslt.EndTime = TestEndTime; + tstRslt.FlowSetTime = flowSetTime; + tstRslt.TestTime = cBrd.TestTime; /// [s] measurement time + tstRslt.PulsesMaster = Convert.ToDouble(cBrd.RefPulses); /// Pulses of the master flow meter (test total) + tstRslt.MassStartRaw = StartMass.Val; + tstRslt.MassEndRaw = EndMass.Val; tstRslt.TimeBtwnMassMsrmnts = tMass2 - tMass1; tstRslt.ConstMasterRaw = outPath.FlowMeter.LtrPerPulse; - tstRslt.VolumeMaster = tstRslt.ConstMasterRaw * tstRslt.PulsesMaster; /// [l] volume from the master flow meter - double flowMID = 3.6 * tstRslt.VolumeMaster / tstRslt.TestTime; /// [m3/h] flow before correction from the master flow meter + tstRslt.VolumeMaster = tstRslt.ConstMasterRaw * tstRslt.PulsesMaster; /// [l] volume from the master flow meter + double flowMID = 3.6 * tstRslt.VolumeMaster / tstRslt.TestTime; /// [m3/h] flow before correction from the master flow meter  /// Corrected data tstRslt.MassStart = MeasurementCorrection.CorrectedValue(tstRslt.MassStartRaw, scale.Corrections); @@ -698,23 +715,37 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection tstRslt.ConstMasterCorr = outPath.FlowMeter.LtrPerPulseCorrected(flowMID, tstRslt.TempDownMean);  /// Main result calculation - tstRslt.VolumeCTV = 1000 * tstRslt.Batch.Buoyancy * mass / tstRslt.DensityLine; + tstRslt.VolumeCTV = 1000 * tstRslt.Batch.Buoyancy * mass / tstRslt.DensityLine; if ((outPath.Diverter != null) && (tstRslt.TestTime > float.Epsilon)) { tstRslt.TestTimeCorrection = outPath.Diverter.TestTimeCorrection(flowMID); tstRslt.VolumeCTV *= tstRslt.TestTime + tstRslt.TestTimeCorrection; tstRslt.VolumeCTV /= tstRslt.TestTime; } - tstRslt.Flow = 3.6 * tstRslt.VolumeCTV / tstRslt.TestTime; /// Flow from VolumeCTV and time + tstRslt.Flow = 3.6 * tstRslt.VolumeCTV / tstRslt.TestTime; /// Flow from VolumeCTV and time tstRslt.ErrorMaster = Formulas.ErrorFromVolumes(tstRslt.VolumeMaster, tstRslt.VolumeCTV); tstRslt.ConstMaster = (tstRslt.PulsesMaster != 0) ? (tstRslt.VolumeCTV / tstRslt.PulsesMaster) : tstRslt.ConstMasterCorr; - /// Master pulses per liter from the measured mass + /// Master pulses per liter from the measured mass + + /// Main result calculation for mass + tstRslt.MassCTV = tstRslt.Batch.Buoyancy * mass; + if ((outPath.Diverter != null) && (tstRslt.TestTime > float.Epsilon)) + { + tstRslt.TestTimeCorrection = outPath.Diverter.TestTimeCorrection(flowMID); + tstRslt.MassCTV *= tstRslt.TestTime + tstRslt.TestTimeCorrection; + tstRslt.MassCTV /= tstRslt.TestTime; + } + tstRslt.MassFlow = 3.6 * tstRslt.MassCTV / tstRslt.TestTime; /// Flow from MassCTV and time + tstRslt.MassErrorMaster = Formulas.ErrorFromVolumes(tstRslt.VolumeMaster, tstRslt.MassCTV); + tstRslt.MassConstMaster = (tstRslt.PulsesMaster != 0) ? (tstRslt.MassCTV / tstRslt.PulsesMaster) : tstRslt.ConstMasterCorr; + + /// Flow statistics correction - tstRslt.FlowMean = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Average / tstRslt.ConstMasterRaw); + tstRslt.FlowMean = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Average / tstRslt.ConstMasterRaw); tstRslt.FlowStart = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.First / tstRslt.ConstMasterRaw); - tstRslt.FlowEnd = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Last / tstRslt.ConstMasterRaw); - tstRslt.FlowMin = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Min / tstRslt.ConstMasterRaw); - tstRslt.FlowMax = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Max / tstRslt.ConstMasterRaw); + tstRslt.FlowEnd = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Last / tstRslt.ConstMasterRaw); + tstRslt.FlowMin = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Min / tstRslt.ConstMasterRaw); + tstRslt.FlowMax = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Max / tstRslt.ConstMasterRaw);  tstRslt.DiverterStart = outPath.Diverter.SwitchTimeStart.Val; tstRslt.DivStart10 = 0; @@ -734,114 +765,114 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection : 0; tstRslt.InfoFlags = infoFlags;  - if (compoundTestParams != null) - { - /// - /// Compound meters - /// - for (int i = 0; i < BatchRslts.WMPositionsCount; i++) - { - if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue; + if (compoundTestParams != null) + { + /// + /// Compound meters + /// + for (int i = 0; i < BatchRslts.WMPositionsCount; i++) + { + if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue;  - var mainMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.CompoundMain); - var auxMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.CompoundAux); + var mainMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.CompoundMain); + var auxMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.CompoundAux);  - for (int isAux = 0; isAux <= 1; isAux++) /// 0=main, 1=aux + for (int isAux = 0; isAux <= 1; isAux++) /// 0=main, 1=aux { - IRegReader regReader = sensPath.RegisterReaders[2 * i + isAux]; - var oneMTR = (isAux == 0) ? mainMeterRslt : auxMeterRslt; + IRegReader regReader = sensPath.RegisterReaders[2 * i + isAux]; + var oneMTR = (isAux == 0) ? mainMeterRslt : auxMeterRslt;  - if (oneMTR != null && regReader != null) - { + if (oneMTR != null && regReader != null) + { oneMTR.RegReaderType = (int)regReader.RegisterReaderType; if (regReader is PoseidonReader poseidon) //is Poseidon reader family { - oneMTR.PulsesPerLiter = 0; - - /// Optionally supress pulses from the large water meter - oneMTR.PulsesMeter = 0; - oneMTR.PulsesMaster = 0; - oneMTR.TestTime = cBrd.TestTime; - oneMTR.VolumeStart = 0; - oneMTR.VolumeEnd = 0; - oneMTR.VolumeRef = tstRslt.VolumeCTV; - - if (oneMTR.PulsesMaster != 0) - { - oneMTR.PulsesMeter *= (tstRslt.PulsesMaster / oneMTR.PulsesMaster); - oneMTR.PulsesMaster = tstRslt.PulsesMaster; - } - - oneMTR.VolumeMeter = poseidon.WMVolume; -  - oneMTR.Error = - Formulas.ErrorFromVolumes(oneMTR.VolumeMeter, - tstRslt.VolumeCTV); /// Main/Aux meter error is not usedfor evaluation + oneMTR.PulsesPerLiter = 0; + + /// Optionally supress pulses from the large water meter + oneMTR.PulsesMeter = 0; + oneMTR.PulsesMaster = 0; + oneMTR.TestTime = cBrd.TestTime; + oneMTR.VolumeStart = 0; + oneMTR.VolumeEnd = 0; + oneMTR.VolumeRef = tstRslt.VolumeCTV; + + if (oneMTR.PulsesMaster != 0) + { + oneMTR.PulsesMeter *= (tstRslt.PulsesMaster / oneMTR.PulsesMaster); + oneMTR.PulsesMaster = tstRslt.PulsesMaster; + } + + oneMTR.VolumeMeter = poseidon.WMVolume; + + oneMTR.Error = + Formulas.ErrorFromVolumes(oneMTR.VolumeMeter, + tstRslt.VolumeCTV); /// Main/Aux meter error is not usedfor evaluation } else { - oneMTR.PulsesPerLiter = regReader.PulsesPerLtr; - - /// Optionally supress pulses from the large water meter - oneMTR.PulsesMeter = (isAux == 0 && compoundTestParams.SupressTrills) - ? 0 - : Convert.ToDouble(regReader.WMPulses); - oneMTR.PulsesMaster = Convert.ToDouble(regReader.WMRefPulses); - oneMTR.TestTime = cBrd.TestTime; - oneMTR.VolumeStart = 0; - oneMTR.VolumeEnd = 0; - oneMTR.VolumeRef = tstRslt.VolumeCTV; - - if (oneMTR.PulsesMaster != 0) - { - oneMTR.PulsesMeter *= (tstRslt.PulsesMaster / oneMTR.PulsesMaster); - oneMTR.PulsesMaster = tstRslt.PulsesMaster; - } - - oneMTR.VolumeMeter = oneMTR.PulsesMeter * regReader.LtrsPerPulse; /// liter - - oneMTR.Error = - Formulas.ErrorFromVolumes(oneMTR.VolumeMeter, - tstRslt.VolumeCTV); /// Main/Aux meter error is not usedfor evaluation + oneMTR.PulsesPerLiter = regReader.PulsesPerLtr; + + /// Optionally supress pulses from the large water meter + oneMTR.PulsesMeter = (isAux == 0 && compoundTestParams.SupressTrills) + ? 0 + : Convert.ToDouble(regReader.WMPulses); + oneMTR.PulsesMaster = Convert.ToDouble(regReader.WMRefPulses); + oneMTR.TestTime = cBrd.TestTime; + oneMTR.VolumeStart = 0; + oneMTR.VolumeEnd = 0; + oneMTR.VolumeRef = tstRslt.VolumeCTV; + + if (oneMTR.PulsesMaster != 0) + { + oneMTR.PulsesMeter *= (tstRslt.PulsesMaster / oneMTR.PulsesMaster); + oneMTR.PulsesMaster = tstRslt.PulsesMaster; + } + + oneMTR.VolumeMeter = oneMTR.PulsesMeter * regReader.LtrsPerPulse; /// liter + + oneMTR.Error = + Formulas.ErrorFromVolumes(oneMTR.VolumeMeter, + tstRslt.VolumeCTV); /// Main/Aux meter error is not usedfor evaluation } - } - } + } + }  - var compoundMTR = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.Compound); + var compoundMTR = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.Compound);  - if (compoundMTR != null && mainMeterRslt != null && auxMeterRslt != null) - { - compoundMTR.VolumeRef = tstRslt.VolumeCTV; - compoundMTR.VolumeMeter = mainMeterRslt.VolumeMeter + auxMeterRslt.VolumeMeter; - compoundMTR.PulsesMaster = tstRslt.PulsesMaster; - compoundMTR.TestTime = tstRslt.TestTime; - compoundMTR.Error = Formulas.ErrorFromVolumes(compoundMTR.VolumeMeter, compoundMTR.VolumeRef); - compoundMTR.Passed = (compoundMTR.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) - && (compoundMTR.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) + if (compoundMTR != null && mainMeterRslt != null && auxMeterRslt != null) + { + compoundMTR.VolumeRef = tstRslt.VolumeCTV; + compoundMTR.VolumeMeter = mainMeterRslt.VolumeMeter + auxMeterRslt.VolumeMeter; + compoundMTR.PulsesMaster = tstRslt.PulsesMaster; + compoundMTR.TestTime = tstRslt.TestTime; + compoundMTR.Error = Formulas.ErrorFromVolumes(compoundMTR.VolumeMeter, compoundMTR.VolumeRef); + compoundMTR.Passed = (compoundMTR.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) + && (compoundMTR.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) && (tstRslt.ErrorFlags == 0); - mainMeterRslt.Passed = auxMeterRslt.Passed = compoundMTR.Passed; - mainMeterRslt.TestDone = auxMeterRslt.TestDone = compoundMTR.TestDone = true; + mainMeterRslt.Passed = auxMeterRslt.Passed = compoundMTR.Passed; + mainMeterRslt.TestDone = auxMeterRslt.TestDone = compoundMTR.TestDone = true; tstRslt.TestDone = true; - } - } - } - else if (heatMetersTestParams != null) - { + } + } + } + else if (heatMetersTestParams != null) + { /// /// Heat meters /// tstRslt.RefEnergy = Energy.Sum * tstRslt.VolumeCTV / VolumeForEnergy.Sum; /// [J] = [J] * [l] / [l]  - tstRslt.Custom1 = (float)TempRefHiStat.Average; - tstRslt.Custom2 = (float)TempRefHiStat.First; - tstRslt.Custom3 = (float)TempRefHiStat.Last; - tstRslt.Custom4 = (float)TempRefHiStat.Min; - tstRslt.Custom5 = (float)TempRefHiStat.Max; - tstRslt.Custom6 = (float)TempRefLoStat.Average; - tstRslt.Custom7 = (float)TempRefLoStat.First; - tstRslt.Custom8 = (float)TempRefLoStat.Last; - tstRslt.Custom9 = (float)TempRefLoStat.Min; - tstRslt.Custom10 = (float)TempRefLoStat.Max;  + tstRslt.Custom1 = (float)TempRefHiStat.Average; + tstRslt.Custom2 = (float)TempRefHiStat.First; + tstRslt.Custom3 = (float)TempRefHiStat.Last; + tstRslt.Custom4 = (float)TempRefHiStat.Min; + tstRslt.Custom5 = (float)TempRefHiStat.Max; + tstRslt.Custom6 = (float)TempRefLoStat.Average; + tstRslt.Custom7 = (float)TempRefLoStat.First; + tstRslt.Custom8 = (float)TempRefLoStat.Last; + tstRslt.Custom9 = (float)TempRefLoStat.Min; + tstRslt.Custom10 = (float)TempRefLoStat.Max;  for (int i = 0; i < BatchRslts.WMPositionsCount; i++) { @@ -868,10 +899,10 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection volumeRslt.TestTime = cBrd.TestTimeWM(i + 1); /// [s]  volumeRslt.Error = Formulas.ErrorFromVolumes(volumeRslt.VolumeMeter, volumeRslt.VolumeRef); - volumeRslt.Passed = !heatMetersTestParams.EvaluateVolume || - ((volumeRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) && - (volumeRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) && - (tstRslt.ErrorFlags == 0)); + volumeRslt.Passed = !heatMetersTestParams.EvaluateVolume || + ((volumeRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) && + (volumeRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) && + (tstRslt.ErrorFlags == 0)); volumeRslt.TestDone = true; tstRslt.TestDone = true; } @@ -883,103 +914,131 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection energyRslt.PulsesMaster = Convert.ToDouble(energyRegReader.WMRefPulses); energyRslt.VolumeStart = 0; energyRslt.VolumeEnd = 0; - energyRslt.VolumeRef = tstRslt.RefEnergy * (energyRslt.PulsesMaster / tstRslt.PulsesMaster); /// [J] + energyRslt.VolumeRef = tstRslt.RefEnergy * (energyRslt.PulsesMaster / tstRslt.PulsesMaster); /// [J] energyRslt.VolumeMeter = energyRslt.PulsesMeter * Common.Units.ConvertFrom(Common.Unit.kWh, energyRegReader.LtrsPerPulse); /// [J] energyRslt.TestTime = cBrd.TestTimeWM(i + 1); /// [s]  energyRslt.Error = Formulas.ErrorFromVolumes(energyRslt.VolumeMeter, energyRslt.VolumeRef); - energyRslt.Passed = (energyRslt.Error >= heatMetersTestParams.ErrorLimitLo) - && (energyRslt.Error <= heatMetersTestParams.ErrorLimitHi) + energyRslt.Passed = (energyRslt.Error >= heatMetersTestParams.ErrorLimitLo) + && (energyRslt.Error <= heatMetersTestParams.ErrorLimitHi) && (tstRslt.ErrorFlags == 0); energyRslt.TestDone = true; tstRslt.TestDone = true; } } } - else - { - /// - /// Single meters - /// - for (int i = 0; i < BatchRslts.WMPositionsCount; i++) - { - if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue; - - /// MetersKind.Single meters - Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Common.CompoundMeterId.Single); - GenericDevices.IRegReader regReader = sensPath.RegisterReaders[i]; + else + { + /// + /// Single meters + /// + for (int i = 0; i < BatchRslts.WMPositionsCount; i++) + { + if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue; + + /// MetersKind.Single meters + Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Common.CompoundMeterId.Single); + GenericDevices.IRegReader regReader = sensPath.RegisterReaders[i]; GenericDevices.IRegReaderDatastream dstrReader = regReader as GenericDevices.IRegReaderDatastream; TestMethods.iPerlCommunication.iPerlHead.IperlHead iPerl = regReader as TestMethods.iPerlCommunication.iPerlHead.IperlHead; GenericDevices.IRegReaderLiveCamera cameraRoi = regReader as GenericDevices.IRegReaderLiveCamera;  - if (meterRslt != null && regReader != null) - { + if (meterRslt != null && regReader != null) + { meterRslt.RegReaderType = (int)regReader.RegisterReaderType; - meterRslt.PulsesPerLiter = regReader.PulsesPerLtr; - meterRslt.PulsesMeter = Convert.ToDouble(regReader.WMPulses); + ComponentProcedure procParamsEntity = test.Procedure.GetProcedureParamsEntity(regReader.Name); + + try + { + if (regReader.RegisterReaderType == RegisterReaderType.Pulses) + { + XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(RRProcParams) })[0]; + RRProcParams tmp = Serializer.Deserialize(new StringReader(procParamsEntity.Parameters.ToString())) as RRProcParams; + regReader.PulsesPerLtr = tmp.PulsesPerLtr; + regReader.QuantityUnits = tmp.Units; + } + else + { + //MessageBox.Show("Cannot create or initialize a printer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + } + } + catch (Exception ex) + { + /*log.DebugFormat( + "Error during Procedure parameters deserialization. CmpntName='{0}', Procedure='{1}', Parameters='{2}', Exception: {3}", + dbEntity?.CmpntName, + dbEntity?.Procedure, + dbEntity?.Parameters, + ex + );*/ + } + + meterRslt.PulsesPerLiter = regReader.PulsesPerLtr;//...MF 11.12.2025 toto chybalo, v .csv bol stlpec naplneny nulami + meterRslt.QuantityUnits = regReader.QuantityUnits; + meterRslt.PulsesMeter = Convert.ToDouble(regReader.WMPulses);  if (dstrReader != null) - { - - if (dstrReader is SmartReader poseidon) //is Poseidon reader family - { - log.Info("Poseidon reader detected - Results"); - meterRslt.TimestampStart = poseidon.TimestampSecStart; - meterRslt.TimestampEnd = !poseidon.NoSamples - ? poseidon.TimestampSecEnd - : (poseidon.TimestampSecStart + tstRslt.TestTime); - meterRslt.TestTime = meterRslt.TimestampEnd - meterRslt.TimestampStart; - meterRslt.VolumeStart = poseidon.VolumeLtrStart; /// liter + { + + if (dstrReader is SmartReader poseidon) //is Poseidon reader family + { + log.Info("Poseidon reader detected - Results"); + meterRslt.TimestampStart = poseidon.TimestampSecStart; + meterRslt.TimestampEnd = !poseidon.NoSamples + ? poseidon.TimestampSecEnd + : (poseidon.TimestampSecStart + tstRslt.TestTime); + meterRslt.TestTime = meterRslt.TimestampEnd - meterRslt.TimestampStart; + meterRslt.VolumeStart = poseidon.VolumeLtrStart; /// liter meterRslt.VolumeEnd = poseidon.VolumeLtrStart + poseidon.WMVolume; //dstrReader.VolumeLtrEnd; /// liter - meterRslt.VolumeMeter = poseidon.WMVolume; - - if (!(meterRslt.TestTime == 0 || tstRslt.TestTime == 0)) - { - meterRslt.VolumeRef = tstRslt.VolumeCTV * meterRslt.TestTime / tstRslt.TestTime; - meterRslt.PulsesMaster = - tstRslt.PulsesMaster * meterRslt.TestTime / tstRslt.TestTime; - } - else - { - meterRslt.VolumeRef = tstRslt.VolumeCTV; - meterRslt.PulsesMaster = tstRslt.PulsesMaster; - } - - log.Info($"meterRslt.TimestampStart = {meterRslt.TimestampStart} \n" + - $"meterRslt.TimestampEnd = {meterRslt.TimestampEnd }\n" + - $"meterRslt.TestTime = {meterRslt.TestTime}\n" + - $"meterRslt.VolumeStart = {meterRslt.VolumeStart}\n" + - $"meterRslt.VolumeEnd = {meterRslt.VolumeEnd}\n" + - $"meterRslt.VolumeMeter = {meterRslt.VolumeMeter}\n" + - $"meterRslt.VolumeRef = {meterRslt.VolumeRef}\n" + - $"meterRslt.PulsesMaster = {meterRslt.PulsesMaster}\n"); -  -  - } - else - { - meterRslt.TimestampStart = dstrReader.TimestampSecStart; - meterRslt.TimestampEnd = !dstrReader.NoSamples - ? dstrReader.TimestampSecEnd - : (dstrReader.TimestampSecStart + tstRslt.TestTime); - meterRslt.TestTime = meterRslt.TimestampEnd - meterRslt.TimestampStart; - meterRslt.VolumeStart = dstrReader.VolumeLtrStart; /// liter + meterRslt.VolumeMeter = poseidon.WMVolume; + + if (!(meterRslt.TestTime == 0 || tstRslt.TestTime == 0)) + { + meterRslt.VolumeRef = tstRslt.VolumeCTV * meterRslt.TestTime / tstRslt.TestTime; + meterRslt.PulsesMaster = + tstRslt.PulsesMaster * meterRslt.TestTime / tstRslt.TestTime; + } + else + { + meterRslt.VolumeRef = tstRslt.VolumeCTV; + meterRslt.PulsesMaster = tstRslt.PulsesMaster; + } + + log.Info($"meterRslt.TimestampStart = {meterRslt.TimestampStart} \n" + + $"meterRslt.TimestampEnd = {meterRslt.TimestampEnd}\n" + + $"meterRslt.TestTime = {meterRslt.TestTime}\n" + + $"meterRslt.VolumeStart = {meterRslt.VolumeStart}\n" + + $"meterRslt.VolumeEnd = {meterRslt.VolumeEnd}\n" + + $"meterRslt.VolumeMeter = {meterRslt.VolumeMeter}\n" + + $"meterRslt.VolumeRef = {meterRslt.VolumeRef}\n" + + $"meterRslt.PulsesMaster = {meterRslt.PulsesMaster}\n"); + + + } + else + { + meterRslt.TimestampStart = dstrReader.TimestampSecStart; + meterRslt.TimestampEnd = !dstrReader.NoSamples + ? dstrReader.TimestampSecEnd + : (dstrReader.TimestampSecStart + tstRslt.TestTime); + meterRslt.TestTime = meterRslt.TimestampEnd - meterRslt.TimestampStart; + meterRslt.VolumeStart = dstrReader.VolumeLtrStart; /// liter meterRslt.VolumeEnd = dstrReader.VolumeLtrEnd; /// liter meterRslt.VolumeMeter = - Math.Abs(dstrReader.VolumeLtrEnd - dstrReader.VolumeLtrStart); - meterRslt.VolumeRef = tstRslt.VolumeCTV * meterRslt.TestTime / tstRslt.TestTime; - meterRslt.PulsesMaster = - tstRslt.PulsesMaster * meterRslt.TestTime / tstRslt.TestTime; - } + Math.Abs(dstrReader.VolumeLtrEnd - dstrReader.VolumeLtrStart); + meterRslt.VolumeRef = tstRslt.VolumeCTV * meterRslt.TestTime / tstRslt.TestTime; + meterRslt.PulsesMaster = + tstRslt.PulsesMaster * meterRslt.TestTime / tstRslt.TestTime; + }  - if (iPerl != null) + if (iPerl != null) { if (iPerl.ResultCode != 0 && (meterRslt.WaterMeter.ResultCode & (int)Results.Entities.ResultCode.OptoErrorCodeMask) == 0) { meterRslt.WaterMeter.ResultCode |= iPerl.ResultCode; } #if IPERL - meterRslt.WaterMeter.CalibFactor = iPerl.CalibFactor; + meterRslt.WaterMeter.CalibFactor = iPerl.CalibFactor; meterRslt.ExtraDataPath = iPerl.ExtraDataPath; if (TestMethods.iPerlCommunication.iPerlHead.IperlHead.FeatureVectorSize >= 1) meterRslt.X1 = iPerl.X[0]; if (TestMethods.iPerlCommunication.iPerlHead.IperlHead.FeatureVectorSize >= 2) meterRslt.X2 = iPerl.X[1]; @@ -1005,18 +1064,18 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection meterRslt.VolumeMeter, meterRslt.VolumeRef); } - else if (cameraRoi != null) - { - meterRslt.TimestampStart = cameraRoi.TimestampStart; /// [s] - meterRslt.TimestampEnd = cameraRoi.TimestampEnd; /// [s] - meterRslt.VolumeStart = cameraRoi.VolumeStart; /// [l] - meterRslt.VolumeEnd = cameraRoi.VolumeEnd; /// [l] - meterRslt.VolumeMeter = cameraRoi.VolumeEnd - cameraRoi.VolumeStart; /// [l] + else if (cameraRoi != null) + { + meterRslt.TimestampStart = cameraRoi.TimestampStart; /// [s] + meterRslt.TimestampEnd = cameraRoi.TimestampEnd; /// [s] + meterRslt.VolumeStart = cameraRoi.VolumeStart; /// [l] + meterRslt.VolumeEnd = cameraRoi.VolumeEnd; /// [l] + meterRslt.VolumeMeter = cameraRoi.VolumeEnd - cameraRoi.VolumeStart; /// [l]  if (meterRslt.VolumeMeter != 0) { /// Normal measurement with camera - meterRslt.TestTime = cameraRoi.TimestampEnd - cameraRoi.TimestampStart; /// [s] + meterRslt.TestTime = cameraRoi.TimestampEnd - cameraRoi.TimestampStart; /// [s] meterRslt.VolumeRef = tstRslt.VolumeCTV * meterRslt.TestTime / tstRslt.TestTime; meterRslt.PulsesMaster = tstRslt.PulsesMaster * meterRslt.TestTime / tstRslt.TestTime; } @@ -1038,11 +1097,11 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection meterRslt.VolumeMeter, meterRslt.VolumeRef); } - else - { + else + { meterRslt.PulsesMaster = Convert.ToDouble(regReader.WMRefPulses); meterRslt.VolumeStart = 0; - meterRslt.VolumeEnd = 0; + meterRslt.VolumeEnd = 0; meterRslt.VolumeMeter = meterRslt.PulsesMeter * regReader.LtrsPerPulse; /// [l]  if (regReader.WMPulses >= 1) @@ -1050,43 +1109,67 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection /// Normal measurement meterRslt.TestTime = cBrd.TestTimeWM(regReader.Position); meterRslt.VolumeRef = meterRslt.PulsesMaster * tstRslt.ConstMaster; /// [l] + meterRslt.MassRef = meterRslt.PulsesMaster * tstRslt.MassConstMaster; /// [kg] } else { /// None or one pulse from the water meter meterRslt.TestTime = tstRslt.TestTime; meterRslt.VolumeRef = tstRslt.VolumeCTV; /// [l] + meterRslt.MassRef = tstRslt.MassCTV; }  - log.DebugFormat("Pulses: Pref4meter={0} Vmeter={1} Vref4meter={2} Ttime4meter={3} Ttime={4}", + log.DebugFormat("Pulses: Pref4meter={0} Vmeter={1} Vref4meter={2} Mmeter={3} Mref4meter={4} Ttime4meter={5} Ttime={6}", meterRslt.PulsesMaster, meterRslt.VolumeMeter, meterRslt.VolumeRef, + meterRslt.MassMeter, + meterRslt.MassRef, meterRslt.TestTime, tstRslt.TestTime); }  - meterRslt.Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef); - meterRslt.Passed = (meterRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) - && (meterRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) - && (tstRslt.ErrorFlags == 0); + double Error = 0; + if (meterRslt.GetQuantityFromUnits() == "Mass") + Error = Formulas.ErrorFromVolumes(meterRslt.MassMeter, meterRslt.MassRef); + else + Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef); + + meterRslt.Error = Error; + + var ErrLimLo_Volume = test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime); + var ErrLimHi_Volume = test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime); + var ErrLimLo_Mass = test.GetErrLimLo(tstRslt.MassCTV, tstRslt.TestTime); + var ErrLimHi_Mass = test.GetErrLimHi(tstRslt.MassCTV, tstRslt.TestTime); + + bool Passed; + if (meterRslt.GetQuantityFromUnits() == "Mass") + Passed = (meterRslt.Error >= ErrLimLo_Volume + test.Uncertainty) && + (meterRslt.Error <= ErrLimHi_Volume - test.Uncertainty) && + (tstRslt.ErrorFlags == 0); + else + Passed = (meterRslt.Error >= ErrLimLo_Mass + test.Uncertainty) && + (meterRslt.Error <= ErrLimHi_Mass - test.Uncertainty) && + (tstRslt.ErrorFlags == 0); + + meterRslt.Passed = Passed; meterRslt.TestDone = true; tstRslt.TestDone = true; #if ORACLE_DB meterRslt.ErrorBC = meterRslt.Error; #endif } - } - } - - tstRslt.Components = Results.Entities.Components.UpdateList(BatchRslts.ComponentsList, - new Results.Entities.Components((BenchInfo != null) ? BenchInfo.TestBenchId : 1, - (BenchInfo != null) ? BenchInfo.TestBenchName : "testbench", - inPath.Pump != null ? inPath.Pump.Name : string.Empty, - outPath.FlowMeter != null ? outPath.FlowMeter.Name : string.Empty, - cBrd.Devices.Scale.Name, - outPath.RegValve != null ? outPath.RegValve.Name : string.Empty, - outPath.Diverter != null ? outPath.Diverter.Name : string.Empty)); + } + } + + tstRslt.Components = Results.Entities.Components.UpdateList(BatchRslts.ComponentsList, + new Results.Entities.Components((BenchInfo != null) ? BenchInfo.TestBenchId : 1, + (BenchInfo != null) ? BenchInfo.TestBenchName : "testbench", + inPath.Pump != null ? inPath.Pump.Name : string.Empty, + outPath.FlowMeter != null ? outPath.FlowMeter.Name : string.Empty, + cBrd.Devices.Scale.Name, + outPath.RegValve != null ? outPath.RegValve.Name : string.Empty, + outPath.Diverter != null ? outPath.Diverter.Name : string.Empty));  /// Update water meter error flags if (ErrorFlagsComp != null) @@ -1105,24 +1188,24 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection } }  - /// Update results - Bridge.OnTestCompleted(this, new TestCompletedEventArgs(testName, tstRslt)); - } + /// Update results + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(testName, tstRslt)); + }  - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.TransitionAfter)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.TransitionAfter));  - /// Append the results to the CSV-file - allResults.Info(TestResult2CsvLine(testName, test.Part)); + /// Append the results to the CSV-file + allResults.Info(TestResult2CsvLine(testName, test.Part));  if (stopCycle) retVal = Event.ErrorFlagsStop;  - stopTest: + stopTest:  - StopRecordingStatistics(); /// Make sure graph files are closed + StopRecordingStatistics(); /// Make sure graph files are closed  - /// - /// Quit this sequence - /// + /// + /// Quit this sequence + /// if (isLastRepetition || retVal == Event.UiCmdStop || retVal == Event.OpArgumentError || retVal == Event.RecoverableError @@ -1133,18 +1216,18 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection cBrd.StopAll(false); }  - return new List { retVal }; - } + return new List { retVal }; + }   - IList Simulate1(Config.Entities.Test test, int repetitionNr, bool isLastRepetition, - Compound.CombinedTestParams compoundTestParams, - HeatMeters.TestParams heatMetersTestParams) - { - /// - /// Test method simulation - ///  - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting)); + IList Simulate1(Config.Entities.Test test, int repetitionNr, bool isLastRepetition, + Compound.CombinedTestParams compoundTestParams, + HeatMeters.TestParams heatMetersTestParams) + { + /// + /// Test method simulation + ///  + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  foreach (var rr in sensPath.RegisterReaders) { @@ -1157,12 +1240,12 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection StateMachine.WaitRunDevsRunOps(); StateMachine.WaitRunDevsRunOps();  -  - if (compoundTestParams != null) - { + + if (compoundTestParams != null) + { if (test.Name.ToLower().Contains("nok")) MakeSimulatedCompound(test, 1, test.Part, 4.7f, 0.9f); else MakeSimulatedCompound(test, repetitionNr, test.Part, 0.7f, 1.0f); - } + } else if (heatMetersTestParams != null) { MakeSimulatedHeatMeters(test, repetitionNr, test.Part, 1.5f, 1000000, heatMetersTestParams.ErrorLimitLo, heatMetersTestParams.ErrorLimitHi, heatMetersTestParams.EvaluateVolume); @@ -1170,91 +1253,91 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection else { float errorPctBase = -1.0f; - if (test.Name.ToLower().Contains("q3")) errorPctBase = -0.5f; + if (test.Name.ToLower().Contains("q3")) errorPctBase = -0.5f; else if (test.Name.ToLower().Contains("q2")) errorPctBase = 0.5f; else if (test.Name.ToLower().Contains("q1")) errorPctBase = -5.1f;  MakeSimulated(test, repetitionNr, test.Part, errorPctBase + repetitionNr * 0.1f); }  - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Completed)); - Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0))); - allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Completed)); + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0))); + allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file  - //------------------------------------------------------------------- - Bridge.OnActivity(this, string.Format("{0} Simulation", test.Name)); - //------------------------------------------------------------------- + //------------------------------------------------------------------- + Bridge.OnActivity(this, string.Format("{0} Simulation", test.Name)); + //-------------------------------------------------------------------  - State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name)) - .AddOperation(checkUiOp) - .EnterState(); - IList e = StateMachine.WaitRunDevsRunOps(); + State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name)) + .AddOperation(checkUiOp) + .EnterState(); + IList e = StateMachine.WaitRunDevsRunOps();  return new List { TestAndLogUiCmdStop(test, e) ? Event.UiCmdStop : Event.Done }; - } + }   - IList Simulate2(Config.Entities.Test test, int repetitionNr, bool isLastRepetition, - Compound.CombinedTestParams compoundTestParams, - HeatMeters.TestParams heatMetersTestParams) - { - IList e; - Event retVal = Event.Done; + IList Simulate2(Config.Entities.Test test, int repetitionNr, bool isLastRepetition, + Compound.CombinedTestParams compoundTestParams, + HeatMeters.TestParams heatMetersTestParams) + { + IList e; + Event retVal = Event.Done;  - /// - /// Test method with flow chart simulation - ///  - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting)); + /// + /// Test method with flow chart simulation + ///  + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));   - /// Simulate flow + /// Simulate flow StartNewStatistics(null, BatchRslts.Batch.BatchNr, test, repetitionNr, 0);  - IntBox remainingTime = new IntBox((int)test.TestTime); - State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name)) - .AddOperation(checkUiOp) - .AddOperation(new Operations.TimerOp((int)test.TestTime, remainingTime)) - .EnterState(); - do - { - e = StateMachine.WaitRunDevsRunOps(); - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; } - - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test)); - - if (remainingTime.Val > 60) - { - Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Test_in_progress, remainingTime.Val / 60, "min", remainingTime.Val % 60, Strings.sec)); - } - else - { - Bridge.OnActivity(this, string.Format("{0} ... {1} s", Strings.Test_in_progress, remainingTime.Val)); - } - //------------------------------------------------ - - RefFlow.Val = (1.0 + 0.2 * Math.Sin(2 * Math.PI * (float)remainingTime.Val / test.TestTime)) * (test.QfromM3ph() + test.QtoM3ph()) / 2.0; + IntBox remainingTime = new IntBox((int)test.TestTime); + State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name)) + .AddOperation(checkUiOp) + .AddOperation(new Operations.TimerOp((int)test.TestTime, remainingTime)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; } + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test)); + + if (remainingTime.Val > 60) + { + Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Test_in_progress, remainingTime.Val / 60, "min", remainingTime.Val % 60, Strings.sec)); + } + else + { + Bridge.OnActivity(this, string.Format("{0} ... {1} s", Strings.Test_in_progress, remainingTime.Val)); + } + //------------------------------------------------ + + RefFlow.Val = (1.0 + 0.2 * Math.Sin(2 * Math.PI * (float)remainingTime.Val / test.TestTime)) * (test.QfromM3ph() + test.QtoM3ph()) / 2.0; PressUp.Val = 2.7f; PressDown.Val = 2.2f;  - UpdateAllStatistics(); - } - while (!e.Contains(Event.TimerExpired)); + UpdateAllStatistics(); + } + while (!e.Contains(Event.TimerExpired));  - StopRecordingStatistics(); + StopRecordingStatistics();  - if (retVal != Event.UiCmdStop) - { - float errorPctBase = -1.0f; + if (retVal != Event.UiCmdStop) + { + float errorPctBase = -1.0f;  - if (test.Name.ToLower().Contains("q3")) errorPctBase = -0.5f; - else if (test.Name.ToLower().Contains("q2")) errorPctBase = 0.5f; - else if (test.Name.ToLower().Contains("q1")) errorPctBase = -5.1f; + if (test.Name.ToLower().Contains("q3")) errorPctBase = -0.5f; + else if (test.Name.ToLower().Contains("q2")) errorPctBase = 0.5f; + else if (test.Name.ToLower().Contains("q1")) errorPctBase = -5.1f;  - MakeSimulated(test, repetitionNr, test.Part, errorPctBase + repetitionNr * 0.1f); + MakeSimulated(test, repetitionNr, test.Part, errorPctBase + repetitionNr * 0.1f);  - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Completed)); - Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0))); - allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Completed)); + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0))); + allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file }  return new List { retVal }; /// default 'retVal' value is Event.Done diff --git a/TBF/Rig/TestMethods/StandingStartMassCollection/StandingStartMassCollectionSeq.cs b/TBF/Rig/TestMethods/StandingStartMassCollection/StandingStartMassCollectionSeq.cs --- a/TBF/Rig/TestMethods/StandingStartMassCollection/StandingStartMassCollectionSeq.cs +++ b/TBF/Rig/TestMethods/StandingStartMassCollection/StandingStartMassCollectionSeq.cs @@ -1,13 +1,14 @@ -/// +using Common; +using Config.Entities; +using log4net; +/// /// Copyright (c) 2013-2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.IO; using System.Threading; -using log4net; -using Common; -using Config.Entities; +using System.Xml.Serialization; using TBF.Boxes; using TBF.Resources; using TBF.Rig.GenericDevices; @@ -74,21 +75,21 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection return true; }  - ///  - /// Fixed start mass collection method sequence - ///  - /// Test entity - ///  - /// Event.Done . . . . . . . OK - /// Event.MakeSecondPass . . OK, 2nd pass (=evaluation) required - /// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP - /// Event.OpArgumentError . Target flow is out of range - /// Event.Error . . . . . . Unspecified error - ///  - public IList Execute(Config.Entities.Test test, int repetitionNr, bool isLastRepetition, + ///  + /// Fixed start mass collection method sequence + ///  + /// Test entity + ///  + /// Event.Done . . . . . . . OK + /// Event.MakeSecondPass . . OK, 2nd pass (=evaluation) required + /// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP + /// Event.OpArgumentError . Target flow is out of range + /// Event.Error . . . . . . Unspecified error + ///  + public IList Execute(Config.Entities.Test test, int repetitionNr, bool isLastRepetition, bool compound, - HeatMeters.TestParams heatMetersTestParams, - Common.DebugMode debugLevel) + HeatMeters.TestParams heatMetersTestParams, + Common.DebugMode debugLevel) { ControlBoard.IControlBoard cBrd = StateMachine.ControlBoardMain; IScale scale = cBrd.Devices.Scale as IScale; @@ -101,7 +102,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection }  IList e; /// Events from currently running operations - int waterMetersCount = Math.Min(BenchInfo.WaterMetersCount, sensPath.RegisterReaders.Length);  + int waterMetersCount = Math.Min(BenchInfo.WaterMetersCount, sensPath.RegisterReaders.Length); DateTimeBox timeStampStart = new DateTimeBox(); DateTimeBox timeStampEnd = new DateTimeBox(); FloatBox startSwitchTime = new FloatBox(); @@ -154,7 +155,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .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; } @@ -172,53 +174,54 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection IOperation heatMetersPromptOp = null; if (heatMetersTestParams != null && !string.IsNullOrEmpty(heatMetersTestParams.Prompt)) { - /// Make sure the CycleBeginForm is closed - if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest; + /// Make sure the CycleBeginForm is closed + if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest;  - heatMetersPromptOp = new Operations.MessageBoxOp(heatMetersTestParams.Prompt); + heatMetersPromptOp = new Operations.MessageBoxOp(heatMetersTestParams.Prompt); }   if (test.DoDraining || (scale.Mass + test.Volume >= scale.Capacity * Constants.TankFullFactor)) - { + { /// /// There is not enough room in the tank OR unconditional draining ... drain the water tank /// IList ops = new List(readTempPressOps); ops.Add(heatMetersPromptOp); - switch (DrainTheTank(scale, ops)) - { - 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) + switch (DrainTheTank(scale, ops)) + { + 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(heatMetersPromptOp) - .AddOperation(cBrd.SetValvesOp(null, scale.DrainValve)) - .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.JustStarted)); + .AddOperation(heatMetersPromptOp) + .AddOperation(cBrd.SetValvesOp(null, scale.DrainValve)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, 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)); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.ValvesSet));   //------------------------------------------------ Bridge.OnActivity(this, Strings.Starting_the_pump); //------------------------------------------------  - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting)); - int flowSetTime0 = StateMachine.Time; + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting)); + int flowSetTime0 = StateMachine.Time;  - if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower); + if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower); /// State.Create(string.Format("{0}({1}) : Starting the pump", test.Method, test.Name)) .AddOperation(checkUiOp) @@ -227,14 +230,15 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(heatMetersPromptOp) .AddOperation(inPath.Pump != null ? cBrd.SetValvesOp(inPath.Pump, null) : null) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } } - while (e.Contains(Event.ValvesBusy) /* || !e.Contains(Event.AllPositionsReached)*/); + while (e.Contains(Event.ValvesBusy) /* || !e.Contains(Event.AllPositionsReached)*/);   if (test.TimePump2StartV > 0) @@ -245,7 +249,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(new Operations.TimerOp(test.TimePump2StartV)) .AddOperation(heatMetersPromptOp) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  @@ -263,10 +268,11 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(cBrd.SetValvesOp(benchPath.StopBFValve, null)) .AddOperation(heatMetersPromptOp) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } } while (!e.Contains(Event.ValvesSet)); } @@ -280,7 +286,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(new Operations.TimerOp(test.TimeBeforeFlow)) .AddOperation(heatMetersPromptOp) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  @@ -302,8 +309,9 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperations(readTempPressOps) .AddOperation(cBrd.SetValvesOp(inPath.Pump, null)) .AddOperation(heatMetersPromptOp) - .EnterState(); - do { + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  @@ -317,7 +325,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(cBrd.OpenStartValveOp()) .AddOperation(heatMetersPromptOp) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  @@ -329,14 +338,15 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperation(cBrd.SetFlowOp(test.QfromM3ph(), test.QtoM3ph(), RefFlow, FlowSettingTimeoutSec)) - .AddOperation(heatMetersPromptOp) - .EnterState(); - do { + .AddOperation(heatMetersPromptOp) + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));  if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.RegulValveTimeOut)) { Bridge.OnError(this, Strings.Flow_adjustment_failed); @@ -362,15 +372,16 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection //---------------------------------------------------  int lastTimeSec = StateMachine.Time; - double Tw_last = 0; - double Tc_last = 0; + double Tw_last = 0; + double Tc_last = 0;  State.Create(string.Format("{0}({1}) : Checking if the temperature is stable", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .AddOperation(heatMetersPromptOp) - .EnterState(); - do { + .AddOperation(heatMetersPromptOp) + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.Next)) @@ -378,56 +389,57 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection break; /// Simulate temperature is within range }  - if (TempRefHi1.Val != 0 && TempRefHi2.Val != 0 && TempRefLo1.Val != 0 && TempRefLo2.Val != 0) - { - if (StateMachine.Time - lastTimeSec > 10 || StateMachine.Time - lastTimeSec < 0) - { - 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 (TempRefHi1.Val != 0 && TempRefHi2.Val != 0 && TempRefLo1.Val != 0 && TempRefLo2.Val != 0) + { + if (StateMachine.Time - lastTimeSec > 10 || StateMachine.Time - lastTimeSec < 0) + { + 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)) + { break; /// Temperature is withing required range }  - lastTimeSec = StateMachine.Time; - Tw_last = Tw; - Tc_last = Tc; - } - } + lastTimeSec = StateMachine.Time; + Tw_last = Tw; + Tc_last = Tc; + } + } } while (true); } - else if (!string.IsNullOrEmpty(test.TempControl) && benchPath.TempMtrUp != null && benchPath.TempMtrDown != null) - { - //--------------------------------------------------- - Bridge.OnActivity(this, Strings.Setting_temperature); - //--------------------------------------------------- - - State.Create(string.Format("{0}({1}) : Wait until the water temperature is within limits", test.Method, test.Name)) - .AddOperation(checkUiOp) + else if (!string.IsNullOrEmpty(test.TempControl) && benchPath.TempMtrUp != null && benchPath.TempMtrDown != null) + { + //--------------------------------------------------- + Bridge.OnActivity(this, Strings.Setting_temperature); + //--------------------------------------------------- + + State.Create(string.Format("{0}({1}) : Wait until the water temperature is within limits", test.Method, test.Name)) + .AddOperation(checkUiOp) .AddOperations(readTempPressOps) - .EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.Next)) { break; /// Simulate temperature is within range }  - if (TempUp.Val >= test.TempLimLo && TempUp.Val <= test.TempLimHi && - TempDown.Val >= test.TempLimLo && TempDown.Val <= test.TempLimHi) - { + if (TempUp.Val >= test.TempLimLo && TempUp.Val <= test.TempLimHi && + TempDown.Val >= test.TempLimLo && TempDown.Val <= test.TempLimHi) + { break; /// Temperature set withing required range } - } - while (true); - } + } + while (true); + }  /// /// Temperature is withing required range at this point @@ -435,7 +447,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection  //----------------------------------------------------------------- Bridge.OnActivity(this, Strings.Stopping_flow_for_the_fixed_start); - //----------------------------------------------------------------- + //----------------------------------------------------------------- State.Create(string.Format("{0}({1}) : Stop flow regulation", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(readTempPressOps) @@ -451,10 +463,11 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperation(cBrd.CloseStartValveOp()) - .EnterState(); - do { + .EnterState(); + do + { e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } } while (!e.Contains(Event.ValvesSet)); @@ -483,10 +496,10 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Start mass"); else LogProcessDataHeaderHeatMeters(processDataLogger, "Start mass");  - /// - /// Enter water meter begin states and read the start mass at the same time - /// - GenericDevices.IHasWMStatesForm dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IHasWMStatesForm; + /// + /// Enter water meter begin states and read the start mass at the same time + /// + GenericDevices.IHasWMStatesForm dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IHasWMStatesForm; IOperation readStartMassOp = scale.ReadStableMassOp(ref StartMass, test.TimeFlow2Mass, test.MassMethod, test.MassRepeats, test.MassSpread);  if (dataEntryCmpnt != null) @@ -515,7 +528,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection triggerValve = roi.GetValve(); if (triggerValve != null && !triggerSend) { - OpenValveGrabImage(cBrd,testInProgress, triggerValve, e, + OpenValveGrabImage(cBrd, testInProgress, triggerValve, e, string.Format("{0}({1}) : Grabbing images - valve open", test.Method, test.Name)); triggerSend = true; } @@ -533,27 +546,28 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection } } state2.EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps();  Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test));  - if (e.Contains(Event.Error)) { retVal = Event.Error; break; } + if (e.Contains(Event.Error)) { retVal = Event.Error; break; } if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; } } while (e.Contains(Event.CameraBusy));  (dataEntryCmpnt as GenericDevices.IDataEntryForCamera).StartImages = startImages; } -  + ///valve trigger camera close if (triggerValve != null) { - CloseValveGrabImage(cBrd,testInProgress,triggerValve, e, + CloseValveGrabImage(cBrd, testInProgress, triggerValve, e, string.Format("{0}({1}) : Grabbing images - valve close", test.Method, test.Name)); } /////// -  +  Bridge.OnActivity(this, Strings.Enter_water_meter_data); long readStartTime = StateMachine.Time; @@ -564,13 +578,14 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation((dataEntryCmpnt as GenericDevices.IHasWMStatesForm).ShowTestStartFormOp(sensPath.RegisterReaders)) .AddOperation(processDataLoggingOp) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } } while (!e.Contains(Event.ModelessFormClosed)); long readEndTime = StateMachine.Time; -  + log.Debug("Read poseidon - took:" + (readEndTime - readStartTime));  if (heatMetersTestParams != null) @@ -612,7 +627,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection { (rr as Rig.Network.Camera.RoiForFixedStartKeyence.Roi).BeginWMState = dataEntryCmpnt.WMStartState(i); - log.DebugFormat(" StandingStartMassCollectionSeq.cs - BeginWMState [{0}] -> RoiForFixedStartKeyence.Roi",dataEntryCmpnt.WMStartState(i)); + log.DebugFormat(" StandingStartMassCollectionSeq.cs - BeginWMState [{0}] -> RoiForFixedStartKeyence.Roi", dataEntryCmpnt.WMStartState(i)); } if (rr is Rig.Network.Camera.RoiForFixedStartCJMS11.Roi) (rr as Rig.Network.Camera.RoiForFixedStartCJMS11.Roi).BeginWMState = dataEntryCmpnt.WMStartState(i); @@ -638,7 +653,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection string destFName = string.IsNullOrEmpty((dataEntryCmpnt as IDataEntryForCamera).TestStartImgName(i, testName)) ? fileName : (dataEntryCmpnt as IDataEntryForCamera).TestStartImgName(i, testName); File.Copy(Path.Combine(srcDir, fileName), Path.Combine(destDir, destFName), true); - log.DebugFormat("Save images sourceFile: {0}, destFile: {1} ",Path.Combine(srcDir, fileName), Path.Combine(destDir, destFName)); + log.DebugFormat("Save images sourceFile: {0}, destFile: {1} ", Path.Combine(srcDir, fileName), Path.Combine(destDir, destFName)); } } catch (Exception exc) @@ -681,7 +696,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(scale.ReadStableMassOp(ref StartMass, test.TimeFlow2Mass, 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; } @@ -724,11 +740,12 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(controlFlowOp) .AddOperation(processDataLoggingOp) .EnterState(); - do { + 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; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }  /// Show remaining time if ((remainingTime = Math.Max(estimtdEndTime - StateMachine.Time, 0)) > 60) @@ -767,8 +784,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection  Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test)); } - while ((cBrd.DebugLevel==DebugMode.Simulate && !e.Contains(Event.FlowReached)) ||  - (cBrd.DebugLevel!=DebugMode.Simulate && cBrd.RefPulses < initialPulsesCount + totalPulses && !e.Contains(Event.TestCompleted) && !e.Contains(Event.Next))); + while ((cBrd.DebugLevel == DebugMode.Simulate && !e.Contains(Event.FlowReached)) || + (cBrd.DebugLevel != DebugMode.Simulate && cBrd.RefPulses < initialPulsesCount + totalPulses && !e.Contains(Event.TestCompleted) && !e.Contains(Event.Next)));  /// Measurement loop end log.WarnFormat("Start valve switch time on test start = {0} ms", cBrd.ValveOpenCloseTime); @@ -783,7 +800,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(cBrd.CloseStartValveOp(timeStampEnd, stopSwitchTime)) .AddOperation(processDataLoggingOp) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } } @@ -807,9 +825,10 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection .AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec)) .AddOperation(processDataLoggingOp) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.ScaleTimeout)) { @@ -844,7 +863,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection double buoyancy = Formulas.Buoyancy(); double massOfEvaporatedWater = (double)(tMass2 - tMass1) * outPath.Scale.EvaporationRate(TempDivStat.Average); double volumeCTV = 1000.0 * buoyancy * (massEnd - massStart + massOfEvaporatedWater) / densityOut; - if (debugLevel == Common.DebugMode.Simulate) volumeCTV = test.Volume; + if (debugLevel == Common.DebugMode.Simulate) volumeCTV = test.Volume;  double refEnergy = Energy.Sum * volumeCTV / VolumeForEnergy.Sum; /// [J]=[J]*[l]/[l]  @@ -853,33 +872,33 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection /// if (dataEntryCmpnt != null) { - string fileName = string.Format("{0}-{1}-end.bmp", test.Name, repetitionNr); //string.Format("{0}-end.bmp", test.Name); -  + string fileName = string.Format("{0}-{1}-end.bmp", test.Name, repetitionNr); //string.Format("{0}-end.bmp", test.Name); + IValve triggerValve = null; bool triggerSend = false; - if (dataEntryCmpnt is GenericDevices.IDataEntryForCamera) - { - string[] endImages = new string[sensPath.RegisterReaders.Length]; - - State state2 = State.Create(string.Format("{0}({1}) : Grabbing images", test.Method, test.Name)) - .AddOperation(checkUiOp); - for (int i = 0; i < sensPath.RegisterReaders.Length; i++) - { - GenericDevices.IRegReaderStillCamera roi = sensPath.RegisterReaders[i] as GenericDevices.IRegReaderStillCamera; - if (roi != null) - { + if (dataEntryCmpnt is GenericDevices.IDataEntryForCamera) + { + string[] endImages = new string[sensPath.RegisterReaders.Length]; + + State state2 = State.Create(string.Format("{0}({1}) : Grabbing images", test.Method, test.Name)) + .AddOperation(checkUiOp); + for (int i = 0; i < sensPath.RegisterReaders.Length; i++) + { + GenericDevices.IRegReaderStillCamera roi = sensPath.RegisterReaders[i] as GenericDevices.IRegReaderStillCamera; + if (roi != null) + { ///if exist valve trigger camera open triggerValve = roi.GetValve(); if (triggerValve != null && !triggerSend) { - OpenValveGrabImage(cBrd,testInProgress,triggerValve, e, + OpenValveGrabImage(cBrd, testInProgress, triggerValve, e, string.Format("{0}({1}) : Grabbing images - valve open", test.Method, test.Name)); triggerSend = true; } - string directory = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString()); - Directory.CreateDirectory(directory); - endImages[i] = Path.Combine(directory, fileName); - state2.AddOperation(roi.GrabImageOp(endImages[i])); + string directory = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString()); + Directory.CreateDirectory(directory); + endImages[i] = Path.Combine(directory, fileName); + state2.AddOperation(roi.GrabImageOp(endImages[i])); state2.AddOperation(testInProgress); } else @@ -890,47 +909,49 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection endImages[i] = Path.Combine(directory, fileName); } } - state2.EnterState(); - do { - e = StateMachine.WaitRunDevsRunOps(); + state2.EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test));  - Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test)); + if (e.Contains(Event.Error)) { retVal = Event.Error; break; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; } + } + while (e.Contains(Event.CameraBusy));  - if (e.Contains(Event.Error)) { retVal = Event.Error; break; } - if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; } - } - while (e.Contains(Event.CameraBusy)); + (dataEntryCmpnt as GenericDevices.IDataEntryForCamera).EndImages = endImages; + }  - (dataEntryCmpnt as GenericDevices.IDataEntryForCamera).EndImages = endImages; - } -  ///valve trigger camera close if (triggerValve != null) { - CloseValveGrabImage(cBrd,testInProgress, triggerValve, e, + CloseValveGrabImage(cBrd, testInProgress, triggerValve, e, string.Format("{0}({1}) : Grabbing images - valve close", test.Method, test.Name)); } /////// -  - Bridge.OnActivity(this, Strings.Enter_water_meter_data); + + Bridge.OnActivity(this, Strings.Enter_water_meter_data); 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, - volumeCTV, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty, + ShowTestEndFormOp(sensPath.RegisterReaders, + volumeCTV, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty, refEnergy, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty)); } else { - state.AddOperation(dataEntryCmpnt.ShowTestEndFormOp(sensPath.RegisterReaders, - volumeCTV, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty)); + state.AddOperation(dataEntryCmpnt.ShowTestEndFormOp(sensPath.RegisterReaders, + volumeCTV, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty)); } state.AddOperation(checkUiOp) .AddOperations(readTempPressOps) .AddOperation(testInProgress) .EnterState(); - do { + do + { e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } } @@ -958,41 +979,41 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection { for (int i = 0; i < waterMetersCount; i++) { - GenericDevices.IRegReader rr = sensPath.RegisterReaders[i]; -  + GenericDevices.IRegReader rr = sensPath.RegisterReaders[i]; + if (rr is ICommonRegReader) (rr as ICommonRegReader).EndWMState = dataEntryCmpnt.WMEndState(i);   - if (rr is Rig.RegisterReaders.StandingStartStop.RegisterReader) - (rr as Rig.RegisterReaders.StandingStartStop.RegisterReader).EndWMState = dataEntryCmpnt.WMEndState(i); + if (rr is Rig.RegisterReaders.StandingStartStop.RegisterReader) + (rr as Rig.RegisterReaders.StandingStartStop.RegisterReader).EndWMState = dataEntryCmpnt.WMEndState(i);  - if (rr is Rig.Network.Camera.RoiForFixedStart.Roi) - (rr as Rig.Network.Camera.RoiForFixedStart.Roi).EndWMState = dataEntryCmpnt.WMEndState(i); + if (rr is Rig.Network.Camera.RoiForFixedStart.Roi) + (rr as Rig.Network.Camera.RoiForFixedStart.Roi).EndWMState = dataEntryCmpnt.WMEndState(i);  if (rr is Rig.Network.Camera.RoiForFixedStartKeyence.Roi) { (rr as Rig.Network.Camera.RoiForFixedStartKeyence.Roi).EndWMState = dataEntryCmpnt.WMEndState(i); - log.DebugFormat(" StandingStartMassCollectionSeq.cs - EndWMState [{0}] -> RoiForFixedStartKeyence.Roi",dataEntryCmpnt.WMEndState(i)); + log.DebugFormat(" StandingStartMassCollectionSeq.cs - EndWMState [{0}] -> RoiForFixedStartKeyence.Roi", dataEntryCmpnt.WMEndState(i)); } - if(rr is Rig.Network.Camera.RoiForFixedStartCJMS11.Roi) + if (rr is Rig.Network.Camera.RoiForFixedStartCJMS11.Roi) (rr as Rig.Network.Camera.RoiForFixedStartCJMS11.Roi).EndWMState = dataEntryCmpnt.WMEndState(i);  } }  - if (dataEntryCmpnt is IDataEntryForCamera && (dataEntryCmpnt as IDataEntryForCamera).SaveImages) - { + if (dataEntryCmpnt is IDataEntryForCamera && (dataEntryCmpnt as IDataEntryForCamera).SaveImages) + { log.Debug("Save images EndWMState..."); - /// SaveImages==true ... copy images to the directory that will be archived at the end of the cycle - for (int i = 0; i < sensPath.RegisterReaders.Length; i++) - { - var roi = sensPath.RegisterReaders[i] as IRegReaderStillCamera; - if (roi != null) - { - 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()); + /// SaveImages==true ... copy images to the directory that will be archived at the end of the cycle + for (int i = 0; i < sensPath.RegisterReaders.Length; i++) + { + var roi = sensPath.RegisterReaders[i] as IRegReaderStillCamera; + if (roi != null) + { + 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()); try { if (File.Exists(Path.Combine(srcDir, fileName))) @@ -1001,7 +1022,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection string destFName = string.IsNullOrEmpty((dataEntryCmpnt as IDataEntryForCamera).TestEndImgName(i, testName)) ? fileName : (dataEntryCmpnt as IDataEntryForCamera).TestEndImgName(i, testName); File.Copy(Path.Combine(srcDir, fileName), Path.Combine(destDir, destFName), true); - log.DebugFormat("Save images sourceFile: {0}, destFile: {1} ",Path.Combine(srcDir, fileName), Path.Combine(destDir, destFName)); + log.DebugFormat("Save images sourceFile: {0}, destFile: {1} ", Path.Combine(srcDir, fileName), Path.Combine(destDir, destFName)); } } catch (Exception exc) @@ -1009,8 +1030,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection log.ErrorFormat("Failed to copy image {0} to {1}: {2}", fileName, destDir, exc.Message); } } - } - } + } + }  //...MF...kvapkanie //------------------------------------------------ @@ -1059,14 +1080,14 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection  /// Raw data UpdateTempPressDensAmb(tstRslt); - tstRslt.MethodClass = TbfComponents.FindComponent(test.Method).ClassName; - tstRslt.StartTime = TestStartTime; - tstRslt.EndTime = TestEndTime; - tstRslt.FlowSetTime = flowSetTime; - tstRslt.TestTime = Math.Max(1.0, DateTimeBox.DurationSec(timeStampStart, timeStampEnd)); /// Min. 1s to prevent division by zero + tstRslt.MethodClass = TbfComponents.FindComponent(test.Method).ClassName; + tstRslt.StartTime = TestStartTime; + tstRslt.EndTime = TestEndTime; + tstRslt.FlowSetTime = flowSetTime; + tstRslt.TestTime = Math.Max(1.0, DateTimeBox.DurationSec(timeStampStart, timeStampEnd)); /// Min. 1s to prevent division by zero tstRslt.PulsesMaster = Convert.ToDouble(cBrd.RefPulses); /// Pulses of the master flow meter (test total) tstRslt.MassStartRaw = StartMass.Val; - tstRslt.MassEndRaw = EndMass.Val; + tstRslt.MassEndRaw = EndMass.Val; tstRslt.TimeBtwnMassMsrmnts = tMass2 - tMass1;  /// Corrected values @@ -1077,6 +1098,8 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection /// Main results tstRslt.VolumeCTV = volumeCTV; /// [l] 1000.0f is because density is in [kg/m3] tstRslt.Flow = 3.6 * volumeCTV / tstRslt.TestTime; /// [m3/h] + tstRslt.MassCTV = massCTV; /// [kg] 1000.0f is because density is in [kg/m3] + tstRslt.MassFlow = 3.6 * massCTV / tstRslt.TestTime; /// [kg/h]  if (cBrd is ControlBoard.Uni.UniCB) { @@ -1085,6 +1108,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection tstRslt.ConstMasterCorr = outPath.FlowMeter.LtrPerPulseCorrected(tstRslt.Flow, tstRslt.TempDownMean); tstRslt.VolumeMaster = tstRslt.ConstMasterRaw * tstRslt.PulsesMaster; /// [l] volume from the master flow meter tstRslt.ConstMaster = (tstRslt.VolumeMaster != 0) ? (tstRslt.ConstMasterRaw * tstRslt.VolumeCTV / tstRslt.VolumeMaster) : tstRslt.ConstMasterCorr; + tstRslt.MassConstMaster = (tstRslt.PulsesMaster != 0) ? (tstRslt.MassCTV / tstRslt.PulsesMaster) : tstRslt.ConstMasterCorr; } else { @@ -1095,11 +1119,12 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection tstRslt.ConstMaster = 1; } tstRslt.ErrorMaster = Formulas.ErrorFromVolumes(tstRslt.VolumeMaster, tstRslt.VolumeCTV); + tstRslt.MassErrorMaster = Formulas.ErrorFromVolumes(tstRslt.VolumeMaster, tstRslt.MassCTV);  tstRslt.FlowMean = (float)RefFlowStat.Average; - tstRslt.FlowStart = (float)RefFlowStat.First; - tstRslt.FlowEnd = (float)RefFlowStat.Last; - tstRslt.FlowMin = (float)RefFlowStat.Min; + tstRslt.FlowStart = (float)RefFlowStat.First; + tstRslt.FlowEnd = (float)RefFlowStat.Last; + tstRslt.FlowMin = (float)RefFlowStat.Min; tstRslt.FlowMax = (float)RefFlowStat.Max;  tstRslt.DiverterStart = startSwitchTime.Val; @@ -1124,7 +1149,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection for (int isAux = 0; isAux <= 1; isAux++) /// 0=main, 1=aux { Results.Entities.MeterTestRslt meterRslt = (isAux == 0) ? mainMeterRslt : auxMeterRslt; - GenericDevices.IRegReader regReader = sensPath.RegisterReaders[2 * i + isAux]; + GenericDevices.IRegReader regReader = sensPath.RegisterReaders[2 * i + isAux];  if (meterRslt != null && regReader != null) { @@ -1166,63 +1191,63 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection /// tstRslt.RefEnergy = Energy.Sum * tstRslt.VolumeCTV / VolumeForEnergy.Sum; /// [J] = [J] * [l] / [l]  - tstRslt.Custom1 = (float)TempRefHiStat.Average; - tstRslt.Custom2 = (float)TempRefHiStat.First; - tstRslt.Custom3 = (float)TempRefHiStat.Last; - tstRslt.Custom4 = (float)TempRefHiStat.Min; - tstRslt.Custom5 = (float)TempRefHiStat.Max; - tstRslt.Custom6 = (float)TempRefLoStat.Average; - tstRslt.Custom7 = (float)TempRefLoStat.First; - tstRslt.Custom8 = (float)TempRefLoStat.Last; - tstRslt.Custom9 = (float)TempRefLoStat.Min; - tstRslt.Custom10 = (float)TempRefLoStat.Max;  + tstRslt.Custom1 = (float)TempRefHiStat.Average; + tstRslt.Custom2 = (float)TempRefHiStat.First; + tstRslt.Custom3 = (float)TempRefHiStat.Last; + tstRslt.Custom4 = (float)TempRefHiStat.Min; + tstRslt.Custom5 = (float)TempRefHiStat.Max; + tstRslt.Custom6 = (float)TempRefLoStat.Average; + tstRslt.Custom7 = (float)TempRefLoStat.First; + tstRslt.Custom8 = (float)TempRefLoStat.Last; + tstRslt.Custom9 = (float)TempRefLoStat.Min; + tstRslt.Custom10 = (float)TempRefLoStat.Max;  for (int i = 0; i < BatchRslts.WMPositionsCount; i++) { if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue;  Results.Entities.MeterTestRslt volumeRslt = BatchRslts.GetMeterTestRslt(testName, i, Common.CompoundMeterId.HeatMeterVolume); - Results.Entities.MeterTestRslt energyRslt = BatchRslts.GetMeterTestRslt(testName, i, Common.CompoundMeterId.HeatMeterEnergy); + Results.Entities.MeterTestRslt energyRslt = BatchRslts.GetMeterTestRslt(testName, i, Common.CompoundMeterId.HeatMeterEnergy);  - GenericDevices.IRegReader volumeRegReader = + GenericDevices.IRegReader volumeRegReader = (sensPath.RegisterReaders.Length > 2 * i) ? sensPath.RegisterReaders[2 * i] : null;  - GenericDevices.IRegReader energyRegReader = + GenericDevices.IRegReader energyRegReader = (sensPath.RegisterReaders.Length > 2 * i + 1) ? sensPath.RegisterReaders[2 * i + 1] : null;  if (volumeRslt != null && volumeRegReader != null) { - volumeRslt.PulsesPerLiter = volumeRegReader.PulsesPerLtr; - volumeRslt.VolumeStart = volumeRegReader.BeginWMState; - volumeRslt.VolumeEnd = volumeRegReader.EndWMState; - volumeRslt.VolumeMeter = volumeRslt.VolumeEnd - volumeRslt.VolumeStart; - volumeRslt.VolumeRef = tstRslt.VolumeCTV; - volumeRslt.PulsesMeter = volumeRslt.VolumeMeter; - volumeRslt.PulsesMaster = tstRslt.PulsesMaster; /// <----------------- ??? + volumeRslt.PulsesPerLiter = volumeRegReader.PulsesPerLtr; + volumeRslt.VolumeStart = volumeRegReader.BeginWMState; + volumeRslt.VolumeEnd = volumeRegReader.EndWMState; + volumeRslt.VolumeMeter = volumeRslt.VolumeEnd - volumeRslt.VolumeStart; + volumeRslt.VolumeRef = tstRslt.VolumeCTV; + volumeRslt.PulsesMeter = volumeRslt.VolumeMeter; + volumeRslt.PulsesMaster = tstRslt.PulsesMaster; /// <----------------- ??? volumeRslt.TestTime = tstRslt.TestTime;  volumeRslt.Error = Formulas.ErrorFromVolumes(volumeRslt.VolumeMeter, volumeRslt.VolumeRef); - volumeRslt.Passed = !heatMetersTestParams.EvaluateVolume || - ((volumeRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) && - (volumeRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) && - (tstRslt.ErrorFlags == 0)); - volumeRslt.TestDone = true; + volumeRslt.Passed = !heatMetersTestParams.EvaluateVolume || + ((volumeRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) && + (volumeRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) && + (tstRslt.ErrorFlags == 0)); + volumeRslt.TestDone = true; tstRslt.TestDone = true; }  if (energyRslt != null && energyRegReader != null && dataEntryCmpnt is GenericDevices.IHasHeatMtrStatesForm) - { - volumeRslt.PulsesPerLiter = energyRegReader.PulsesPerLtr; - energyRslt.VolumeStart = (dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).EnergyStartState(i); - energyRslt.VolumeEnd = (dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).EnergyEndState(i); - energyRslt.VolumeMeter = energyRslt.VolumeEnd - energyRslt.VolumeStart; - energyRslt.VolumeRef = tstRslt.RefEnergy; - energyRslt.PulsesMeter = energyRslt.VolumeMeter; + { + volumeRslt.PulsesPerLiter = energyRegReader.PulsesPerLtr; + energyRslt.VolumeStart = (dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).EnergyStartState(i); + energyRslt.VolumeEnd = (dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).EnergyEndState(i); + energyRslt.VolumeMeter = energyRslt.VolumeEnd - energyRslt.VolumeStart; + energyRslt.VolumeRef = tstRslt.RefEnergy; + energyRslt.PulsesMeter = energyRslt.VolumeMeter; energyRslt.PulsesMaster = tstRslt.PulsesMaster; /// <----------------- ???  energyRslt.Error = Formulas.ErrorFromVolumes(energyRslt.VolumeMeter, energyRslt.VolumeRef); - energyRslt.Passed = (energyRslt.Error >= heatMetersTestParams.ErrorLimitLo) - && (energyRslt.Error <= heatMetersTestParams.ErrorLimitHi) + energyRslt.Passed = (energyRslt.Error >= heatMetersTestParams.ErrorLimitLo) + && (energyRslt.Error <= heatMetersTestParams.ErrorLimitHi) && (tstRslt.ErrorFlags == 0); energyRslt.TestDone = true; tstRslt.TestDone = true; @@ -1244,18 +1269,75 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection if (meterRslt != null && regReader != null) { meterRslt.RegReaderType = (int)regReader.RegisterReaderType; - meterRslt.PulsesPerLiter = regReader.PulsesPerLtr; + + + ComponentProcedure procParamsEntity = test.Procedure.GetProcedureParamsEntity(regReader.Name); + + try + { + if (regReader.RegisterReaderType == RegisterReaderType.Pulses || regReader.RegisterReaderType == RegisterReaderType.Manual) + { + XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(RRProcParams) })[0]; + RRProcParams tmp = Serializer.Deserialize(new StringReader(procParamsEntity.Parameters.ToString())) as RRProcParams; + regReader.PulsesPerLtr = tmp.PulsesPerLtr; + regReader.QuantityUnits = tmp.Units; + } + else + { + //MessageBox.Show("Cannot create or initialize a printer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + } + } + catch (Exception ex) + { + /*log.DebugFormat( + "Error during Procedure parameters deserialization. CmpntName='{0}', Procedure='{1}', Parameters='{2}', Exception: {3}", + dbEntity?.CmpntName, + dbEntity?.Procedure, + dbEntity?.Parameters, + ex + );*/ + } + + meterRslt.PulsesPerLiter = regReader.PulsesPerLtr;//...MF 11.12.2025 toto chybalo, v .csv bol stlpec naplneny nulami + meterRslt.QuantityUnits = regReader.QuantityUnits; meterRslt.VolumeStart = regReader.BeginWMState; meterRslt.VolumeEnd = regReader.EndWMState; meterRslt.VolumeMeter = Math.Abs(meterRslt.VolumeEnd - meterRslt.VolumeStart); - meterRslt.VolumeRef = tstRslt.VolumeCTV; /// liter + meterRslt.MassMeter = Math.Abs(meterRslt.VolumeEnd - meterRslt.VolumeStart); + meterRslt.VolumeRef = tstRslt.VolumeCTV; /// liter + meterRslt.MassRef = tstRslt.MassCTV; /// kg meterRslt.PulsesMeter = meterRslt.VolumeMeter; meterRslt.PulsesMaster = tstRslt.PulsesMaster; meterRslt.TestTime = tstRslt.TestTime; - meterRslt.Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef); - meterRslt.Passed = (meterRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) + + //meterRslt.Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef); + double Error = 0; + if (meterRslt.GetQuantityFromUnits() == "Mass") + Error = Formulas.ErrorFromVolumes(meterRslt.MassMeter, meterRslt.MassRef); + else + Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef); + + meterRslt.Error = Error; + + /*meterRslt.Passed = (meterRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) && (meterRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) - && (tstRslt.ErrorFlags == 0); + && (tstRslt.ErrorFlags == 0);*/ + var ErrLimLo_Volume = test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime); + var ErrLimHi_Volume = test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime); + var ErrLimLo_Mass = test.GetErrLimLo(tstRslt.MassCTV, tstRslt.TestTime); + var ErrLimHi_Mass = test.GetErrLimHi(tstRslt.MassCTV, tstRslt.TestTime); + + bool Passed; + if (meterRslt.GetQuantityFromUnits() == "Mass") + Passed = (meterRslt.Error >= ErrLimLo_Volume + test.Uncertainty) && + (meterRslt.Error <= ErrLimHi_Volume - test.Uncertainty) && + (tstRslt.ErrorFlags == 0); + else + Passed = (meterRslt.Error >= ErrLimLo_Mass + test.Uncertainty) && + (meterRslt.Error <= ErrLimHi_Mass - test.Uncertainty) && + (tstRslt.ErrorFlags == 0); + + meterRslt.Passed = Passed; meterRslt.TestDone = true; tstRslt.TestDone = true; if (regReader is ICommonRegReader regReaderCommon) @@ -1265,7 +1347,7 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection { meterRslt.WaterMeter.SerialNr = regReaderCommon.SerialNr; } -  + } } } @@ -1308,9 +1390,9 @@ namespace TBF.Rig.TestMethods.StandingStartMassCollection  if (stopCycle) retVal = Event.ErrorFlagsStop;  - stopTest: + stopTest:  - StopRecordingStatistics(); + StopRecordingStatistics();  /// /// Quit this sequence