838 lines
41 KiB
C#
838 lines
41 KiB
C#
///
|
|
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
using TBF.Resources;
|
|
using TBF.UiBridge;
|
|
using TBF.BenchControl.GenericDevices;
|
|
|
|
namespace TBF.BenchControl.TestMethods.FlyingStartTankCollection
|
|
{
|
|
public class FlyingStartTankCollectionSeq : Sequences.SequenceBase
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(FlyingStartTankCollectionSeq));
|
|
|
|
/// <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, int repetitionNr, bool isLastRepetition,
|
|
Single.TestParams singleTestParams,
|
|
Compound.TestParams compoundTestParams,
|
|
Config.Entities.DebugMode debugLevel)
|
|
{
|
|
if (debugLevel == Config.Entities.DebugMode.Simulate)
|
|
{
|
|
return Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams);
|
|
}
|
|
|
|
|
|
if ((outPath.Scale == null) || !(outPath.Scale is IVolumeMeter))
|
|
{
|
|
Bridge.OnError(this, Strings.Missing_a_tank_with_volume_measurement);
|
|
return new List<Event> { Event.ConfigurationError };
|
|
}
|
|
IVolumeMeter tank = outPath.Scale as IVolumeMeter;
|
|
|
|
bool manualLevelMsrmnt = (singleTestParams != null) ? singleTestParams.ManualLevelMsrmnt : compoundTestParams.ManualLevelMsrmnt;
|
|
|
|
int rangeIx = 0; /// Default range, used for non-Elde flowmeters
|
|
if (outPath.FlowMeter is Elde.FlowMeter.FlowMeter)
|
|
{
|
|
Elde.FlowMeter.FlowMeter eldeFM = outPath.FlowMeter as Elde.FlowMeter.FlowMeter;
|
|
rangeIx = -1; /// Indicates invalid range
|
|
for (int r = 0; r <= 5; r++)
|
|
{
|
|
if (eldeFM.RangeEnabled(r) && eldeFM.GetTempLo(r) <= test.TempLimLo
|
|
&& eldeFM.GetTempHi(r) >= test.TempLimHi)
|
|
{
|
|
rangeIx = r;
|
|
}
|
|
}
|
|
|
|
if (rangeIx == -1)
|
|
{
|
|
Bridge.OnError(this, Strings.Flow_meter_temperature_range_does_not_fit_this_test_conditions);
|
|
return new List<Event> { Event.ConfigurationError };
|
|
}
|
|
}
|
|
|
|
if (test.Volume > outPath.Scale.Capacity * Constants.TankFullFactor)
|
|
{
|
|
Bridge.OnError(this, Strings.Test_volume_exceeds_the_scale_capacity);
|
|
return new List<Event> { Event.ConfigurationError };
|
|
}
|
|
|
|
|
|
IList<Event> e; /// Events from currently running operations
|
|
Event retVal = Event.Done;
|
|
Elde.ControlBoardDev cBrd = StateMachine.ControlBoard;
|
|
checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state
|
|
processDataLoggingOp = new TBF.BenchControl.Operations.ProcessDataLoggingOp(processDataLogger, this, false);
|
|
|
|
|
|
int[] filters = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
if (sensPath != null && sensPath.RegisterReaders != null)
|
|
{
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
{
|
|
TBF.BenchControl.Elde.RegisterReader.RegisterReader eldeRR = rr as TBF.BenchControl.Elde.RegisterReader.RegisterReader;
|
|
if ((eldeRR != null) && (eldeRR.Position >= 1) && (eldeRR.Position <= 8))
|
|
{
|
|
filters[eldeRR.Position - 1] = eldeRR.Filter;
|
|
}
|
|
}
|
|
}
|
|
|
|
IList<IOperation> readTempPressOps = new List<IOperation>();
|
|
if (benchPath.TempMtrUp != null) readTempPressOps.Add(benchPath.TempMtrUp.ReadTempOp(ref TempUp));
|
|
if (benchPath.TempMtrDown != null) readTempPressOps.Add(benchPath.TempMtrDown.ReadTempOp(ref TempDown));
|
|
if (outPath.TempDiv != null) readTempPressOps.Add(outPath.TempDiv.ReadTempOp(ref TempDiv));
|
|
if (benchPath.PressMtrUp != null) readTempPressOps.Add(benchPath.PressMtrUp.ReadPressureOp(ref PressUp));
|
|
if (benchPath.PressMtrDown != null) readTempPressOps.Add(benchPath.PressMtrDown.ReadPressureOp(ref PressDown));
|
|
if (benchPath.PressMtrDelta != null) readTempPressOps.Add(benchPath.PressMtrDelta.ReadPressureOp(ref PressDelta));
|
|
if (heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefWarm1.ReadTempOp(ref TempRefHi1));
|
|
if (heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefWarm2.ReadTempOp(ref TempRefHi2));
|
|
if (heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefCold1.ReadTempOp(ref TempRefLo1));
|
|
if (heatMetersPath != null) readTempPressOps.Add(heatMetersPath.TMeterRefCold2.ReadTempOp(ref TempRefLo2));
|
|
|
|
FloatBox switchTimeStart = new FloatBox(0.001f); /// in seconds, initial value is 1 ms
|
|
FloatBox switchTimeEnd = new FloatBox(0.001f); /// in seconds, initial value is 1 ms
|
|
|
|
LtrPerRefPulse = outPath.FlowMeter.LtrPerPulse;
|
|
int totalPulses = (int)(test.Volume / LtrPerRefPulse + 0.5f);
|
|
|
|
DoubleBox volumeBox = new DoubleBox();
|
|
|
|
//====================================
|
|
loop:
|
|
/// Read pressure and temperature once before calling Bridge.OnTestSelected(...)
|
|
State.Create(string.Format("{0}({1}) : Measuring process data", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.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.Busy));
|
|
|
|
/// Start the test, initialize test results
|
|
Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, heatMetersPath, totalPulses));
|
|
string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr);
|
|
TestStartTime = DateTime.Now;
|
|
|
|
|
|
///
|
|
/// Optionally drain the water tank
|
|
///
|
|
if (test.DoDraining)
|
|
{
|
|
switch (DrainTheTank(outPath.Scale))
|
|
{
|
|
case Event.Error: { retVal = Event.Error; goto stopTest; }
|
|
case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
}
|
|
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Starting_the_pump);
|
|
//------------------------------------------------
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting));
|
|
int flowSetTime0 = StateMachine.Time;
|
|
|
|
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)
|
|
.AddOperations(readTempPressOps)
|
|
//.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)*/);
|
|
|
|
|
|
if (test.TimePump2StartV > 0)
|
|
{
|
|
State.Create(string.Format("{0}({1}) : Waiting after the pump started", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperation(new Operations.TimerOp(test.TimePump2StartV))
|
|
.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(string.Format("{0}({1}) : Opening the stop backflow valve", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(benchPath.StopBFValve, null))
|
|
.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(string.Format("{0}({1}) : Waiting before flow setting process starts", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperation(new Operations.TimerOp(test.TimeBeforeFlow))
|
|
.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(string.Format("{0}({1}) : Setting the flow", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperation(outPath.RegulValve.SetFlowOp(outPath.FlowMeter, test.Qfrom, test.Qto, outPath.PidCoef, filters, (test.TolerRed == 0) ? 0 : 1, RefFlow, FlowSettingTimeoutSec))
|
|
.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.Flow_adjustment_failed);
|
|
retVal = Event.RecoverableError;
|
|
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)
|
|
.AddOperations(readTempPressOps)
|
|
.EnterState();
|
|
do {
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
if (e.Contains(Event.Next)) goto temperature_set;
|
|
|
|
if ((test.TempLimLo <= TempUp.Val) && (TempUp.Val <= test.TempLimHi) &&
|
|
(test.TempLimLo <= TempDown.Val) && (TempDown.Val <= test.TempLimHi))
|
|
{
|
|
goto temperature_set;
|
|
}
|
|
}
|
|
while (true);
|
|
}
|
|
|
|
temperature_set:
|
|
|
|
///
|
|
/// Prepare cameras, ROI-s and measurementOperations
|
|
///
|
|
|
|
/// Find successfully detected ROI-s
|
|
IList<GenericDevices.IRoi> rois = new List<GenericDevices.IRoi>();
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
{
|
|
GenericDevices.IRoi cameraRoI = rr as GenericDevices.IRoi;
|
|
if ((cameraRoI != null) && cameraRoI.Detected)
|
|
{
|
|
rois.Add(cameraRoI);
|
|
}
|
|
}
|
|
|
|
/// Find cameras
|
|
IList<GenericDevices.ICamera> cameras = new List<GenericDevices.ICamera>();
|
|
foreach (var roi in rois)
|
|
{
|
|
if (roi.Camera != null && !cameras.Contains(roi.Camera))
|
|
{
|
|
cameras.Add(roi.Camera);
|
|
roi.Camera.ClearRoiParams();
|
|
}
|
|
}
|
|
|
|
/// 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());
|
|
|
|
|
|
LogProcessDataTestInfo(processDataLogger, test.Procedure.Name, test.Name);
|
|
LogProcessDataHeader(processDataLogger, "Measurement");
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Test_in_progress);
|
|
//------------------------------------------------
|
|
State.Create(string.Format("{0}({1}) : Starting the test", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperations(measureOperations)
|
|
.AddOperation(processDataLoggingOp)
|
|
.AddOperation(cBrd.StartMeasurementOp(outPath, Elde.TestMethods.Diverter | Elde.TestMethods.Synchro,
|
|
test.Qfrom, test.Qto, totalPulses, filters, (test.TolerRed == 0) ? 0 : 1))
|
|
.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)
|
|
{
|
|
GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
|
|
if (readerWithTstName != null)
|
|
{
|
|
readerWithTstName.TestName = test.Name;
|
|
readerWithTstName.TestRepeats = test.Repeats;
|
|
readerWithTstName.RepetitionNr = repetitionNr;
|
|
}
|
|
}
|
|
|
|
|
|
/// Measurement loop - preparation
|
|
readRegistersOp = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders);
|
|
|
|
int estimtdEndTime = StateMachine.Time + (int)test.TstTime;
|
|
StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, 0);
|
|
|
|
/// Measurement loop - begin
|
|
State.Create(string.Format("{0}({1}) : Reading watermeters", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperations(measureOperations)
|
|
.AddOperation(readRegistersOp)
|
|
.AddOperation(cBrd.ReadDiverterTransitionOp(outPath.Diverter, 2, 4, switchTimeStart, DiverterStart, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, filters, (test.TolerRed == 0) ? 0 : 1))
|
|
.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));
|
|
}
|
|
//------------------------------------------------
|
|
|
|
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.Next)); /// 'Next' button can be used in Debug version
|
|
|
|
/// Measurement loop - end
|
|
|
|
test_completed:
|
|
|
|
StopRecordingStatistics();
|
|
|
|
///
|
|
/// (Berlin:) Water is stopped immediately after the test and before the 2nd mass measurement in case:
|
|
/// - no 'transition sequence after test' is used
|
|
/// - this is the last (or the only) test repetition or test is a part of an 'outer loop'
|
|
///
|
|
#if !CEVAK_200
|
|
if (isLastRepetition && transitionAfter == null)
|
|
#endif
|
|
{
|
|
if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOff();
|
|
|
|
State.Create("SequenceBase : Transition : TestEnd - Default action")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
|
|
.EnterState();
|
|
do {
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
|
|
if (TestAndLogUiCmdStop(e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
}
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Wait_please);
|
|
//------------------------------------------------
|
|
State.Create(string.Format("{0}({1}) : Waiting before the water level measurement", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperation(cBrd.ReadDiverterTransitionOp(outPath.Diverter, 2, 4, switchTimeEnd, DiverterEnd, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, filters, (test.TolerRed == 0) ? 0 : 1))
|
|
.AddOperation(new Operations.TimerOp(test.TimeStop2Mass))
|
|
.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.TimerExpired));
|
|
|
|
|
|
LogProcessDataHeader(processDataLogger, "Water level measurement");
|
|
|
|
|
|
State.Create(string.Format("{0}({1}) : Water level measurement", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperation(manualLevelMsrmnt ? tank.ManualReadVolumeOp(ref volumeBox) : tank.ReadStableVolumeOp(ref volumeBox, test.MassSpread))
|
|
.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.VolumeDone));
|
|
///
|
|
log.WarnFormat("Volumes = {0}l", volumeBox.Val);
|
|
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)
|
|
{
|
|
UpdateTempPressDensAmb(tstRslt);
|
|
|
|
/// Main results
|
|
tstRslt.MethodClass = TbfComponents.FindComponent(test.Method).ClassName;
|
|
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;
|
|
tstRslt.FlowVolume = 3.6 * LtrPerRefPulse * tstRslt.PulsesMaster / tstRslt.TestTime; /// [m3/h]
|
|
tstRslt.Buoyancy = 0;
|
|
tstRslt.VolumeCTV = volumeBox.Val; /// [l]
|
|
tstRslt.VolumeMaster = LtrPerRefPulse * tstRslt.PulsesMaster; /// [l] volume from the master flow meter
|
|
tstRslt.ConstMasterRaw = outPath.FlowMeter.LtrPerPulse; /// Uncorrected master flowmeter coefficient
|
|
tstRslt.ConstMasterCorr = outPath.FlowMeter.LtrPerPulseCorrected(tstRslt.FlowVolume, rangeIx); /// Corrected master pulses per liter
|
|
tstRslt.ConstMaster = (tstRslt.VolumeMaster == 0) ? tstRslt.ConstMasterCorr : (LtrPerRefPulse * tstRslt.VolumeCTV / tstRslt.VolumeMaster);
|
|
/// Calculated master pulses per liter
|
|
tstRslt.ErrorMaster = Config.Formulas.ErrorFromVolumes(tstRslt.VolumeMaster, tstRslt.VolumeCTV);
|
|
|
|
tstRslt.FlowMean = (float)RefFlowStat.Average;
|
|
tstRslt.FlowStart = (float)RefFlowStat.First;
|
|
tstRslt.FlowEnd = (float)RefFlowStat.Last;
|
|
tstRslt.FlowMin = (float)RefFlowStat.Min;
|
|
tstRslt.FlowMax = (float)RefFlowStat.Max;
|
|
|
|
tstRslt.DiverterStart = switchTimeStart.Val;
|
|
tstRslt.DivStart10 = 0;
|
|
tstRslt.DivStart50 = 0;
|
|
tstRslt.DivStart90 = 0;
|
|
tstRslt.DiverterEnd = switchTimeEnd.Val;
|
|
tstRslt.DivEnd90 = 0;
|
|
tstRslt.DivEnd50 = 0;
|
|
tstRslt.DivEnd10 = 0;
|
|
log.DebugFormat("Diverter switch time [s]: Start: {0}ms ({1} {2} {3}) End: {4}ms ({5} {6} {7})",
|
|
(tstRslt.DiverterStart * 1000).ToString("F0"), tstRslt.DivStart10, tstRslt.DivStart50, tstRslt.DivStart90,
|
|
(tstRslt.DiverterEnd * 1000).ToString("F0"), tstRslt.DivEnd90, tstRslt.DivEnd50, tstRslt.DivEnd10);
|
|
|
|
tstRslt.ErrorFlagsMd = (ErrorFlagsComp != null) ? (sbyte)ErrorFlagsComp.Mode : (sbyte)0;
|
|
tstRslt.ErrorFlags = (ErrorFlagsComp != null) ? ErrorFlagsComp.GetErrorFlags(tstRslt, true, false, tstRslt.DiverterStart, tstRslt.DiverterEnd) : 0;
|
|
|
|
if (compoundTestParams != null)
|
|
{
|
|
///
|
|
/// Compound meters
|
|
///
|
|
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
|
|
{
|
|
if (!test.IsPartCompatible(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.RegReaderType = (int)regReader.RegisterReaderType;
|
|
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 = cBrd.ImpulseTime(2 * i + isAux + 1);
|
|
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 = Config.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 = Config.Formulas.ErrorFromVolumes(compoundMeterRslt.VolumeMeter, compoundMeterRslt.VolumeRef);
|
|
compoundMeterRslt.Passed = (compoundMeterRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty)
|
|
&& (compoundMeterRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty)
|
|
&& (tstRslt.ErrorFlags == 0 || tstRslt.ErrorFlagsMode() != Config.Entities.ErrorFlagsMode.On);
|
|
mainMeterRslt.Passed = auxMeterRslt.Passed = compoundMeterRslt.Passed;
|
|
mainMeterRslt.TestDone = auxMeterRslt.TestDone = compoundMeterRslt.TestDone = true;
|
|
tstRslt.TestDone = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
///
|
|
/// Single meters
|
|
///
|
|
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
|
|
{
|
|
if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue;
|
|
|
|
/// MetersKind.Single meters
|
|
Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Config.Entities.CompoundMeterId.Single);
|
|
GenericDevices.IRegisterReader regReader = sensPath.RegisterReaders[i];
|
|
GenericDevices.IDatastreamReader dstrReader = regReader as GenericDevices.IDatastreamReader;
|
|
TestMethods.iPerlCommunication.iPerlHead.IperlHead iPerl = regReader as TestMethods.iPerlCommunication.iPerlHead.IperlHead;
|
|
GenericDevices.IRoi cameraRoi = regReader as GenericDevices.IRoi;
|
|
|
|
if (meterRslt != null && regReader != null)
|
|
{
|
|
meterRslt.RegReaderType = (int)regReader.RegisterReaderType;
|
|
meterRslt.PulsesPerLiter = regReader.PulsesPerLtr;
|
|
meterRslt.PulsesMeter = Convert.ToDouble(regReader.WMPulses);
|
|
|
|
if (dstrReader != null)
|
|
{
|
|
|
|
meterRslt.TimestampStart = dstrReader.TimestampSecStart;
|
|
meterRslt.TimestampEnd = dstrReader.NoSamples ? (dstrReader.TimestampSecStart + tstRslt.TestTime) : dstrReader.TimestampSecEnd;
|
|
meterRslt.TestTime = meterRslt.TimestampEnd - meterRslt.TimestampStart;
|
|
meterRslt.VolumeStart = dstrReader.VolumeLtrStart; /// liter
|
|
meterRslt.VolumeEnd = dstrReader.VolumeLtrEnd; /// liter
|
|
meterRslt.VolumeMeter = Math.Abs(dstrReader.VolumeLtrEnd - dstrReader.VolumeLtrStart);
|
|
meterRslt.VolumeRef = tstRslt.VolumeCTV * meterRslt.TestTime / tstRslt.TestTime;
|
|
meterRslt.PulsesMaster = tstRslt.PulsesMaster * meterRslt.TestTime / tstRslt.TestTime;
|
|
|
|
if (iPerl != null)
|
|
{
|
|
if (iPerl.ResultCode != 0 && (meterRslt.WaterMeter.ResultCode & (int)Results.Entities.ResultCode.OptoErrorCodeMask) == 0)
|
|
{
|
|
meterRslt.WaterMeter.ResultCode |= iPerl.ResultCode;
|
|
}
|
|
#if IPERL
|
|
meterRslt.WaterMeter.CalibFactor = iPerl.CalibFactor;
|
|
#endif
|
|
iPerl.LastTestResult2 = iPerl.LastTestResult; /// Save shift previous test result
|
|
iPerl.LastTestResult = meterRslt; /// Save this test result
|
|
}
|
|
}
|
|
else if (cameraRoi != null)
|
|
{
|
|
meterRslt.TimestampStart = cameraRoi.TimestampStart; /// second
|
|
meterRslt.TimestampEnd = cameraRoi.TimestampEnd; /// second
|
|
|
|
meterRslt.VolumeStart = cameraRoi.VolumeStart; /// liter
|
|
meterRslt.VolumeEnd = cameraRoi.VolumeEnd; /// liter
|
|
meterRslt.VolumeMeter = cameraRoi.VolumeEnd - cameraRoi.VolumeStart; /// liter
|
|
|
|
if (meterRslt.VolumeMeter != 0)
|
|
{
|
|
/// Normal measurement with camera
|
|
meterRslt.TestTime = cameraRoi.TimestampEnd - cameraRoi.TimestampStart; /// second
|
|
meterRslt.VolumeRef = tstRslt.VolumeCTV * meterRslt.TestTime / tstRslt.TestTime;
|
|
meterRslt.PulsesMaster = tstRslt.PulsesMaster * meterRslt.TestTime / tstRslt.TestTime;
|
|
}
|
|
else
|
|
{
|
|
/// None or one pulse from the water meter using camera
|
|
meterRslt.TestTime = tstRslt.TestTime;
|
|
meterRslt.VolumeRef = tstRslt.VolumeCTV;
|
|
meterRslt.PulsesMaster = tstRslt.PulsesMaster;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
meterRslt.PulsesMaster = Convert.ToDouble(regReader.WMRefPulses);
|
|
meterRslt.VolumeStart = 0; /// liter
|
|
meterRslt.VolumeEnd = 0; /// liter
|
|
meterRslt.VolumeMeter = meterRslt.PulsesMeter * regReader.LtrsPerPulse; /// liter
|
|
///
|
|
if (regReader.WMPulses >= 1)
|
|
{
|
|
/// Normal measurement
|
|
meterRslt.TestTime = cBrd.ImpulseTime(i + 1);
|
|
meterRslt.VolumeRef = meterRslt.PulsesMaster * tstRslt.ConstMaster; /// liter
|
|
}
|
|
else
|
|
{
|
|
/// None or one pulse from the water meter
|
|
meterRslt.TestTime = tstRslt.TestTime;
|
|
meterRslt.VolumeRef = tstRslt.VolumeCTV; /// liter
|
|
}
|
|
}
|
|
|
|
meterRslt.Error = Config.Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef);
|
|
|
|
#if TEST_MODE
|
|
if (!BatchRslts.IsProduction() &&
|
|
((test.Name.ToLower().Contains("q2") && Math.Abs(meterRslt.Error) > 2.0 && Math.Abs(meterRslt.Error) <= 4.0) ||
|
|
(test.Name.ToLower().Contains("q1") && Math.Abs(meterRslt.Error) > 5.0 && Math.Abs(meterRslt.Error) <= 10.0)))
|
|
{
|
|
meterRslt.KorrErrQ = meterRslt.Error;
|
|
meterRslt.Error /= 2.0;
|
|
meterRslt.VolumeMeter = (1.0 + meterRslt.Error / 100.0) * meterRslt.VolumeRef;
|
|
meterRslt.PulsesMeter = meterRslt.VolumeMeter * regReader.PulsesPerLtr;
|
|
|
|
if (meterRslt.VolumeEnd > meterRslt.VolumeStart)
|
|
{
|
|
meterRslt.VolumeEnd = meterRslt.VolumeStart + meterRslt.VolumeMeter;
|
|
}
|
|
else if (meterRslt.VolumeEnd < meterRslt.VolumeStart)
|
|
{
|
|
meterRslt.VolumeEnd = meterRslt.VolumeStart - meterRslt.VolumeMeter;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
meterRslt.KorrErrQ = 0;
|
|
}
|
|
#endif
|
|
|
|
meterRslt.Passed = (meterRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty)
|
|
&& (meterRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty)
|
|
&& (tstRslt.ErrorFlags == 0 || tstRslt.ErrorFlagsMode() != Config.Entities.ErrorFlagsMode.On);
|
|
meterRslt.TestDone = true;
|
|
tstRslt.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.Scale != null ? outPath.Scale.Name : string.Empty,
|
|
outPath.RegulValve != null ? outPath.RegulValve.Name : string.Empty,
|
|
outPath.Diverter != null ? outPath.Diverter.Name : string.Empty));
|
|
|
|
/// Update water meter error flags
|
|
if (ErrorFlagsComp != null)
|
|
{
|
|
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
|
|
{
|
|
if (BatchRslts.WaterMeters[i] != null)
|
|
{
|
|
BatchRslts.WaterMeters[i].ErrorFlags = ErrorFlagsComp.GetWMtrErrorFlags(BatchRslts.WaterMeters[i].MeterTestRslts);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 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));
|
|
|
|
stopTest:
|
|
|
|
StopRecordingStatistics(); /// Make sure graph files are closed
|
|
|
|
///
|
|
/// Quit this sequence
|
|
///
|
|
if (isLastRepetition || retVal == Event.UiCmdStop || retVal == Event.OpArgumentError
|
|
|| retVal == Event.Error || retVal == Event.ConfigurationError)
|
|
{
|
|
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)) break;
|
|
}
|
|
while (!e.Contains(Event.PreviousStopped));
|
|
}
|
|
|
|
return new List<Event> { retVal };
|
|
}
|
|
|
|
|
|
public IList<Event> Simulate(Config.Entities.Test test, int repetitionNr, bool isLastRepetition,
|
|
Single.TestParams singleTestParams,
|
|
Compound.TestParams compoundTestParams)
|
|
{
|
|
///
|
|
/// Test method simulation
|
|
///
|
|
if ((outPath.Scale == null) || !(outPath.Scale is IVolumeMeter))
|
|
{
|
|
Bridge.OnError(this, Strings.Missing_a_tank_with_volume_measurement);
|
|
return new List<Event> { Event.ConfigurationError };
|
|
}
|
|
IVolumeMeter tank = outPath.Scale as IVolumeMeter;
|
|
|
|
bool manualLevelMsrmnt = (singleTestParams != null) ? singleTestParams.ManualLevelMsrmnt : compoundTestParams.ManualLevelMsrmnt;
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting));
|
|
|
|
IList<Event> e = new List<Event>(); /// Events from currently running operations
|
|
Event retVal = Event.Done;
|
|
DoubleBox volumeBox = new DoubleBox();
|
|
///
|
|
IOperation msrVolOp = manualLevelMsrmnt ? tank.ManualReadVolumeOp(ref volumeBox) : tank.ReadStableVolumeOp(ref volumeBox, test.MassSpread);
|
|
State.Create(string.Format("{0}({1}) : Water level measurement", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(msrVolOp)
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopSimulation; }
|
|
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopSimulation; }
|
|
}
|
|
while (!e.Contains(Event.VolumeDone));
|
|
///
|
|
log.WarnFormat("Volumes = {0}l", volumeBox.Val);
|
|
|
|
|
|
if (compoundTestParams != null)
|
|
{
|
|
if (test.Name.ToLower().Contains("nok")) MakeSimulatedCompound(test, 1, 0, 4.7f, 0.9f);
|
|
else MakeSimulatedCompound(test, 1, 0, 0.7f, 1.0f);
|
|
}
|
|
else
|
|
{
|
|
float errorPctBase = -1.0f;
|
|
if (test.Name.ToLower().Contains("q3")) errorPctBase = -0.5f;
|
|
else if (test.Name.ToLower().Contains("q2")) errorPctBase = 0.5f;
|
|
else if (test.Name.ToLower().Contains("q1")) errorPctBase = -5.1f;
|
|
|
|
MakeSimulated(test, repetitionNr, 0, errorPctBase + repetitionNr * 0.1f);
|
|
}
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Completed));
|
|
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0)));
|
|
allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file
|
|
|
|
//-------------------------------------------------------------------
|
|
Bridge.OnActivity(this, string.Format("{0} Simulation", test.Name));
|
|
//-------------------------------------------------------------------
|
|
|
|
State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.EnterState();
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
stopSimulation:
|
|
|
|
return new List<Event> { retVal };
|
|
}
|
|
}
|
|
}
|