tbf/TestBenchFramework/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs

784 lines
36 KiB
C#

///
/// 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.FlyingStartMassCollection
{
public class FlyingStartMassCollectionSeq : Sequences.SequenceBase
{
private static readonly ILog log = LogManager.GetLogger(typeof(FlyingStartMassCollectionSeq));
/// <summary>
/// Flying start mass collection method sequence
/// </summary>
/// <param name="test">Test entity</param>
/// <returns>
/// 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
/// </returns>
public IList<Event> Execute(Config.Entities.Test test,
Compound.CombinedTestParams compoundTestParams,
HeatMeters.TestParams heatMetersTestParams)
{
Elde.ControlBoardDev cBrd = StateMachine.ControlBoard;
IList<Event> e = new List<Event>(); /// 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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;
if (heatMetersTestParams != null && heatMetersPath != null)
{
//---------------------------------------------------
Bridge.OnActivity(this, Strings.Setting_temperature);
//---------------------------------------------------
int lastTimeSec = StateMachine.Time;
float Tw_last = 0;
float Tc_last = 0;
FloatBox Tw1 = new FloatBox();
FloatBox Tw2 = new FloatBox();
FloatBox Tc1 = new FloatBox();
FloatBox Tc2 = new FloatBox();
State.Create("FixedStartMassCollection : Check temperature stabilized.")
.AddOperation(checkUiOp)
.AddOperation(heatMetersPath.TMeterRefWarm1.ReadTempOp(ref Tw1))
.AddOperation(heatMetersPath.TMeterRefWarm2.ReadTempOp(ref Tw2))
.AddOperation(heatMetersPath.TMeterRefCold1.ReadTempOp(ref Tc1))
.AddOperation(heatMetersPath.TMeterRefCold2.ReadTempOp(ref Tc2))
.EnterState();
do
{
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.Next)) goto temperature_set;
if (StateMachine.Time - lastTimeSec > 10 || StateMachine.Time - lastTimeSec < 0)
{
float Tw = (Tw1.Val + Tw2.Val) / 2.0f;
float Tc = (Tc1.Val + Tc2.Val) / 2.0f;
if (heatMetersTestParams.TempWarmLo <= Tw && Tw <= heatMetersTestParams.TempWarmHi &&
heatMetersTestParams.TempColdLo <= Tc && Tc <= heatMetersTestParams.TempColdHi &&
Math.Abs(Tw - Tw_last) <= heatMetersTestParams.ChangeInTimeWarm &&
Math.Abs(Tc - Tc_last) <= heatMetersTestParams.ChangeInTimeCold &&
Math.Abs(Tw1.Val - Tw2.Val) <= heatMetersTestParams.DeltaTempWarm &&
Math.Abs(Tc1.Val - Tc2.Val) <= heatMetersTestParams.DeltaTempCold)
{
goto temperature_set;
}
lastTimeSec = StateMachine.Time;
Tw_last = Tw;
Tc_last = Tc;
}
}
while (true);
}
temperature_set:
/// Extract cameras from the current sensors path, add operations to the detection state
IList<IOperation> measureOperations = new List<IOperation>();
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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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("FlyingStartMassCollection : 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;
if (compoundTestParams != null)
{
///
/// Compound 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 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 = (isAux == 0 && compoundTestParams.SupressTrills) ? 0 : 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;
}
}
}
else if (heatMetersTestParams != null)
{
///
/// Heat meters
///
}
else
{
///
/// Single meters
///
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;
}
}
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("FlyingStartMassCollection : 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<Event> retList = new List<Event>(1);
retList.Add(retVal);
return retList;
}
}
}