diff --git a/TestBenchFramework/BenchControl/TbfComponents.cs b/TestBenchFramework/BenchControl/TbfComponents.cs index 322f44190..69c2fc6d9 100644 --- a/TestBenchFramework/BenchControl/TbfComponents.cs +++ b/TestBenchFramework/BenchControl/TbfComponents.cs @@ -43,6 +43,7 @@ namespace TBF.BenchControl Factories.Add(new DataEntry.WMStates.EntryFormFactory()); Factories.Add(new Ambient.Comet.Factory()); Factories.Add(new Ambient.Greco.Factory()); + Factories.Add(new TestMethods.HeatMeters.TestMethodFactory()); /// HeatMeters Factories.Add(new Cameras.IdcCamera.IdcCameraFactory()); Factories.Add(new WaterMeters.iPerl.WaterMeterFactory()); /// iPerl Factories.Add(new TestMethods.iPerlCommunication.TestMethodFactory()); /// iPerlCommunication diff --git a/TestBenchFramework/BenchControl/TestMethods/HeatMeters/HeatMetersSeq.cs b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/HeatMetersSeq.cs new file mode 100644 index 000000000..41585ed39 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/HeatMetersSeq.cs @@ -0,0 +1,673 @@ +/// +/// Copyright (c) 2016 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.HeatMeters +{ + public class HeatMetersSeq : Sequences.SequenceBase + { + private static readonly ILog log = LogManager.GetLogger(typeof(HeatMetersSeq)); + + /// + /// 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(Config.Entities.Test test, HeatTestParams testParams) + { + 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 + processDataLoggingOp = new TBF.BenchControl.Operations.ProcessDataLoggingOp(processDataLogger, this); + + LtrPerRefPulse = outPath.FlowMeter.LtrPerPulse; + int totalPulses = (int)(test.Volume / LtrPerRefPulse + 0.5f); + + 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)); + string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); + TestStartTime = DateTime.Now; + TestProgressEventArgs.SetEstimatedTimes(new int[] { 1, 1, 1, 30, Convert.ToInt32(test.TstTime) + 15, 0, 0 }); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.JustStarted)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + int flowSetTime0 = StateMachine.Time; + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Checking_tank_capacity); + //------------------------------------------------ + bool tankEmptyingInProgress = test.Emptying; + + if (!tankEmptyingInProgress) /// If condition met => skip measuring and force emptying + { + /// + /// Measure the weight and skip emptying if there is enough room in the tank + /// + State.Create("HeatMeters : Checking available tank capacity") + .AddOperation(checkUiOp) + .AddOperation(outPath.Balance.ReadMassOp(ref Mass)) + .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.BalanceDone)); + + float estimatedEndMass = Mass.Val + test.Volume; + if (estimatedEndMass >= outPath.Balance.Capacity * Constants.TankFullFactor) + { + tankEmptyingInProgress = true; + } + } + /// + if (tankEmptyingInProgress) + { + State.Create("SequenceBase : Opening the emptying valve") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(outPath.EmptyTankValve, null)) + .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.ValvesSet)); + } + + + if (inPath.Pump != null) + { + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Starting_the_pump); + //------------------------------------------------ + if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower); + /// + State.Create("HeatMeters : Starting the pump") + .AddOperation(checkUiOp) + .AddOperation(cBrd.SetValvesOp(inPath.Pump, null)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.ValvesSet)); + } + + + if (test.TimePump2StartV > 0) + { + State.Create("HeatMeters : Waiting after the pump started") + .AddOperation(checkUiOp) + .AddOperation(new Operations.TimerOp(test.TimePump2StartV)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.TimerExpired)); + } + + + if (benchPath.StopBFValve != null) + { + State.Create("HeatMeters : Opening the stop backflow valve") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(benchPath.StopBFValve, null)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + } + while (!e.Contains(Event.ValvesSet)); + } + + + if (test.TimeBeforeFlow > 0) + { + State.Create("HeatMeters : Waiting before flow setting process starts") + .AddOperation(checkUiOp) + .AddOperation(new Operations.TimerOp(test.TimeBeforeFlow)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.TimerExpired)); + } + + + setting_flow: + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Setting_the_flow); + //------------------------------------------------ + State.Create("HeatMeters : Setting the flow") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .AddOperation(outPath.RegulValve.SetFlowOp(outPath.FlowMeter, test.Qfrom, test.Qto, outPath.PidCoef, RefFlow, 990)) /// timeout = 16.5 min. + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.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.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: + + int flowSetTime = StateMachine.Time - flowSetTime0; + 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()); + } + + + if (tankEmptyingInProgress) + { + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Closing_the_tank); + //------------------------------------------------ + + /// + /// Make sure tank emptying completed + /// + switch (EmptyTheTank(outPath.EmptyTankValve, outPath.Balance)) + { + case Event.Error: { retVal = Event.Error; goto stopTest; } + case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } + } + + tankEmptyingInProgress = false; + } + + if (test.TimeFlow2Mass > 0) + { + State.Create("HeatMeters : Waiting before 1st mass measurement") + .AddOperation(checkUiOp) + .AddOperation(cBrd.UpdateTankWeightOp()) + .AddOperation(new Operations.TimerOp(test.TimeFlow2Mass)) + .EnterState(); + do{ + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.TimerExpired)); + } + + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Measuring_the_weight); + //------------------------------------------------ + + LogProcessHeader(processDataLogger, "Start mass"); + + State.Create("HeatMeters : 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 PressureUp)) + .AddOperation(benchPath.PressOut.ReadPressureOp(ref PressureDown)) + .AddOperation((StateMachine.Ambient != null) + ? StateMachine.Ambient.ReadAmbientOp(AmbientTemp, AmbientPressure, AmbientHumidity) : null) + .AddOperations(measureOperations) + .AddOperation(outPath.Balance.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(cBrd.UpdateTankWeightOp()) + .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; } + } + while (!e.Contains(Event.BalanceDone)); + + LogProcessHeader(processDataLogger, "Measurement"); + + log.WarnFormat("Start mass = {0}kg", StartMass); + Mass.Val = StartMass.Val; + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Test_in_progress); + //------------------------------------------------ + State.Create("HeatMeters : Starting the test") + .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 PressureUp)) + .AddOperation(benchPath.PressOut.ReadPressureOp(ref PressureDown)) + .AddOperation((StateMachine.Ambient != null) + ? StateMachine.Ambient.ReadAmbientOp(AmbientTemp, AmbientPressure, AmbientHumidity) : null) + .AddOperations(measureOperations) + .AddOperation(Operations.EnthalpyCalculationOp.GetOp(Enthalpy, heatMetersPath)) + .AddOperation(cBrd.UpdateTankWeightOp()) + .AddOperation(processDataLoggingOp) + .AddOperation(cBrd.StartMeasurementOp(outPath, Elde.TestMethods.Diverter | Elde.TestMethods.Synchro, + test.Qfrom, test.Qto, totalPulses, (float)test.TolerRed)) + .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.MeasurementStarted)); + + + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is WaterMeters.iPerl.WaterMeter) (rr as WaterMeters.iPerl.WaterMeter).TestName = test.Name; + } + + + /// Measurement loop - preparation + readRegistersOp = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders); + + int estimtdEndTime = StateMachine.Time + (int)test.TstTime; + ClearAllStatistics(); + + /// Measurement loop - begin + State.Create("Read water meters") + .AddOperation(checkUiOp) + .AddOperations(measureOperations) + .AddOperation(readRegistersOp) + .AddOperation(benchPath.TempIn.ReadTempOp(ref TempIn)) + .AddOperation(benchPath.TempOut.ReadTempOp(ref TempOut)) + .AddOperation(outPath.TempDiv.ReadTempOp(ref TempDiv)) + .AddOperation(benchPath.PressIn.ReadPressureOp(ref PressureUp)) + .AddOperation(benchPath.PressOut.ReadPressureOp(ref PressureDown)) + .AddOperation(outPath.Balance.ReadMassOp(ref Mass)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .AddOperation((StateMachine.Ambient != null) + ? StateMachine.Ambient.ReadAmbientOp(AmbientTemp, AmbientPressure, AmbientHumidity) + : null) + .AddOperation(cBrd.QueryMeasurementEndOp()) + .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; } + if (e.Contains(Event.MeasurementCompleted)) goto test_completed; + + //------------------------------------------------ + int remainingTime = Math.Max(estimtdEndTime - StateMachine.Time, 0); + if (remainingTime > 60) + { + Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Test_in_progress, remainingTime / 60, "min", remainingTime % 60, Strings.sec)); + } + else + { + Bridge.OnActivity(this, string.Format("{0} ... {1} s", Strings.Test_in_progress, remainingTime)); + } + //------------------------------------------------ + + UpdateAllStatistics(); + RefFreq.Val = cBrd.ReferenceFreq; + RefFlow.Val = cBrd.ReferenceFlow; + + Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); + } + while (true); + /// Measurement loop - end + + test_completed: + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Measuring_the_weight); + //------------------------------------------------ + State.Create("HeatMeters : Waiting before the 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 PressureUp)) + .AddOperation(benchPath.PressOut.ReadPressureOp(ref PressureDown)) + .AddOperation(readRegistersOp) + .AddOperation((StateMachine.Ambient != null) + ? StateMachine.Ambient.ReadAmbientOp(AmbientTemp, AmbientPressure, AmbientHumidity) : 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 (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.TimerExpired)); + + LogProcessHeader(processDataLogger, "End mass"); + + State.Create("HeatMeters : 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 PressureUp)) + .AddOperation(benchPath.PressOut.ReadPressureOp(ref PressureDown)) + .AddOperation(readRegistersOp) + .AddOperation((StateMachine.Ambient != null) + ? StateMachine.Ambient.ReadAmbientOp(AmbientTemp, AmbientPressure, AmbientHumidity) : null) + .AddOperation(outPath.Balance.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod)) + .AddOperation(cBrd.UpdateTankWeightOp()) + .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; } + } + while (!e.Contains(Event.BalanceDone)); + /// + log.WarnFormat("End mass = {0}kg", EndMass); + TestEndTime = DateTime.Now; + + //------------------------------------------------ + 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 (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest; + + /// + /// Populate TestResult data entity with data + /// + Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(testName, test.Part); + + if (tstRslt != null) + { + /// Auxiliary results + tstRslt.AmbientTempAve = AmbientTempStat.Average; + tstRslt.AmbientPressAve = AmbientPressureStat.Average; + tstRslt.AmbientHumiAve = AmbientHumidityStat.Average; + tstRslt.PressUpAvrg = PressureUpStat.Average; + tstRslt.PressUpStart = PressureUpStat.First; + tstRslt.PressUpEnd = PressureUpStat.Last; + tstRslt.PressUpMin = PressureUpStat.Min; + tstRslt.PressUpMax = PressureUpStat.Max; + tstRslt.PressDownAvrg = PressureDownStat.Average; + tstRslt.PressDownStart = PressureDownStat.First; + tstRslt.PressDownEnd = PressureDownStat.Last; + tstRslt.PressDownMin = PressureDownStat.Min; + tstRslt.PressDownMax = PressureDownStat.Max; + tstRslt.TempInAvrg = TempInStat.Average; + tstRslt.TempInStart = TempInStat.First; + tstRslt.TempInEnd = TempInStat.Last; + tstRslt.TempInMin = TempInStat.Min; + tstRslt.TempInMax = TempInStat.Max; + tstRslt.TempOutAvrg = TempOutStat.Average; + tstRslt.TempOutStart = TempOutStat.First; + tstRslt.TempOutEnd = TempOutStat.Last; + tstRslt.TempOutMin = TempOutStat.Min; + tstRslt.TempOutMax = TempOutStat.Max; + tstRslt.TempDivAvrg = TempDivStat.Average; + tstRslt.TempDivStart = TempDivStat.First; + tstRslt.TempDivEnd = TempDivStat.Last; + tstRslt.TempDivMin = TempDivStat.Min; + tstRslt.TempDivMax = TempDivStat.Max; + tstRslt.DensityIn = Formulas.WaterDensityFromTemp(tstRslt.TempInAvrg); /// [kg/m3] + tstRslt.DensityOut = Formulas.WaterDensityFromTemp(tstRslt.TempOutAvrg); /// [kg/m3] + tstRslt.DensityDiv = Formulas.WaterDensityFromTemp(tstRslt.TempDivAvrg); /// [kg/m3] + + /// Main results + tstRslt.StartTime = TestStartTime; + tstRslt.EndTime = TestEndTime; + tstRslt.FlowSetTime = flowSetTime; + tstRslt.TestTime = cBrd.TTime; /// [s] measurement time + tstRslt.PulsesMaster = Convert.ToDouble(cBrd.EtPulses(0)); /// Pulses of the master flow meter (test total) + tstRslt.MassStartRaw = StartMass.Val; + tstRslt.MassStart = Formulas.CorrectedValue(tstRslt.MassStartRaw, outPath.Balance.Corrections); + tstRslt.MassEndRaw = EndMass.Val; + tstRslt.MassEnd = Formulas.CorrectedValue(tstRslt.MassEndRaw, outPath.Balance.Corrections); + tstRslt.FlowMass = 3600.0 * (tstRslt.MassEnd - tstRslt.MassStart) / tstRslt.TestTime; /// [kg/h] + tstRslt.FlowVolume = 3.6 * LtrPerRefPulse * tstRslt.PulsesMaster / tstRslt.TestTime; /// [m3/h] + tstRslt.VolumeCTV = 1001.03 * (tstRslt.MassEnd - tstRslt.MassStart) / tstRslt.DensityOut; /// [l] 1000.0f is because density is in [kg/m3] + tstRslt.VolumeMaster = LtrPerRefPulse * tstRslt.PulsesMaster; /// [l] volume from the master flow meter + tstRslt.ConstMaster = LtrPerRefPulse * tstRslt.VolumeCTV / tstRslt.VolumeMaster; /// Corrected master pulses per liter + tstRslt.ErrorMaster = Formulas.ErrorFromVolumes(tstRslt.VolumeMaster, tstRslt.VolumeCTV); + + tstRslt.FlowMin = (tstRslt.VolumeMaster != 0) ? (float)(RefFlowStat.Min * tstRslt.VolumeCTV / tstRslt.VolumeMaster) : RefFlowStat.Min; + tstRslt.FlowMax = (tstRslt.VolumeMaster != 0) ? (float)(RefFlowStat.Max * tstRslt.VolumeCTV / tstRslt.VolumeMaster) : RefFlowStat.Max; + + for (int i = 0; i < BatchRslts.WMPositionsCount; i++) + { + if (test.Part != 0 && test.Part != Utils.PartNr(i + 1, BatchRslts.Batch.Compound)) continue; + + if (BatchRslts.Batch.Compound) + { + /// + /// Compound meters + /// + Results.Entities.MeterTestRslt mainMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, Config.Entities.CompoundMeterId.CompoundMain); + Results.Entities.MeterTestRslt auxMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, Config.Entities.CompoundMeterId.CompoundAux); + + for (int isAux = 0; isAux <= 1; isAux++) /// 0=main, 1=aux + { + GenericDevices.IRegisterReader regReader = sensPath.RegisterReaders[2 * i + isAux]; + Results.Entities.MeterTestRslt meterRslt = (isAux == 0) ? mainMeterRslt : auxMeterRslt; + + if (meterRslt != null && regReader != null) + { + meterRslt.PulsesPerLiter = regReader.PulsesPerLtr; + + /// Optionally supress pulses from the large water meter + meterRslt.PulsesMeter = Convert.ToDouble(regReader.WMPulses); + meterRslt.PulsesMaster = Convert.ToDouble(regReader.WMRefPulses); + + meterRslt.TestTime = tstRslt.TestTime; + meterRslt.VolumeStart = 0; + meterRslt.VolumeEnd = 0; + meterRslt.VolumeRef = tstRslt.VolumeCTV; + meterRslt.VolumeMeter = meterRslt.PulsesMeter * regReader.LtrsPerPulse; /// liter + + if (meterRslt.PulsesMaster != 0) + { + meterRslt.VolumeMeter *= (tstRslt.PulsesMaster / meterRslt.PulsesMaster); + } + + meterRslt.Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, tstRslt.VolumeCTV); /// Main/Aux meter error is not usedfor evaluation + } + } + + Results.Entities.MeterTestRslt compoundMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, Config.Entities.CompoundMeterId.Compound); + + if (compoundMeterRslt != null && mainMeterRslt != null && auxMeterRslt != null) + { + compoundMeterRslt.VolumeRef = tstRslt.VolumeCTV; + compoundMeterRslt.VolumeMeter = mainMeterRslt.VolumeMeter + auxMeterRslt.VolumeMeter; + compoundMeterRslt.PulsesMaster = tstRslt.PulsesMaster; + compoundMeterRslt.TestTime = tstRslt.TestTime; + compoundMeterRslt.Error = Formulas.ErrorFromVolumes(compoundMeterRslt.VolumeMeter, compoundMeterRslt.VolumeRef); + compoundMeterRslt.Passed = (compoundMeterRslt.Error >= test.ErrLimLo + test.Uncertainty) + && (compoundMeterRslt.Error <= test.ErrLimHi - test.Uncertainty); + mainMeterRslt.Passed = auxMeterRslt.Passed = compoundMeterRslt.Passed; + mainMeterRslt.TestDone = auxMeterRslt.TestDone = compoundMeterRslt.TestDone = true; + } + } +#if HEAT_METERS_SUPPORT + else if (BatchRslts.Batch.HeatMeter) + { + /// + /// Heat meters + /// + } +#endif + else + { + /// MetersKind.Single meters + Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Config.Entities.CompoundMeterId.Single); + GenericDevices.IRegisterReader regReader = sensPath.RegisterReaders[i]; + WaterMeters.iPerl.WaterMeter iPerl = regReader as WaterMeters.iPerl.WaterMeter; + + if (meterRslt != null && regReader != null) + { + meterRslt.PulsesPerLiter = regReader.PulsesPerLtr; + meterRslt.PulsesMeter = Convert.ToDouble(regReader.WMPulses); + meterRslt.PulsesMaster = Convert.ToDouble(regReader.WMRefPulses); + + if (iPerl != null) + { + meterRslt.TimestampStart = iPerl.TimestampSecStart; + meterRslt.TimestampEnd = iPerl.NoSamples ? (iPerl.TimestampSecStart + tstRslt.TestTime) : iPerl.TimestampSecEnd; + meterRslt.TestTime = iPerl.NoSamples ? tstRslt.TestTime : (meterRslt.TimestampEnd - meterRslt.TimestampStart); + meterRslt.VolumeStart = iPerl.VolumeLtrStart; /// liter + meterRslt.VolumeEnd = iPerl.VolumeLtrEnd; /// liter + meterRslt.VolumeMeter = Math.Abs(iPerl.VolumeLtrEnd - iPerl.VolumeLtrStart); + meterRslt.VolumeRef = tstRslt.VolumeCTV * meterRslt.TestTime / tstRslt.TestTime; + iPerl.VolumeLtrRef = meterRslt.VolumeRef; +#if IPERLST || IPERLST_SPECIAL + meterRslt.WaterMeter.CalibFactor = (iPerl.CalibrationStruct != null) ? iPerl.CalibrationStruct.Calibration : 0; + meterRslt.WaterMeter.Q2Correction = iPerl.Q2CorrectionFactor; +#endif + iPerl.LastTestResult2 = iPerl.LastTestResult; /// Save shift previous test result + iPerl.LastTestResult = meterRslt; /// Save this test result + iPerl.NominalTestFlow = 500.0 * (test.Qfrom + test.Qto); /// Ave. + convert to liter/hour + } + else + { + meterRslt.TestTime = tstRslt.TestTime; /// TODO: Malo by sa citat z dosky + meterRslt.VolumeStart = 0; /// liter + meterRslt.VolumeEnd = 0; /// liter + meterRslt.VolumeMeter = meterRslt.PulsesMeter * regReader.LtrsPerPulse; /// liter + meterRslt.VolumeRef = meterRslt.PulsesMaster * tstRslt.ConstMaster; /// liter + } + + meterRslt.Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef); + meterRslt.Passed = (meterRslt.Error >= test.ErrLimLo + test.Uncertainty) + && (meterRslt.Error <= test.ErrLimHi - test.Uncertainty); + meterRslt.TestDone = true; + } + } + + 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, + outPath.Balance != null ? outPath.Balance.Name : string.Empty, + outPath.RegulValve != null ? outPath.RegulValve.Name : string.Empty, + outPath.Diverter != null ? outPath.Diverter.Name : string.Empty)); + } + + /// Update results + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(testName, tstRslt)); + } + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.TransitionAfter)); + + /// Append the results to the CSV-file + allResults.Info(TestResult2CsvLine(testName, test.Part)); + + if (++repetitionNr <= test.Repeats) + { + goto loop; + } + + stopTest: + + ///----------------------/// + /// Quit this sequence /// + ///----------------------/// + + State.Create("HeatMeters : Stopping diverter, gate, etc.") + .AddOperation(checkUiOp) + .AddOperation(cBrd.StopPreviousOp()) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (TestAndLogUiCmdStop(test,e)) { 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, (retVal == Event.Done) ? TransitionContext.AfterTest : TransitionContext.Stop)) + { + case Event.Error: { if (retVal == Event.Done) retVal = Event.Error; break; } + case Event.UiCmdStop: { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; } + } + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Completed)); + + /// 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/HeatMeters/HeatTestParams.cs b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/HeatTestParams.cs new file mode 100644 index 000000000..aefceb6bc --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/HeatTestParams.cs @@ -0,0 +1,112 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.IO; +using System.Text; +using System.Xml.Serialization; +using Config.Entities; +using TBF.BenchControl.Generic; +using TBF.Resources; + +namespace TBF.BenchControl.TestMethods.HeatMeters +{ + public class HeatTestParams : TestParamsBase, IParamsProvider, ITestParams + { + public bool SupressTrills; /// Main meter readings are ignored during test (suitable for small flows) + + public override void InitializeAll() + { + SupressTrills = false; + } + + + string[] paramNames = new string[] + { + Strings.SupressWMTrills, + }; + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } + + public override string ToString(int i) + { + switch (i) + { + case 0: return (SupressTrills ? Strings.yes : Strings.no); + default: return string.Empty; + } + } + + public void UpdateParam(int i, string strValue) + { + switch (i) + { + case 0: SupressTrills = strValue.Equals(Strings.yes); return; + default: return; + } + } + + public bool ValidateParam(int i, string strValue, out string message) + { + message = string.Empty; + + switch (i) + { + case 0: + if (strValue.Equals(Strings.yes) || strValue.Equals(Strings.no)) return true; + break; + default: + message = "Invalid index"; + return false; + } + + message = ParamName(i) + " is invalid"; + return false; + } + + void CopyContentTo(HeatTestParams prms) + { + prms.SupressTrills = this.SupressTrills; + } + + public IParamsProvider Clone() + { + HeatTestParams pars = new HeatTestParams(); + CopyContentTo(pars); + return pars; + } + + public override void UpdateTestParams(ComponentTest dbEntity) + { + if (dbEntity == null) return; + try + { + HeatTestParams tmp = (HeatTestParams)(new XmlSerializer(typeof(HeatTestParams))) + .Deserialize(new StringReader(dbEntity.Parameters)); + + testParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + test = dbEntity.Test; + + tmp.CopyContentTo(this); + } + catch + { + } + } + + /// + /// Parameterless constructor initializes the parameters + /// + public HeatTestParams() + { + } + + public HeatTestParams(ComponentTest testParamsEntity, string componentName, Test test) + { + this.testParamsEntity = testParamsEntity; + this.componentName = componentName; + this.test = test; + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethod.cs new file mode 100644 index 000000000..190fc9963 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethod.cs @@ -0,0 +1,39 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using log4net; +using Config.Entities; +using TBF.BenchControl; + +namespace TBF.BenchControl.TestMethods.HeatMeters +{ + public class TestMethod : ComponentBase, GenericDevices.ITestMethod + { + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + public override string ToString() { return string.Format("TestMethods.HeatMeters({0})", Cfg.ToString(1)); } + + readonly TestMethodCfg testMethodCfg; + + public bool Evaluate(Test test) { return true; } + public bool Publish(Test test) { return true; } + public bool CanTest(MetersKind meters) { return meters == MetersKind.HeatMeter; } + + public TestMethod() + { + } + + public TestMethod(TestMethodCfg cfg) + : base(cfg) + { + testMethodCfg = cfg; + log.Debug(this.ToString()); + } + + public IList Execute(Test test) + { + return (new HeatMetersSeq()).Execute(test, testMethodCfg.TestParams); + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodCfg.cs new file mode 100644 index 000000000..5c55bf3ac --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodCfg.cs @@ -0,0 +1,48 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml.Serialization; +using Config.Entities; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.TestMethods.HeatMeters +{ + public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg + { + public IComponent GetComponent(IList components) { return new TestMethod(this); } + public IComponentCfgCtrl GetControl() { return new TestMethodCfgCtrl(); } + + /// Test parameters + [XmlIgnore] + public HeatTestParams TestParams; + public override IParamsProvider GetTestParams() { return TestParams; } + public override IParamsProvider CreateTestParams(Test test) + { + HeatTestParams testParams = new HeatTestParams(); + testParams.UpdateTestParams(Name, test); + return testParams; + } + + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() + { + Name = "HeatMeters"; + ParentName = string.Empty; + TestParams = new HeatTestParams(); + } + + 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/HeatMeters/TestMethodCfgCtrl.cs b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodCfgCtrl.cs new file mode 100644 index 000000000..e05395951 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodCfgCtrl.cs @@ -0,0 +1,71 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Windows.Forms; +using log4net; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.TestMethods.HeatMeters +{ + 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/HeatMeters/TestMethodCfgCtrl.designer.cs b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodCfgCtrl.designer.cs new file mode 100644 index 000000000..8ceab0b3a --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodCfgCtrl.designer.cs @@ -0,0 +1,86 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +namespace TBF.BenchControl.TestMethods.HeatMeters +{ + 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/HeatMeters/TestMethodCfgCtrl.resx b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodCfgCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/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/HeatMeters/TestMethodFactory.cs b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodFactory.cs new file mode 100644 index 000000000..d3203e175 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/HeatMeters/TestMethodFactory.cs @@ -0,0 +1,23 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.TestMethods.HeatMeters +{ + public class TestMethodFactory : IComponentFactory + { + public string ClassName { get { return "HeatMeters"; } } + + public void ResetStaticProperties() { TestMethod.ResetStaticProperties(); } + + public IComponent DummyComponent() { return new TestMethod(); } + + public IComponentCfg DefaultConfig() { return new TestMethodCfg(this); } + + public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(typeof(TestMethodCfg), component, this); + } + } +} diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index 94b4fc319..a90e1d2b8 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.9.332.1")] -[assembly: AssemblyFileVersion("2.9.332.1")] +[assembly: AssemblyVersion("2.9.333.1")] +[assembly: AssemblyFileVersion("2.9.333.1")] diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index dbf8bd578..554a37477 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -516,6 +516,17 @@ TestMethodCfgCtrl.cs + + + + + + UserControl + + + TestMethodCfgCtrl.cs + + @@ -1727,6 +1738,9 @@ TestMethodCfgCtrl.cs + + TestMethodCfgCtrl.cs + iPerlCommunicationForm.cs