/// /// Copyright (c) 2016-2017 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.Endurance { public class EnduranceSeq : Sequences.SequenceBase { private static readonly ILog log = LogManager.GetLogger(typeof(EnduranceSeq)); /// /// Endurance test 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, bool outerLoopMode, int outerLoopCounter, string enduranceCycleStr, Config.Entities.DebugMode debugLevel) { IList e = new List(); /// Events from currently running operations Event retVal = Event.Done; checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state /// Elde.ControlBoardDev cBrd = StateMachine.ControlBoard; processDataLoggingOp = new TBF.BenchControl.Operations.ProcessDataLoggingOp(processDataLogger, this, false); string enduranceLogDir = string.Format("C:\\TBF\\Results\\{0:yyyy}\\{0:MM}\\{0:dd}\\", BatchRslts.Batch.StartTime); string enduranceLogName = string.Format("{0}{1:HHmm}.txt", enduranceLogDir, BatchRslts.Batch.StartTime); System.IO.Directory.CreateDirectory(enduranceLogDir); try { bool writeHeader = !System.IO.File.Exists(enduranceLogName); System.IO.StreamWriter writer = new System.IO.StreamWriter(enduranceLogName, true); enduranceDataLoggingOp = new TBF.BenchControl.Operations.EnduranceDataLoggingOp(writer, this); if (writeHeader) LogEnduranceHeader(writer); } catch { enduranceDataLoggingOp = null; } 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); int repetitionNr = outerLoopMode ? outerLoopCounter : 1; /// Initialize repetitionNr (First test =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, 0, Convert.ToInt32(test.TstTime) + 15, 0, 0 }); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.JustStarted)); //------------------------------------------------ Bridge.OnActivity(this, Strings.Starting_the_pump); //------------------------------------------------ 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) .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) // .AddOperation(new Operations.SetAllRegulValvesOp(inPath.RegulValves, inPath.RegulValvesPct, 60)) .AddOperation(inPath.Pump != null ? cBrd.SetValvesOp(inPath.Pump, null) : null) .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; } if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } } while (e.Contains(Event.ValvesBusy) /* || !e.Contains(Event.AllPositionsReached)*/); //------------------------------------------------ Bridge.OnActivity(this, Strings.Setting_the_flow); //------------------------------------------------ int flowSetTime0 = StateMachine.Time; State.Create(string.Format("{0}({1}) : Setting the flow", test.Method, test.Name)) .AddOperation(checkUiOp) .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; double currentFlow = RefFlow.Val; if (test.DoControlWaterTemp && 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) .AddOperation(benchPath.TempMtrUp.ReadTempOp(ref TempUp)) .AddOperation(benchPath.TempMtrDown.ReadTempOp(ref TempDown)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.Next)) goto temperature_set; if (TempUp.Val >= test.TempLimLo && TempUp.Val <= test.TempLimHi && TempDown.Val >= test.TempLimLo && TempDown.Val <= test.TempLimHi) { goto temperature_set; } } while (true); } temperature_set: if (test.Part <= 3) /// 0 = measurement /// 1 = measurement through line 1 /// 2 = measurement through line 2 /// 3 = continuous test { ///----------------------------------------------------- /// Flying start measurement through line 1 or line 2 ///----------------------------------------------------- /// /// Prepare cameras, ROI-s and measurementOperations /// /// Find ROI-s IList rois = new List(); foreach (var rr in sensPath.RegisterReaders) { GenericDevices.IRoi roi = rr as GenericDevices.IRoi; if (roi != null && roi.Detected) { rois.Add(roi); } } /// Find cameras IList cameras = new List(); foreach (var roi in rois) { if (roi.Camera != null && !cameras.Contains(roi.Camera)) { roi.Camera.ClearRoiParams(); cameras.Add(roi.Camera); } } /// Register ROI-parameters to cameras foreach (var roi in rois) roi.RegisterRoiToCamera(); /// Prepare measurementOperations IList measureOperations = new List(); foreach (var camera in cameras) measureOperations.Add(camera.MeasurementOp()); //------------------------------------------------ Bridge.OnActivity(this, Strings.Test_in_progress); //------------------------------------------------ State.Create(string.Format("{0}({1}) : Starting the test", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(measureOperations) .AddOperation(benchPath.TempMtrUp == null ? null : benchPath.TempMtrUp.ReadTempOp(ref TempUp)) .AddOperation(benchPath.TempMtrDown == null ? null : benchPath.TempMtrDown.ReadTempOp(ref TempDown)) .AddOperation(outPath.TempDiv == null ? null : outPath.TempDiv.ReadTempOp(ref TempDiv)) .AddOperation(benchPath.PressMtrUp == null ? null : benchPath.PressMtrUp.ReadPressureOp(ref PressUp)) .AddOperation(benchPath.PressMtrDown == null ? null : benchPath.PressMtrDown.ReadPressureOp(ref PressDown)) .AddOperation(benchPath.PressMtrDelta == null ? null : benchPath.PressMtrDelta.ReadPressureOp(ref PressDelta)) .AddOperation(heatMetersPath == null ? null : heatMetersPath.TMeterRefWarm1.ReadTempOp(ref TempRefHi1)) .AddOperation(heatMetersPath == null ? null : heatMetersPath.TMeterRefWarm2.ReadTempOp(ref TempRefHi2)) .AddOperation(heatMetersPath == null ? null : heatMetersPath.TMeterRefCold1.ReadTempOp(ref TempRefLo1)) .AddOperation(heatMetersPath == null ? null : heatMetersPath.TMeterRefCold2.ReadTempOp(ref TempRefLo2)) .AddOperation((StateMachine.Ambient != null) ? StateMachine.Ambient.ReadAmbientOp(AmbTemp, AmbPress, AmbHumi) : null) .AddOperation(processDataLoggingOp) .AddOperation(enduranceDataLoggingOp) .AddOperation(cBrd.StartMeasurementOp(outPath, 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 TestMethods.iPerlCommunication.iPerlHead.IperlHead) { (rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name; } } /// Measurement loop - preparation readRegistersOp = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders); queryEnd1 = cBrd.QueryMeasurementEndOp(); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; ClearAllStatistics(StateMachine.Time); /// Measurement loop - begin State.Create(string.Format("{0}({1}) : Reading watermeters", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperations(measureOperations) .AddOperation(readRegistersOp) .AddOperation(benchPath.TempMtrUp == null ? null : benchPath.TempMtrUp.ReadTempOp(ref TempUp)) .AddOperation(benchPath.TempMtrDown == null ? null : benchPath.TempMtrDown.ReadTempOp(ref TempDown)) .AddOperation(outPath.TempDiv == null ? null : outPath.TempDiv.ReadTempOp(ref TempDiv)) .AddOperation(benchPath.PressMtrUp == null ? null : benchPath.PressMtrUp.ReadPressureOp(ref PressUp)) .AddOperation(benchPath.PressMtrDown == null ? null : benchPath.PressMtrDown.ReadPressureOp(ref PressDown)) .AddOperation(benchPath.PressMtrDelta == null ? null : benchPath.PressMtrDelta.ReadPressureOp(ref PressDelta)) .AddOperation(heatMetersPath == null ? null : heatMetersPath.TMeterRefWarm1.ReadTempOp(ref TempRefHi1)) .AddOperation(heatMetersPath == null ? null : heatMetersPath.TMeterRefWarm2.ReadTempOp(ref TempRefHi2)) .AddOperation(heatMetersPath == null ? null : heatMetersPath.TMeterRefCold1.ReadTempOp(ref TempRefLo1)) .AddOperation(heatMetersPath == null ? null : heatMetersPath.TMeterRefCold2.ReadTempOp(ref TempRefLo2)) .AddOperation((StateMachine.Ambient != null) ? StateMachine.Ambient.ReadAmbientOp(AmbTemp, AmbPress, AmbHumi) : null) .AddOperation(queryEnd1) .AddOperation(processDataLoggingOp) .AddOperation(enduranceDataLoggingOp) .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)); } //------------------------------------------------ RefFreq.Val = cBrd.ReferenceFreq; RefFlow.Val = cBrd.ReferenceFlow; UpdateAllStatistics(StateMachine.Time); 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.Test_completed); //------------------------------------------------ TestEndTime = DateTime.Now; /// Make sure the CycleBeginForm is closed so that water meter data (s/n) can be copied into results if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest; if (test.Part <= 2) /// 0 = measurement /// 1 = measurement through line 1 /// 2 = measurement through line 2 { /// /// Populate TestResult data entity with data /// Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(testName, test.Part); if (tstRslt != null) { UpdateTempPressDensAmb(tstRslt); /// 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 = 0; tstRslt.MassStart = 0; tstRslt.MassEndRaw = 0; tstRslt.MassEnd = 0; tstRslt.FlowMass = 0; /// [kg/h] tstRslt.FlowVolume = 3.6 * LtrPerRefPulse * tstRslt.PulsesMaster / tstRslt.TestTime; /// [m3/h] tstRslt.Buoyancy = Formulas.Buoyancy(); tstRslt.VolumeMaster = LtrPerRefPulse * tstRslt.PulsesMaster; /// [l] volume from the master flow meter tstRslt.ConstMaster = outPath.FlowMeter.LtrPerPulseCorrected(tstRslt.FlowVolume); /// Corrected master pulses per liter tstRslt.VolumeCTV = tstRslt.ConstMaster * tstRslt.PulsesMaster; /// [l] 1000.0f is because density is in [kg/m3] tstRslt.ErrorMaster = 0.0; /// Cannot be determined without a mass measurement tstRslt.FlowMean = (float)RefFlowStat.Average; tstRslt.FlowMin = (float)RefFlowStat.Min; tstRslt.FlowMax = (float)RefFlowStat.Max; /// /// Single meters /// for (int i = 0; i < BatchRslts.WMPositionsCount; i++) { if (test.Part != 0 && test.Part != Utils.PartNr(i + 1, BatchRslts.Batch.Compound)) continue; Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Config.Entities.CompoundMeterId.Single); GenericDevices.IRegisterReader regReader = sensPath.RegisterReaders[i]; TestMethods.iPerlCommunication.iPerlHead.IperlHead iPerl = regReader as TestMethods.iPerlCommunication.iPerlHead.IperlHead; 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; } else { meterRslt.TestTime = tstRslt.TestTime; /// TODO: Malo by sa citat z dosky meterRslt.VolumeStart = 0; meterRslt.VolumeEnd = 0; 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.TestDone = true; if (iPerl != null) { iPerl.LastTestResult2 = iPerl.LastTestResult; /// Save shift previous test result iPerl.LastTestResult = meterRslt; /// Save this test result iPerl.NominalTestFlowLph = 500.0 * (test.Qfrom + test.Qto); /// Ave. + convert to liter/hour } } } } 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.Scale != null ? outPath.Scale.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)); } } else if (test.Part == 4) { /// /// Endurance test : switching mode /// //------------------------------------------------ Bridge.OnActivity(this, Strings.Endurance_cycle_execution); //------------------------------------------------ State.Create(string.Format("{0}({1}) : Stopping diverter, gate, etc.", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperation(cBrd.StopPreviousOp()) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; } } while (!e.Contains(Event.PreviousStopped)); int estimtdEndTime = StateMachine.Time + (int)test.TstTime; ClearAllStatistics(StateMachine.Time); /// /// Update CyclePar[] array /// IList enduranceCycle = CycleStep.StringToCycle(enduranceCycleStr); int stepsCount = Math.Min(enduranceCycle.Count, 80); /// uint[] cyclePar = new uint[2 * stepsCount + 3]; uint duration = 10; uint state = 0; for (int i = 0; i < stepsCount; i++) { state = state | enduranceCycle[i].ValvesOpen; state = state & (~enduranceCycle[i].ValvesClose); cyclePar[2 * i + 1] = duration / 10; cyclePar[2 * i + 2] = state; duration += enduranceCycle[i].Duration; } cyclePar[2 * stepsCount + 1] = 0; cyclePar[2 * stepsCount + 2] = 0; cyclePar[0] = duration / 10; /// cBrd.CyclePar = cyclePar; /// State.Create(string.Format("{0}({1}) : Uploading cycle parameters", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperation(benchPath.TempMtrUp.ReadTempOp(ref TempUp)) .AddOperation(benchPath.TempMtrDown.ReadTempOp(ref TempDown)) .AddOperation(outPath.TempDiv.ReadTempOp(ref TempDiv)) .AddOperation(benchPath.PressMtrUp.ReadPressureOp(ref PressUp)) .AddOperation(benchPath.PressMtrDown.ReadPressureOp(ref PressDown)) .AddOperation(benchPath.PressMtrDelta == null ? null : benchPath.PressMtrDelta.ReadPressureOp(ref PressDelta)) .AddOperation((StateMachine.Ambient != null) ? StateMachine.Ambient.ReadAmbientOp(AmbTemp, AmbPress, AmbHumi) : null) .AddOperation(processDataLoggingOp) .AddOperation(enduranceDataLoggingOp) .AddOperation(cBrd.ExecuteCommandOp(Elde.Command.EnduranceCycleParamsUpload, Elde.Command.None, 0)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } RefFreq.Val = cBrd.ReferenceFreq; RefFlow.Val = cBrd.ReferenceFlow; UpdateAllStatistics(StateMachine.Time); } while (!e.Contains(Event.CommandCompleted)); bool stopInProgress = false; /// State.Create(string.Format("{0}({1}) : Executing the cycle", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperation(new Operations.TimerOp((int)test.TstTime, Event.TimerExpired)) .AddOperation(benchPath.TempMtrUp.ReadTempOp(ref TempUp)) .AddOperation(benchPath.TempMtrDown.ReadTempOp(ref TempDown)) .AddOperation(outPath.TempDiv.ReadTempOp(ref TempDiv)) .AddOperation(benchPath.PressMtrUp.ReadPressureOp(ref PressUp)) .AddOperation(benchPath.PressMtrDown.ReadPressureOp(ref PressDown)) .AddOperation(benchPath.PressMtrDelta == null ? null : benchPath.PressMtrDelta.ReadPressureOp(ref PressDelta)) .AddOperation((StateMachine.Ambient != null) ? StateMachine.Ambient.ReadAmbientOp(AmbTemp, AmbPress, AmbHumi) : null) .AddOperation(processDataLoggingOp) .AddOperation(enduranceDataLoggingOp) .AddOperation(cBrd.ExecuteCommandOp(Elde.Command.EnduranceCycleStart, Elde.Command.EnduranceCycleStop, 0)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } if (TestAndLogUiCmdStop(test, e)) { stopInProgress = true; break; } //------------------------------------------------ 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)); } //------------------------------------------------ RefFreq.Val = cBrd.ReferenceFreq; RefFlow.Val = cBrd.ReferenceFlow; UpdateAllStatistics(StateMachine.Time); Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); } while (!e.Contains(Event.TimerExpired) && !e.Contains(Event.Next)); //------------------------------------------------ Bridge.OnActivity(this, Strings.Last_cycle_wait_please); //------------------------------------------------ State.Create(string.Format("{0}({1}) : Delay to make sure the last endu.cycle completed", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperation(new Operations.TimerOp((int)(duration / 1000) + 1, Event.TimerExpired)) .AddOperation(benchPath.TempMtrUp.ReadTempOp(ref TempUp)) .AddOperation(benchPath.TempMtrDown.ReadTempOp(ref TempDown)) .AddOperation(outPath.TempDiv.ReadTempOp(ref TempDiv)) .AddOperation(benchPath.PressMtrUp.ReadPressureOp(ref PressUp)) .AddOperation(benchPath.PressMtrDown.ReadPressureOp(ref PressDown)) .AddOperation(benchPath.PressMtrDelta == null ? null : benchPath.PressMtrDelta.ReadPressureOp(ref PressDelta)) .AddOperation((StateMachine.Ambient != null) ? StateMachine.Ambient.ReadAmbientOp(AmbTemp, AmbPress, AmbHumi) : null) .AddOperation(processDataLoggingOp) .AddOperation(enduranceDataLoggingOp) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } if (TestAndLogUiCmdStop(test, e)) { stopInProgress = true; } RefFreq.Val = cBrd.ReferenceFreq; RefFlow.Val = cBrd.ReferenceFlow; UpdateAllStatistics(StateMachine.Time); Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); } while (!e.Contains(Event.TimerExpired) && !e.Contains(Event.Next)); if (stopInProgress) { retVal = Event.UiCmdStop; goto stopTest; } } if (!outerLoopMode && (++repetitionNr <= test.Repeats)) { goto loop; } stopTest: ///----------------------/// /// Quit this sequence /// ///----------------------/// State.Create(string.Format("{0}({1}) : Stopping diverter, gate, etc.", test.Method, test.Name)) .AddOperation(checkUiOp) .AddOperation(cBrd.StopPreviousOp()) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (TestAndLogUiCmdStop(test, e)) { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; } } 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, (retVal == Event.Done) ? Config.Entities.Progress.Completed : Config.Entities.Progress.Aborted)); /// Create a list with one item 'retVal' (default is Event.Done) and return it IList retList = new List(1); retList.Add(retVal); return retList; } } }