655 lines
28 KiB
C#
655 lines
28 KiB
C#
///
|
|
/// 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.FixedStartAdvanced
|
|
{
|
|
public class FixedStartAdvancedSeq : Sequences.SequenceBase
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(FixedStartAdvancedSeq));
|
|
|
|
/// <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, bool outerLoopMode, int outerLoopCounter)
|
|
{
|
|
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
|
|
|
|
LtrPerRefPulse = outPath.FlowMeter.LtrPerPulse; /// [ltr/pulse], nominal flow in [m3/h]
|
|
|
|
/// Notes:
|
|
/// float timeHr = volumeLtr / (1000.0f * targetFlow);
|
|
/// float timeSec = 3600.0f * timeHr;
|
|
/// int refPulses = (int)(timeSec * (2000.0f * targetFlow / pOut.FlowMeter.NominalFlow));
|
|
int totalPulses = (int)(test.Volume / LtrPerRefPulse + 0.5f);
|
|
|
|
processDataLoggingOp = new TBF.BenchControl.Operations.ProcessDataLoggingOp(processDataLogger, this, false);
|
|
|
|
int repetitionNr = outerLoopMode ? outerLoopCounter : 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.Setting_the_flow);
|
|
//------------------------------------------------
|
|
if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower);
|
|
|
|
State.Create("FixedStartAdvanced : Waiting 5 sec")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(new Operations.TimerOp(5))
|
|
.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));
|
|
|
|
|
|
State.Create("FixedStartAdvanced : Starting the pump")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(cBrd.SetValvesOp(inPath.Pump, 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; }
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
if (!test.Emptying) /// If condition met => skip measuring and force emptying
|
|
{
|
|
///
|
|
/// Measure the weight and skip emptying if there is enough room in the tank
|
|
///
|
|
State.Create("FixedStartAdvanced : Measuring the mass of water in the tank")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(outPath.Balance.ReadMassOp(ref Mass))
|
|
.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.Error)) { retVal = Event.Error; goto stopTest; }
|
|
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
while (!e.Contains(Event.BalanceDone));
|
|
|
|
double estimatedEndMass = Mass.Val + test.Volume;
|
|
if (estimatedEndMass < outPath.Balance.Capacity * Constants.TankFullFactor)
|
|
{
|
|
goto set_flow; /// Enough room in the tank -> skip emptying
|
|
}
|
|
}
|
|
|
|
///
|
|
/// Empty the water tank
|
|
///
|
|
switch (EmptyTheTank(outPath.EmptyTankValve, outPath.Balance))
|
|
{
|
|
case Event.Error: { retVal = Event.Error; goto stopTest; }
|
|
case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
|
|
set_flow:
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Setting_the_flow);
|
|
//------------------------------------------------
|
|
if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower);
|
|
State.Create("FixedStartAdvanced : Starting the pump")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(cBrd.SetValvesOp(inPath.Pump, 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; }
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
//--------------------------------
|
|
State.Create("FixedStartAdvanced : Setting the flow")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(outPath.RegulValve.SetFlowOp(outPath.FlowMeter, test.Qfrom, test.Qto, outPath.PidCoef, RefFlow, 600)) /// timeout = 10 min.
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
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;
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Stopping_flow_for_the_fixed_start);
|
|
//------------------------------------------------
|
|
State.Create("FixedStartAdvanced : Closing the start/stop valve before the fixed start test")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, outPath.StartValve))
|
|
.AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp())
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
int time = StateMachine.Time;
|
|
double currentFlow = RefFlow.Val;
|
|
|
|
|
|
///
|
|
/// Prepare cameras, ROI-s and measurementOperations
|
|
///
|
|
|
|
/// Find ROI-s
|
|
IList<GenericDevices.IRoi> rois = new List<GenericDevices.IRoi>();
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
{
|
|
if (rr is GenericDevices.IRoi) rois.Add(rr as GenericDevices.IRoi);
|
|
}
|
|
|
|
/// Find cameras
|
|
IList<GenericDevices.ICamera> cameras = new List<GenericDevices.ICamera>();
|
|
foreach (var roi in rois)
|
|
{
|
|
if (roi.Camera != null && !cameras.Contains(roi.Camera))
|
|
{
|
|
roi.Camera.ClearRois();
|
|
cameras.Add(roi.Camera);
|
|
}
|
|
}
|
|
|
|
/// Register ROI-parameters to cameras
|
|
foreach (var roi in rois) roi.RegisterRoiToCamera();
|
|
|
|
/// Prepare measurementOperations
|
|
IList<IOperation> measureOperations = new List<IOperation>();
|
|
foreach (var camera in cameras) measureOperations.Add(camera.MeasurementOp());
|
|
|
|
|
|
|
|
///
|
|
/// Enter watermeter begin states here
|
|
///
|
|
GenericDevices.IHasWMStatesForm dataEntryCmpnt =
|
|
TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IHasWMStatesForm;
|
|
if (dataEntryCmpnt != null)
|
|
{
|
|
Bridge.OnActivity(this, Strings.Enter_water_meter_data);
|
|
State.Create("FixedStartAdvanced : Enter begin-state")
|
|
.AddOperation((dataEntryCmpnt as GenericDevices.IHasWMStatesForm).ShowTestStartFormOp())
|
|
.AddOperation(checkUiOp)
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
while (!e.Contains(Event.ModelessFormClosed));
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++)
|
|
{
|
|
BenchControl.Elde.FixedStartRegisterReader.RegisterReader registerReader =
|
|
sensPath.RegisterReaders[i] as BenchControl.Elde.FixedStartRegisterReader.RegisterReader;
|
|
|
|
if (registerReader != null) registerReader.BeginWMState = dataEntryCmpnt.WMStartState(i);
|
|
}
|
|
}
|
|
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Measuring_the_weight);
|
|
//------------------------------------------------
|
|
State.Create("FixedStartAdvanced : Measuring the start mass")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(measureOperations)
|
|
.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(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));
|
|
|
|
TestStartTime = DateTime.Now;
|
|
Mass.Val = StartMass.Val;
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Test_in_progress);
|
|
//------------------------------------------------
|
|
State.Create("FixedStartAdvanced : Starting the test")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(measureOperations)
|
|
.AddOperation(cBrd.StartMeasurementOp(outPath, Elde.TestMethods.Diverter | Elde.TestMethods.Synchro,
|
|
test.Qfrom, test.Qto, 2 * 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));
|
|
|
|
|
|
State.Create("FixedStartAdvanced : Opening the start/stop valve at the beginning of the fixed start test")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(outPath.StartValve, null))
|
|
.AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp())
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
/// Measurement loop - preparation
|
|
readRegistersOp = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders);
|
|
queryEnd1 = cBrd.QueryMeasurementEndOp();
|
|
queryEnd2 = cBrd.QueryMeasurementEndOp();
|
|
|
|
ClearAllStatistics();
|
|
int estimtdEndTime = StateMachine.Time + (int)test.TstTime;
|
|
|
|
/// Measurement loop - begin
|
|
do
|
|
{
|
|
//--------------------------------
|
|
switch (ReadRegistersTempPressAmbient(measureOperations, true))
|
|
{
|
|
case Event.Error:
|
|
retVal = Event.Error;
|
|
goto stopTest;
|
|
|
|
case Event.UiCmdStop:
|
|
retVal = Event.UiCmdStop;
|
|
goto stopTest;
|
|
|
|
case Event.MeasurementCompleted:
|
|
goto test_completed;
|
|
}
|
|
|
|
int remainingTime = Math.Max(estimtdEndTime - StateMachine.Time, 0);
|
|
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();
|
|
|
|
Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.Test));
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test));
|
|
}
|
|
while (cBrd.EtPulses(0) < totalPulses);
|
|
/// Measurement loop - end
|
|
|
|
test_completed:
|
|
|
|
State.Create("FixedStartAdvanced : Closing the start/stop valve at the end of the fixed start test")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, outPath.StartValve))
|
|
.AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp())
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
|
|
}
|
|
while (e.Contains(Event.ValvesBusy));
|
|
|
|
|
|
State.Create("FixedStartAdvanced : Waiting before 2nd mass measurement")
|
|
.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(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));
|
|
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Measuring_the_weight);
|
|
//------------------------------------------------
|
|
State.Create("FixedStartAdvanced : Measuring the end mass")
|
|
.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(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));
|
|
///
|
|
TestEndTime = DateTime.Now;
|
|
|
|
|
|
State.Create("FixedStartAdvanced : 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));
|
|
|
|
|
|
double massStart = Formulas.CorrectedValue(StartMass.Val, outPath.Balance.Corrections);
|
|
double massEnd = Formulas.CorrectedValue(EndMass.Val, outPath.Balance.Corrections);
|
|
double densityOut = Formulas.WaterDensityFromTemp(TempDownStat.Average);
|
|
double volumeCTV = 1.00103f * 1000.0f * (massEnd - massStart) / densityOut;
|
|
|
|
///
|
|
/// Enter watermeter end states here
|
|
///
|
|
if (dataEntryCmpnt != null)
|
|
{
|
|
Bridge.OnActivity(this, Strings.Enter_water_meter_data);
|
|
State.Create("FixedStartAdvanced : Enter end-state")
|
|
.AddOperation(dataEntryCmpnt.ShowTestEndFormOp(volumeCTV, test.ErrLimLo + test.Uncertainty,
|
|
test.ErrLimHi - test.Uncertainty))
|
|
.AddOperation(checkUiOp)
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
while (!e.Contains(Event.ModelessFormClosed));
|
|
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++)
|
|
{
|
|
BenchControl.Elde.FixedStartRegisterReader.RegisterReader registerReader =
|
|
sensPath.RegisterReaders[i] as BenchControl.Elde.FixedStartRegisterReader.RegisterReader;
|
|
|
|
if (registerReader != null) registerReader.EndWMState = dataEntryCmpnt.WMEndState(i);
|
|
}
|
|
}
|
|
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Test_completed);
|
|
//------------------------------------------------
|
|
|
|
/// Make sure the CycleBeginForm is closed so that water meter data (s/n) can be copied into results
|
|
if (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.AmbTempMean = (float)AmbTempStat.Average;
|
|
tstRslt.AmbTempStart = (float)AmbTempStat.First;
|
|
tstRslt.AmbTempEnd = (float)AmbTempStat.Last;
|
|
tstRslt.AmbTempMin = (float)AmbTempStat.Min;
|
|
tstRslt.AmbTempMax = (float)AmbTempStat.Max;
|
|
tstRslt.AmbPressMean = (float)AmbPressStat.Average;
|
|
tstRslt.AmbPressStart = (float)AmbPressStat.First;
|
|
tstRslt.AmbPressEnd = (float)AmbPressStat.Last;
|
|
tstRslt.AmbPressMin = (float)AmbPressStat.Min;
|
|
tstRslt.AmbPressMax = (float)AmbPressStat.Max;
|
|
tstRslt.AmbHumiMean = (float)AmbHumiStat.Average;
|
|
tstRslt.AmbHumiStart = (float)AmbHumiStat.First;
|
|
tstRslt.AmbHumiEnd = (float)AmbHumiStat.Last;
|
|
tstRslt.AmbHumiMin = (float)AmbHumiStat.Min;
|
|
tstRslt.AmbHumiMax = (float)AmbHumiStat.Max;
|
|
tstRslt.PressUpMean = (float)PressUpStat.Average;
|
|
tstRslt.PressUpStart = (float)PressUpStat.First;
|
|
tstRslt.PressUpEnd = (float)PressUpStat.Last;
|
|
tstRslt.PressUpMin = (float)PressUpStat.Min;
|
|
tstRslt.PressUpMax = (float)PressUpStat.Max;
|
|
tstRslt.PressDownMean = (float)PressDownStat.Average;
|
|
tstRslt.PressDownStart = (float)PressDownStat.First;
|
|
tstRslt.PressDownEnd = (float)PressDownStat.Last;
|
|
tstRslt.PressDownMin = (float)PressDownStat.Min;
|
|
tstRslt.PressDownMax = (float)PressDownStat.Max;
|
|
tstRslt.PressDeltaMean = (float)PressDeltaStat.Average;
|
|
tstRslt.PressDeltaStart = (float)PressDeltaStat.First;
|
|
tstRslt.PressDeltaEnd = (float)PressDeltaStat.Last;
|
|
tstRslt.PressDeltaMin = (float)PressDeltaStat.Min;
|
|
tstRslt.PressDeltaMax = (float)PressDeltaStat.Max;
|
|
tstRslt.TempUpMean = (float)TempUpStat.Average;
|
|
tstRslt.TempUpStart = (float)TempUpStat.First;
|
|
tstRslt.TempUpEnd = (float)TempUpStat.Last;
|
|
tstRslt.TempUpMin = (float)TempUpStat.Min;
|
|
tstRslt.TempUpMax = (float)TempUpStat.Max;
|
|
tstRslt.TempDownMean = (float)TempDownStat.Average;
|
|
tstRslt.TempDownStart = (float)TempDownStat.First;
|
|
tstRslt.TempDownEnd = (float)TempDownStat.Last;
|
|
tstRslt.TempDownMin = (float)TempDownStat.Min;
|
|
tstRslt.TempDownMax = (float)TempDownStat.Max;
|
|
tstRslt.TempDivMean = (float)TempDivStat.Average;
|
|
tstRslt.TempDivStart = (float)TempDivStat.First;
|
|
tstRslt.TempDivEnd = (float)TempDivStat.Last;
|
|
tstRslt.TempDivMin = (float)TempDivStat.Min;
|
|
tstRslt.TempDivMax = (float)TempDivStat.Max;
|
|
tstRslt.DensityIn = Formulas.WaterDensityFromTemp(tstRslt.TempUpMean); /// [kg/m3]
|
|
tstRslt.DensityOut = Formulas.WaterDensityFromTemp(tstRslt.TempDownMean); /// [kg/m3]
|
|
tstRslt.DensityDiv = Formulas.WaterDensityFromTemp(tstRslt.TempDivMean); /// [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 = massStart; /// [kg] calculated before displaying 'End state' dialog
|
|
tstRslt.MassEndRaw = EndMass.Val;
|
|
tstRslt.MassEnd = massEnd; /// [kg] calculated before displaying 'End state' dialog
|
|
tstRslt.FlowMass = 3600.0 * (tstRslt.MassEnd - tstRslt.MassStart) / tstRslt.TestTime; /// [kg/h]
|
|
tstRslt.FlowVolume = 3.6 * LtrPerRefPulse * tstRslt.PulsesMaster / tstRslt.TestTime;
|
|
tstRslt.VolumeCTV = volumeCTV; /// [kg] calculated before displaying 'End state' dialog
|
|
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 = (float)((tstRslt.VolumeMaster != 0) ? (RefFlowStat.Min * tstRslt.VolumeCTV / tstRslt.VolumeMaster) : RefFlowStat.Min);
|
|
tstRslt.FlowMax = (float)((tstRslt.VolumeMaster != 0) ? (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;
|
|
|
|
Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Config.Entities.CompoundMeterId.Single);
|
|
GenericDevices.IRegisterReader regReader = sensPath.RegisterReaders[i];
|
|
|
|
if (meterRslt != null && regReader != null)
|
|
{
|
|
meterRslt.PulsesPerLiter = 1.0f;
|
|
meterRslt.VolumeStart = regReader.BeginWMState;
|
|
meterRslt.VolumeEnd = regReader.EndWMState;
|
|
meterRslt.VolumeMeter = meterRslt.VolumeEnd - meterRslt.VolumeStart;
|
|
meterRslt.VolumeRef = tstRslt.VolumeCTV; /// liter
|
|
meterRslt.PulsesMeter = meterRslt.VolumeMeter;
|
|
meterRslt.PulsesMaster = tstRslt.PulsesMaster;
|
|
meterRslt.TestTime = tstRslt.TestTime;
|
|
meterRslt.Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef);
|
|
meterRslt.Passed = (meterRslt.Error >= test.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 (!outerLoopMode && (++repetitionNr <= test.Repeats))
|
|
{
|
|
goto loop;
|
|
}
|
|
|
|
|
|
stopTest:
|
|
|
|
///----------------------///
|
|
/// Quit this sequence ///
|
|
///----------------------///
|
|
|
|
State.Create("FixedStartAdvanced : 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;
|
|
}
|
|
}
|
|
}
|