From c8afb2d87b83a0c621212acee52f298249035e15 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 2 Jun 2015 17:59:54 +0200 Subject: [PATCH] Added: Fixed start method for combined meters. Version 1.5.55. --- .../BenchControl/TbfComponents.cs | 1 + .../FixedStartCombinedMetersSeq.cs | 626 ++++++++++++++++++ .../FixedStartCombinedMeters/TestMethod.cs | 31 + .../FixedStartCombinedMeters/TestMethodCfg.cs | 35 + .../TestMethodCfgCtrl.cs | 71 ++ .../TestMethodCfgCtrl.designer.cs | 86 +++ .../TestMethodCfgCtrl.resx | 120 ++++ .../TestMethodFactory.cs | 21 + TestBenchFramework/Properties/AssemblyInfo.cs | 4 +- TestBenchFramework/TBF.csproj | 13 + 10 files changed, 1006 insertions(+), 2 deletions(-) create mode 100644 TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/FixedStartCombinedMetersSeq.cs create mode 100644 TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethod.cs create mode 100644 TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfg.cs create mode 100644 TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.cs create mode 100644 TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.designer.cs create mode 100644 TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.resx create mode 100644 TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodFactory.cs diff --git a/TestBenchFramework/BenchControl/TbfComponents.cs b/TestBenchFramework/BenchControl/TbfComponents.cs index 7d53c83a6..85ce8be2b 100644 --- a/TestBenchFramework/BenchControl/TbfComponents.cs +++ b/TestBenchFramework/BenchControl/TbfComponents.cs @@ -28,6 +28,7 @@ namespace TBF.BenchControl Factories.Add(new DataEntry.Standard.EntryFormFactory()); Factories.Add(new DataEntry.Standard24.EntryFormFactory()); Factories.Add(new Elde.Diverter.DiverterFactory()); + Factories.Add(new TestMethods.FixedStartCombinedMeters.TestMethodFactory()); Factories.Add(new TestMethods.FixedStartMassCollection.TestMethodFactory()); Factories.Add(new Elde.FixedStartRegisterReader.RegisterReaderFactory()); Factories.Add(new Elde.FlowMeter.FlowMeterFactory()); diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/FixedStartCombinedMetersSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/FixedStartCombinedMetersSeq.cs new file mode 100644 index 000000000..b8d43ef74 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/FixedStartCombinedMetersSeq.cs @@ -0,0 +1,626 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.Text; +using log4net; +using TBF.BenchControl; +using TBF.Boxes; +using TBF.Resources; +using TBF.UiBridge; + +namespace TBF.BenchControl.TestMethods.FixedStartCombinedMeters +{ + public class FixedStartCombinedMetersSeq : Sequences.SequenceBase + { + private static readonly ILog log = LogManager.GetLogger(typeof(FixedStartCombinedMetersSeq)); + + /// + /// 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(Entities.Test test) + { + Elde.ControlBoardDev cBrd = StateMachine.ControlBoard; + + IList e = new List(); /// Events from currently running operations + Event retVal = Event.Done; + checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state + + ltrPerRefPulse = outPath.FlowMeter.LtrPerPulse; /// [ltr/pulse], nominal flow in [m3/h] + + /// Notes: + /// float timeHr = volumeLtr / (1000.0f * targetFlow); + /// float timeSec = 3600.0f * timeHr; + /// int refPulses = (int)(timeSec * (2000.0f * targetFlow / pOut.FlowMeter.NominalFlow)); + int totalPulses = (int)(test.Volume / ltrPerRefPulse + 0.5f); + + processDataLoggingOp = new TBF.BenchControl.Operations.ProcessDataLoggingOp(processDataLogger, this); + + float[] wmBeginStates = new float[Program.WMsCount]; + float[] wmEndStates = new float[Program.WMsCount]; + + int repetitionNr = 1; /// First test: repetitionNr=1 + + //==================================== + // Transition or SetRoute - Start + //==================================== + switch (Transition(transitionBefore, TransitionContext.BeforeTest)) + { + case Event.Error: { retVal = Event.Error; goto stopTest; } + case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } + } + + //==================================== + loop: + /// Start the test, initialize test results + Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, totalPulses)); + Entities.TestResult tstRslt = new Entities.TestResult(test, repetitionNr, Entities.MetersKind.Combined); + + + int flowSetTime0 = StateMachine.Time; + float estFlowSetTime = 10.0f; + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Setting_the_flow); + //------------------------------------------------ + if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower); + + State.Create("FixedStartCombinedMeters : Starting the pump") + .AddOperation(checkUiOp) + .AddOperation(new Operations.TimerOp(5)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + + int flowSetTime = StateMachine.Time - flowSetTime0; + float progress = Formulas.TestProgress(flowSetTime, estFlowSetTime, test.TstTime); + Bridge.OnTestProgress(this, GetTestProgressData(test, tstRslt, false, cBrd, flowSetTime, progress)); + + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.TimerExpired)); + + + State.Create("FixedStartCombinedMeters : Starting the pump") + .AddOperation(checkUiOp) + .AddOperation(cBrd.SetValvesOp(inPath.Pump, null)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + + int flowSetTime = StateMachine.Time - flowSetTime0; + float progress = Formulas.TestProgress(flowSetTime, estFlowSetTime, test.TstTime); + Bridge.OnTestProgress(this, GetTestProgressData(test, tstRslt, false, cBrd, flowSetTime, progress)); + + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.ValvesSet)); + + + if (!test.Emptying) /// If condition met => skip measuring and force emptying + { + /// + /// Measure the weight and skip emptying if there is enough room in the tank + /// + State.Create("FixedStartCombinedMeters : Measuring the mass of water in the tank") + .AddOperation(checkUiOp) + .AddOperation(outPath.Balance.ReadMassOp(ref mass)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.BalanceDone)); + + float estimatedEndMass = mass.Val + test.Volume; + if (estimatedEndMass < outPath.Balance.Capacity * Constants.TankFullFactor) + { + goto set_flow; /// Enough room in the tank -> skip emptying + } + } + + /// + /// Empty the water tank + /// + switch (EmptyTheTank(outPath.EmptyTankValve, outPath.Balance)) + { + case Event.Error: { retVal = Event.Error; goto stopTest; } + case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } + } + + set_flow: + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Setting_the_flow); + //------------------------------------------------ + if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower); + State.Create("FixedStartCombinedMeters : Starting the pump") + .AddOperation(checkUiOp) + .AddOperation(cBrd.SetValvesOp(inPath.Pump, null)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + + int flowSetTime = StateMachine.Time - flowSetTime0; + float progress = Formulas.TestProgress(flowSetTime, estFlowSetTime, test.TstTime); + Bridge.OnTestProgress(this, GetTestProgressData(test, tstRslt, false, cBrd, flowSetTime, progress)); + + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.ValvesSet)); + + //-------------------------------- + State.Create("FixedStartCombinedMeters : Setting the flow") + .AddOperation(checkUiOp) + .AddOperation(outPath.RegulValve.SetFlowOp(outPath.FlowMeter, test.Qfrom, test.Qto, outPath.PidCoef, refFlow, 600)) /// timeout = 10 min. + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + + int flowSetTime = StateMachine.Time - flowSetTime0; + float progress = Formulas.TestProgress(flowSetTime, estFlowSetTime, test.TstTime); + Bridge.OnTestProgress(this, GetTestProgressData(test, tstRslt, false, cBrd, flowSetTime, progress)); + + if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; } + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.RegulValveTimeOut)) + { + Bridge.OnError(this, Strings.Timeout); + retVal = Event.Done; + goto stopTest; + } + if (e.Contains(Event.Next)) goto flow_set; + } + while (!e.Contains(Event.FlowReached)); + + flow_set: + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Stopping_flow_for_the_fixed_start); + //------------------------------------------------ + State.Create("FixedStartCombinedMeters : Closing the start/stop valve before the fixed start test") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, outPath.StartValve)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + } + while (!e.Contains(Event.ValvesSet)); + + + int time = StateMachine.Time; + float currentFlow = refFlow.Val; + + + /// Extract cameras from the current sensors path, add operations to the detection state + IList measureOperations = new List(); + for (int i = 0; i < sensPath.RegisterReaders.Length; i++) + { + GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; + if (cameraRoi != null) measureOperations.Add(cameraRoi.MeasureOp()); + } + + + /// + /// Enter watermeter begin states here + /// + GenericDevices.IHasWMStatesForm dataEntryCmpnt = + TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IHasWMStatesForm; + if (dataEntryCmpnt != null) + { + Bridge.OnActivity(this, "Enter the water meter data"); + State.Create("FixedStartCombinedMeters : Enter begin-state") + .AddOperation((dataEntryCmpnt as GenericDevices.IHasWMStatesForm).ShowTestStartFormOp()) + .AddOperation(checkUiOp) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.ModelessFormClosed)); + + for (int i = 0; i < Program.WMsCount; i++) + { + tstRslt.Meters[i].VolumeStart = dataEntryCmpnt.WMStartState(i); /// Units: 1 liter + /// + ///----- + BenchControl.Elde.FixedStartRegisterReader.RegisterReader registerReader = + sensPath.RegisterReaders[i] as BenchControl.Elde.FixedStartRegisterReader.RegisterReader; + + if (registerReader != null) registerReader.BeginWMState = dataEntryCmpnt.WMStartState(i); + } + } + + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Measuring_the_weight); + //------------------------------------------------ + State.Create("FixedStartCombinedMeters : Measuring the start mass") + .AddOperation(checkUiOp) + .AddOperation(benchPath.TempIn.ReadTempOp(ref tempIn)) + .AddOperation(benchPath.TempOut.ReadTempOp(ref tempOut)) + .AddOperation(outPath.TempDiv.ReadTempOp(ref tempDiv)) + .AddOperation(benchPath.PressIn.ReadPressureOp(ref pressIn)) + .AddOperation(benchPath.PressOut.ReadPressureOp(ref pressOut)) + .AddOperation((StateMachine.Ambient != null) + ? StateMachine.Ambient.ReadAmbientOp(airTemperature, airPressure, airHumidity) : null) + .AddOperations(measureOperations) + .AddOperation(outPath.Balance.ReadStableMassOp(ref startMass, 5)) + .AddOperation(cBrd.UpdateTankWeightOp()) + .AddOperation(processDataLoggingOp) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.BalanceDone)); + + tstRslt.TimeStart = DateTime.Now; + tstRslt.MassStartRaw = startMass.Val; + mass.Val = startMass.Val; + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Test_in_progress); + //------------------------------------------------ + State.Create("FixedStartCombinedMeters : Starting the test") + .AddOperation(checkUiOp) + .AddOperations(measureOperations) + .AddOperation(cBrd.StartMeasurementOp(outPath.FlowMeter, 2 * totalPulses, Elde.TestMethods.Diverter | Elde.TestMethods.Synchro, (float)test.TolerRed)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.MeasurementStarted)); + + + State.Create("FixedStartCombinedMeters : Opening the start/stop valve at the beginning of the fixed start test") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(outPath.StartValve, null)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + } + while (!e.Contains(Event.ValvesSet)); + + + /// Measurement loop - preparation + readRegisters1 = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders, ref WMPulses, ref WMRefPulses); + readRegisters2 = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders, ref WMPulses, ref WMRefPulses); + queryEnd1 = cBrd.QueryMeasurementEndOp(); + queryEnd2 = cBrd.QueryMeasurementEndOp(); + + bool firstTime = true; /// To reset sums for averaging + ResetAveragedData(); + int estimtdEndTime = StateMachine.Time + (int)test.TstTime; + + /// Measurement loop - begin + do + { + //-------------------------------- + switch (ReadRegistersTempPressAmbient(measureOperations, true)) + { + case Event.Error: { retVal = Event.Error; goto stopTest; } + case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } + case Event.MeasurementCompleted: goto test_completed; + } + + int remainingTime = Math.Max(estimtdEndTime - StateMachine.Time, 0); + Bridge.OnActivity(this, string.Format("{0} ... {1} s", Strings.Test_in_progress, remainingTime)); + + if (firstTime) + { + firstTime = false; /// Do the following only once + tstRslt.TempInStart = tempIn.Val; + tstRslt.TempOutStart = tempOut.Val; + tstRslt.TempDivStart = tempDiv.Val; + tstRslt.PressInStart = pressIn.Val; + tstRslt.PressOutStart = pressOut.Val; + } + + tstRslt.TempInEnd = tempIn.Val; + tstRslt.TempOutEnd = tempOut.Val; + tstRslt.TempDivEnd = tempDiv.Val; + tstRslt.PressInEnd = pressIn.Val; + tstRslt.PressOutEnd = pressOut.Val; + tstRslt.MassEndRaw = mass.Val; + + AccumulateAveragedData(); + + refFreq.Val = cBrd.ReferenceFreq; + refFlow.Val = cBrd.ReferenceFlow; + tstRslt.AmbientTempAve = airTemperature.Val; + tstRslt.AmbientPressAve = airPressure.Val; + tstRslt.AmbientHumiAve = airHumidity.Val; + + string logstr = string.Format("E={0} f={1} q={2}", cBrd.EtPulses(0), cBrd.ReferenceFreq, + cBrd.ReferenceFlow * outPath.FlowMeter.NominalFlow); + for (int i = 0; i < Program.WMsCount; i++) + { + logstr += string.Format(" M{0}=({1},{2})", i + 1, WMRefPulses[i], WMPulses[i]); + } + log.Debug(logstr); + + + float progress = Formulas.TestProgress(cBrd.EtPulses(0), totalPulses, estFlowSetTime, test.TstTime); + TestProgressEventArgs data = GetTestProgressData(test, tstRslt, true, cBrd, cBrd.TTime, progress); + for (int i = 0; i < Program.WMsCount / 2; i++) + { + data.TestResult.CombinedMeters[i].VolumeMeter = data.TestResult.Meters[2 * i].VolumeMeter + + data.TestResult.Meters[2 * i + 1].VolumeMeter; + if (data.Volume.Valid) + { + data.TestResult.CombinedMeters[i].VolumeErrorPct = + Formulas.ErrorFromVolumes(data.TestResult.CombinedMeters[i].VolumeMeter, data.Volume.Val); + } + } + Bridge.OnTestProgress(this, data); + } + while (cBrd.EtPulses(0) < totalPulses); + /// Measurement loop - end + + test_completed: + + State.Create("FixedStartCombinedMeters : Closing the start/stop valve at the end of the fixed start test") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, outPath.StartValve)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + } + while (e.Contains(Event.ValvesBusy)); + + + State.Create("FixedStartCombinedMeters : Waiting before 2nd mass measurement") + .AddOperation(checkUiOp) + .AddOperation(benchPath.TempIn.ReadTempOp(ref tempIn)) + .AddOperation(benchPath.TempOut.ReadTempOp(ref tempOut)) + .AddOperation(outPath.TempDiv.ReadTempOp(ref tempDiv)) + .AddOperation(benchPath.PressIn.ReadPressureOp(ref pressIn)) + .AddOperation(benchPath.PressOut.ReadPressureOp(ref pressOut)) + .AddOperation((StateMachine.Ambient != null) + ? StateMachine.Ambient.ReadAmbientOp(airTemperature, airPressure, airHumidity) : null) + .AddOperation(outPath.Balance.ReadMassOp(ref mass)) + .AddOperation(cBrd.UpdateTankWeightOp()) + .AddOperation(processDataLoggingOp) + .AddOperation(new Operations.TimerOp(test.TimeStop2Mass)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.TimerExpired)); + + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Measuring_the_weight); + //------------------------------------------------ + State.Create("FixedStartCombinedMeters : Measuring the end mass") + .AddOperation(checkUiOp) + .AddOperation(benchPath.TempIn.ReadTempOp(ref tempIn)) + .AddOperation(benchPath.TempOut.ReadTempOp(ref tempOut)) + .AddOperation(outPath.TempDiv.ReadTempOp(ref tempDiv)) + .AddOperation(benchPath.PressIn.ReadPressureOp(ref pressIn)) + .AddOperation(benchPath.PressOut.ReadPressureOp(ref pressOut)) + .AddOperation((StateMachine.Ambient != null) + ? StateMachine.Ambient.ReadAmbientOp(airTemperature, airPressure, airHumidity) : null) + .AddOperation(outPath.Balance.ReadStableMassOp(ref endMass, 5)) + .AddOperation(cBrd.UpdateTankWeightOp()) + .AddOperation(processDataLoggingOp) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.BalanceDone)); + /// + tstRslt.MassEndRaw = endMass.Val; + tstRslt.TimeEnd = DateTime.Now; + + + State.Create("FixedStartCombinedMeters : Stopping diverter, gate, etc.") + .AddOperation(checkUiOp) + .AddOperation(cBrd.StopPreviousOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.PreviousStopped)); + + + tstRslt.MassStart = Formulas.CorrectedValue(tstRslt.MassStartRaw, outPath.Balance.Corrections); + tstRslt.MassEnd = Formulas.CorrectedValue(tstRslt.MassEndRaw, outPath.Balance.Corrections); + tstRslt.MassDiff = tstRslt.MassEnd - tstRslt.MassStart; + tstRslt.DensityOut = Formulas.WaterDensityFromTemp(tstRslt.TempOutAvrg); /// [kg/m3] + tstRslt.VolumeCTV = 1.00103f * 1000.0f * tstRslt.MassDiff / tstRslt.DensityOut; /// [l] 1000.0f is because density is in [kg/m3] + + /// + /// Enter watermeter end states here + /// + if (dataEntryCmpnt != null) + { + Bridge.OnActivity(this, "Enter the water meter data"); + State.Create("FixedStartCombinedMeters : Enter end-state") + .AddOperation(dataEntryCmpnt.ShowTestEndFormOp(tstRslt.VolumeCTV, tstRslt.ErrLimLo, tstRslt.ErrLimHi)) + .AddOperation(checkUiOp) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.ModelessFormClosed)); + + + for (int i = 0; i < Program.WMsCount / 2 * 2; i++) + { + tstRslt.Meters[i].VolumeEnd = dataEntryCmpnt.WMEndState(i); + + ///----- + BenchControl.Elde.FixedStartRegisterReader.RegisterReader registerReader = + sensPath.RegisterReaders[i] as BenchControl.Elde.FixedStartRegisterReader.RegisterReader; + + if (registerReader != null) registerReader.EndWMState = dataEntryCmpnt.WMEndState(i); + } + } + + + //------------------------------------------------ + 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 (WaitBeginFormClosed()) goto stopTest; + + /// + /// Populate TestResult data entity with data + /// + UpdateTestRsltWithAveragedData(tstRslt); + + tstRslt.BatchNr = Program.LocalSettings.BatchNr; + tstRslt.MassStart = Formulas.CorrectedValue(tstRslt.MassStartRaw, outPath.Balance.Corrections); + tstRslt.MassEnd = Formulas.CorrectedValue(tstRslt.MassEndRaw, outPath.Balance.Corrections); + tstRslt.MassDiff = tstRslt.MassEnd - tstRslt.MassStart; + tstRslt.DensityIn = Formulas.WaterDensityFromTemp(tstRslt.TempInAvrg); /// [kg/m3] + tstRslt.DensityOut = Formulas.WaterDensityFromTemp(tstRslt.TempOutAvrg); /// [kg/m3] + tstRslt.DensityDiv = Formulas.WaterDensityFromTemp(tstRslt.TempDivAvrg); /// [kg/m3] + tstRslt.Time = cBrd.TTime; /// [s] measurement time + tstRslt.FlowMass = 3600.0f * tstRslt.MassDiff / tstRslt.Time; /// [kg/h] + tstRslt.FlowVolume = 3600.0f * ltrPerRefPulse * cBrd.EtPulses(0) / tstRslt.Time; /// [l/h] + tstRslt.VolumeCTV = 1.00103f * 1000.0f * tstRslt.MassDiff / tstRslt.DensityOut; /// [l] 1000.0f is because density is in [kg/m3] + tstRslt.VolumeMaster = ltrPerRefPulse * cBrd.EtPulses(0); /// [l] volume from the master flow meter + tstRslt.PulsesMaster = cBrd.EtPulses(0); /// Pulses of the master flow meter (test total) + tstRslt.ConstMaster = ltrPerRefPulse * tstRslt.VolumeCTV / tstRslt.VolumeMaster; /// Corrected master pulses per liter + + if (tstRslt.VolumeCTV <= float.Epsilon) + { + tstRslt.ErrorMaster = 0.1f; + } + else + { + tstRslt.ErrorMaster = 100 * (tstRslt.VolumeMaster - tstRslt.VolumeCTV) / tstRslt.VolumeCTV; + } + tstRslt.TimeDivStart0 = 0; + tstRslt.TimeDivStart1 = 0; + tstRslt.TimeDivStart2 = 0; + tstRslt.TimeDivStart3 = 0; + tstRslt.TimeDivStart4 = 0; + tstRslt.TimeDivStart5 = 0; + tstRslt.TimeDivEnd0 = 0; + tstRslt.TimeDivEnd1 = 0; + tstRslt.TimeDivEnd2 = 0; + tstRslt.TimeDivEnd3 = 0; + tstRslt.TimeDivEnd4 = 0; + tstRslt.TimeDivEnd5 = 0; + + for (int iCmbnd = 0; iCmbnd < Program.WMsCount / 2; iCmbnd++) + { + tstRslt.CombinedMeters[iCmbnd].VolumeRef = tstRslt.VolumeCTV; /// [l] must be calculated before main & aux. meter error + tstRslt.CombinedMeters[iCmbnd].PulsesMaster = tstRslt.PulsesMaster; + + for (int i = 2 * iCmbnd; i < 2 * iCmbnd + 2; i++) + { + tstRslt.Meters[i].PulsesPerLiter = 1.0f; + if (sensPath.RegisterReaders[i] != null && sensPath.RegisterReaders[i].PulsesPerLtr > float.Epsilon) + { + tstRslt.Meters[i].PulsesPerLiter = sensPath.RegisterReaders[i].PulsesPerLtr; + } + + tstRslt.Meters[i].SerialNr = (i < WaterMeters.Count) ? WaterMeters[i].SerialNr : string.Empty; + tstRslt.Meters[i].VolumeMeter = tstRslt.Meters[i].VolumeEnd - tstRslt.Meters[i].VolumeStart; /// [l] + tstRslt.Meters[i].VolumeRef = tstRslt.VolumeCTV; /// [l] + tstRslt.Meters[i].PulsesMeter = 0; + tstRslt.Meters[i].PulsesMaster = tstRslt.PulsesMaster; + tstRslt.Meters[i].Time = cBrd.TTime; + + tstRslt.Meters[i].VolumeErrorPct = Formulas.ErrorFromVolumes(tstRslt.Meters[i].VolumeMeter, tstRslt.CombinedMeters[iCmbnd].VolumeRef); /// Not used + } + + tstRslt.CombinedMeters[iCmbnd].VolumeMeter = tstRslt.Meters[2 * iCmbnd].VolumeMeter + tstRslt.Meters[2 * iCmbnd + 1].VolumeMeter; + + tstRslt.CombinedMeters[iCmbnd].Time = cBrd.TTime; + tstRslt.CombinedMeters[iCmbnd].VolumeErrorPct = Formulas.ErrorFromVolumes(tstRslt.CombinedMeters[iCmbnd].VolumeMeter, tstRslt.CombinedMeters[iCmbnd].VolumeRef); + tstRslt.CombinedMeters[iCmbnd].Passed = (tstRslt.ErrLimLo <= tstRslt.CombinedMeters[iCmbnd].VolumeErrorPct) && (tstRslt.CombinedMeters[iCmbnd].VolumeErrorPct <= tstRslt.ErrLimHi); + } + /// Add data - end + + AddOrOverwriteResult(tstRslt); + + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(tstRslt)); + + /// Append the results to the CSV-file + allResults.Info(TestResult2CsvLine(tstRslt)); + + + if (++repetitionNr <= test.Repeats) + { + goto loop; + } + + + stopTest: + + ///----------------------/// + /// Quit this sequence /// + ///----------------------/// + + State.Create("FixedStartCombinedMeters : Stopping diverter, gate, etc.") + .AddOperation(checkUiOp) + .AddOperation(cBrd.StopPreviousOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.PreviousStopped)); + + /// Transition sequence at the end of test + /// Prevent overwriting 'retVal' in case it was set to non-default value earlier + switch (Transition(transitionAfter, TransitionContext.AfterTest)) + { + case Event.Error: { if (retVal == Event.Done) retVal = Event.Error; break; } + case Event.UiCmdStop: { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; } + } + + /// Create a list with one item 'retVal' (default is Event.Done) and return it + IList retList = new List(1); + retList.Add(retVal); + return retList; + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethod.cs new file mode 100644 index 000000000..39d40ecf7 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethod.cs @@ -0,0 +1,31 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using log4net; +using TBF.BenchControl; + +namespace TBF.BenchControl.TestMethods.FixedStartCombinedMeters +{ + public class TestMethod : ComponentBase, GenericDevices.ITestMethod + { + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + public override string ToString() { return string.Format("TestMethods.FixedStartMassCollection({0})", Cfg.ToString(1)); } + + public bool Evaluate { get { return true; } } + public bool Publish { get { return true; } } + public bool CanTest(Entities.MetersKind meters) { return meters == Entities.MetersKind.Single; } + + public TestMethod(TestMethodCfg cfg) + : base(cfg) + { + log.Debug(this.ToString()); + } + + public IList Execute(Entities.Test test) + { + return (new FixedStartCombinedMetersSeq()).Execute(test); + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfg.cs new file mode 100644 index 000000000..12cb479d9 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfg.cs @@ -0,0 +1,35 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml.Serialization; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.TestMethods.FixedStartCombinedMeters +{ + public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg + { + public IComponent GetComponent(IList components) { return new TestMethod(this); } + public IComponentCfgCtrl GetControl() { return new TestMethodCfgCtrl(); } + + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() + { + Name = "FixedStartCombinedMeters"; + ParentName = string.Empty; + } + + public TestMethodCfg(IComponentFactory factory) + : this() + { + this.Factory = factory; + } + + public string ToString(int i) + { + return string.Format("Name={0}", Name); + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.cs new file mode 100644 index 000000000..8bde5527f --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.cs @@ -0,0 +1,71 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Windows.Forms; +using log4net; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.TestMethods.FixedStartCombinedMeters +{ + public partial class TestMethodCfgCtrl : UserControl, IComponentCfgCtrl + { + static readonly ILog log = LogManager.GetLogger(typeof(TestMethodCfgCtrl)); + + public bool ShowMore { get { return false; } } + + TestMethodCfg config; + public IComponentCfg Config + { + get { return config as IComponentCfg; } + set + { + config = value as TestMethodCfg; + Redraw(); + } + } + + public TestMethodCfgCtrl() + { + InitializeComponent(); + } + + private void EntryFormCfgCtrl_Load(object sender, EventArgs e) + { + Redraw(); + } + + public void Closing() + { + } + + void Redraw() + { + if (config == null) return; /// Control was not loaded, settings were not changed + classNameLabel.Text = config.Factory.ClassName; + nameTextBox.Text = config.Name; + } + + public void Unlock() + { + nameTextBox.Enabled = true; + } + + public CfgUpdateFlags VerifyCfg(ref string message) + { + CfgUpdateFlags flags = CfgUpdateFlags.None; + return flags; + } + + public CfgUpdateFlags UpdateCfg() + { + CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd; + + if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed + + config.Name = nameTextBox.Text; + + return flags; + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.designer.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.designer.cs new file mode 100644 index 000000000..738577fe6 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.designer.cs @@ -0,0 +1,86 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +namespace TBF.BenchControl.TestMethods.FixedStartCombinedMeters +{ + partial class TestMethodCfgCtrl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.nameTextBox = new System.Windows.Forms.TextBox(); + this.nameLabel = new System.Windows.Forms.Label(); + this.classNameLabel = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // nameTextBox + // + this.nameTextBox.Enabled = false; + this.nameTextBox.Location = new System.Drawing.Point(137, 57); + this.nameTextBox.Name = "nameTextBox"; + this.nameTextBox.Size = new System.Drawing.Size(130, 20); + this.nameTextBox.TabIndex = 5; + // + // nameLabel + // + this.nameLabel.AutoSize = true; + this.nameLabel.Location = new System.Drawing.Point(27, 60); + this.nameLabel.Name = "nameLabel"; + this.nameLabel.Size = new System.Drawing.Size(35, 13); + this.nameLabel.TabIndex = 4; + this.nameLabel.Text = "Name"; + // + // classNameLabel + // + this.classNameLabel.AutoSize = true; + this.classNameLabel.Location = new System.Drawing.Point(134, 33); + this.classNameLabel.Name = "classNameLabel"; + this.classNameLabel.Size = new System.Drawing.Size(83, 13); + this.classNameLabel.TabIndex = 3; + this.classNameLabel.Text = "ComonentName"; + // + // BasicPrinterCfgCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.nameTextBox); + this.Controls.Add(this.nameLabel); + this.Controls.Add(this.classNameLabel); + this.Name = "BasicPrinterCfgCtrl"; + this.Size = new System.Drawing.Size(300, 200); + this.Load += new System.EventHandler(this.EntryFormCfgCtrl_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox nameTextBox; + private System.Windows.Forms.Label nameLabel; + private System.Windows.Forms.Label classNameLabel; + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.resx b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodCfgCtrl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodFactory.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodFactory.cs new file mode 100644 index 000000000..7c06949dc --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartCombinedMeters/TestMethodFactory.cs @@ -0,0 +1,21 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.TestMethods.FixedStartCombinedMeters +{ + public class TestMethodFactory : IComponentFactory + { + public string ClassName { get { return "FixedStartCombinedMeters"; } } + + public void ResetStaticProperties() { TestMethod.ResetStaticProperties(); } + + public IComponentCfg DefaultConfig() { return new TestMethodCfg(this); } + + public IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(typeof(TestMethodCfg), component, this); + } + } +} diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index f448aca03..b4def9718 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.5.54.1")] -[assembly: AssemblyFileVersion("1.5.54.1")] +[assembly: AssemblyVersion("1.5.55.1")] +[assembly: AssemblyFileVersion("1.5.55.1")] diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 0f31871cc..09d759674 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -234,6 +234,16 @@ + + + + + UserControl + + + TestMethodCfgCtrl.cs + + Component @@ -1335,6 +1345,9 @@ TestMethodCfgCtrl.cs + + TestMethodCfgCtrl.cs + TestMethodCfgCtrl.cs