2017-10-16 14:55:10 +00:00
|
|
|
|
///
|
2019-07-04 13:20:10 +00:00
|
|
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
2017-10-16 14:55:10 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.BenchControl;
|
|
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
using TBF.UiBridge;
|
2020-11-05 08:31:43 +00:00
|
|
|
|
using TBF.BenchControl.GenericDevices;
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.TestMethods.SensitivityTest
|
|
|
|
|
|
{
|
|
|
|
|
|
public class SensitivityTestSeq : Sequences.SequenceBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(SensitivityTestSeq));
|
|
|
|
|
|
|
|
|
|
|
|
const int DetectionBufferSize = 9;
|
|
|
|
|
|
const int DetectionKernelSize = 5;
|
|
|
|
|
|
|
2018-02-26 11:18:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Executes the specified test.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="test">The test.</param>
|
|
|
|
|
|
/// <param name="repetitionNr">The repetition nr.</param>
|
2018-10-10 12:03:48 +00:00
|
|
|
|
/// <param name="isLastRepetition">true when this is the last repetition</param>
|
2018-02-26 11:18:04 +00:00
|
|
|
|
/// <param name="testParams">The test parameters.</param>
|
|
|
|
|
|
/// <param name="debugLevel">The debug level.</param>
|
|
|
|
|
|
/// <returns></returns>
|
2018-10-10 12:03:48 +00:00
|
|
|
|
public IList<Event> Execute(Config.Entities.Test test, int repetitionNr, bool isLastRepetition,
|
|
|
|
|
|
TestParams testParams,
|
2017-10-16 14:55:10 +00:00
|
|
|
|
Config.Entities.DebugMode debugLevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (debugLevel == Config.Entities.DebugMode.Simulate)
|
|
|
|
|
|
{
|
2019-07-04 13:20:10 +00:00
|
|
|
|
return new List<Event> { Event.Done }; /// TODO: Test method simulation
|
2017-10-16 14:55:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
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 }; /// or Event.UiCmdStop ???
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-05-02 07:36:33 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
|
|
|
|
|
|
IList<Event> e; /// Events from currently running operations
|
|
|
|
|
|
Event retVal = Event.Done;
|
2019-03-18 08:14:13 +00:00
|
|
|
|
Elde.ControlBoardDev cBrd = StateMachine.ControlBoard;
|
2018-10-10 12:03:48 +00:00
|
|
|
|
checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state
|
2019-07-04 13:20:10 +00:00
|
|
|
|
processDataLoggingOp = new TBF.BenchControl.Operations.ProcessDataLoggingOp(processDataLogger, this, false);
|
2018-10-10 12:03:48 +00:00
|
|
|
|
|
2019-05-02 07:36:33 +00:00
|
|
|
|
|
|
|
|
|
|
int[] filters = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
|
if (sensPath != null && sensPath.RegisterReaders != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
|
|
|
|
{
|
2020-11-05 08:31:43 +00:00
|
|
|
|
IRegReaderPulses eldeRR = rr as IRegReaderPulses;
|
2019-05-02 07:36:33 +00:00
|
|
|
|
if ((eldeRR != null) && (eldeRR.Position >= 1) && (eldeRR.Position <= 8))
|
|
|
|
|
|
{
|
|
|
|
|
|
filters[eldeRR.Position - 1] = eldeRR.Filter;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-10 14:26:58 +00:00
|
|
|
|
cBrd.SetFiltersPidShortPulses(filters, outPath.PidCoef, (test.TolerRed == 0) ? 0 : 1);
|
|
|
|
|
|
|
2019-03-18 08:14:13 +00:00
|
|
|
|
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));
|
|
|
|
|
|
|
2018-10-10 12:03:48 +00:00
|
|
|
|
float switchTimeStart = 0.001f; /// in seconds, original vale is 1 ms
|
|
|
|
|
|
float switchTimeEnd = 0.001f; /// in seconds, original vale is 1 ms
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
|
|
|
|
|
|
/// This is to calculate increments of WM pulses
|
2018-10-10 12:03:48 +00:00
|
|
|
|
int[] lastWMPulses = new int[Config.Data.WMsCount];
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
State.Create(string.Format("{0}({1}) : stopTest diverter gate etc", test.Method, test.Name))
|
2019-03-18 08:14:13 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperations(readTempPressOps)
|
|
|
|
|
|
.AddOperation(cBrd.StopPreviousOp())
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do {
|
2017-10-16 14:55:10 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (TestAndLogUiCmdStop(test,e)) goto stopTest;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.PreviousStopped));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2019-07-04 13:20:10 +00:00
|
|
|
|
|
2017-10-16 14:55:10 +00:00
|
|
|
|
/// Meters path is required for the following:
|
|
|
|
|
|
readRegistersOp = new Operations.ReadMoreRegistersOp(sensPath.RegisterReaders);
|
|
|
|
|
|
|
|
|
|
|
|
//====================================
|
|
|
|
|
|
loop:
|
2019-07-04 13:20:10 +00:00
|
|
|
|
/// 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
|
2019-03-18 08:14:13 +00:00
|
|
|
|
Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, heatMetersPath, totalPulses));
|
2017-10-16 14:55:10 +00:00
|
|
|
|
string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr);
|
|
|
|
|
|
TestStartTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
Qrise = 0;
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Prepare cameras, ROI-s and measurementOperations
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
|
|
/// Find ROI-s
|
2020-11-05 08:31:43 +00:00
|
|
|
|
IList<GenericDevices.IRegReaderLiveCamera> rois = new List<GenericDevices.IRegReaderLiveCamera>();
|
2017-10-16 14:55:10 +00:00
|
|
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
|
|
|
|
{
|
2020-11-05 08:31:43 +00:00
|
|
|
|
GenericDevices.IRegReaderLiveCamera cameraRoI = rr as GenericDevices.IRegReaderLiveCamera;
|
2019-05-02 07:36:33 +00:00
|
|
|
|
if ((cameraRoI != null) && cameraRoI.Detected)
|
2018-08-23 09:39:11 +00:00
|
|
|
|
{
|
2019-05-02 07:36:33 +00:00
|
|
|
|
rois.Add(cameraRoI);
|
2018-08-23 09:39:11 +00:00
|
|
|
|
}
|
2019-05-02 07:36:33 +00:00
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
/// 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.ClearRoiParams();
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-10 12:03:48 +00:00
|
|
|
|
int flowDetectTime0 = StateMachine.Time;
|
|
|
|
|
|
int flowDetectTime = 0;
|
|
|
|
|
|
float estFlowSetTime = 100.0f;
|
|
|
|
|
|
|
2017-10-16 14:55:10 +00:00
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Switching_flow_detection);
|
|
|
|
|
|
//------------------------------------------------
|
2019-07-04 13:20:10 +00:00
|
|
|
|
State.Create(string.Format("{0}({1}) : Start the pump", test.Method, test.Name))
|
2019-03-18 08:14:13 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperations(readTempPressOps)
|
|
|
|
|
|
.AddOperations(measureOperations)
|
|
|
|
|
|
.AddOperation((inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOnOp(test.PumpPower) : null)
|
|
|
|
|
|
.AddOperation(cBrd.SetValvesOp(inPath.Pump, null))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do {
|
2017-10-16 14:55:10 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.SwitchingFlowDetection));
|
|
|
|
|
|
|
|
|
|
|
|
if (TestAndLogUiCmdStop(test,e)) goto stopTest;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
|
|
|
|
|
|
State.Create(string.Format("{0}({1}) : Set the initial flow", test.Method, test.Name))
|
2019-03-18 08:14:13 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperations(readTempPressOps)
|
|
|
|
|
|
.AddOperations(measureOperations)
|
2019-05-10 14:26:58 +00:00
|
|
|
|
.AddOperation(outPath.RegulValve.SetFlowAndMeasureOp(outPath.FlowMeter, test.Qfrom, test.Qto, RefFlow, FlowSettingTimeoutSec, (float)test.TolerRed))
|
2019-03-18 08:14:13 +00:00
|
|
|
|
.EnterState();
|
|
|
|
|
|
do {
|
2017-10-16 14:55:10 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.SwitchingFlowDetection));
|
|
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
2017-10-16 14:55:10 +00:00
|
|
|
|
if (e.Contains(Event.RegulValveTimeOut))
|
|
|
|
|
|
{
|
2018-06-05 09:16:13 +00:00
|
|
|
|
Bridge.OnError(this, Strings.Flow_adjustment_failed);
|
2019-07-04 13:20:10 +00:00
|
|
|
|
retVal = Event.RecoverableError;
|
|
|
|
|
|
goto stopTest;
|
2017-10-16 14:55:10 +00:00
|
|
|
|
}
|
2018-10-10 12:03:48 +00:00
|
|
|
|
if (e.Contains(Event.Next)) goto init_flow_set;
|
|
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
while (!e.Contains(Event.FlowReached));
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
switch (ReadRegistersTempPressAmbient(measureOperations, false))
|
|
|
|
|
|
{
|
2019-07-04 13:20:10 +00:00
|
|
|
|
case Event.Error: { retVal = Event.Error; goto stopTest; }
|
|
|
|
|
|
case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; }
|
2017-10-16 14:55:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-10 12:03:48 +00:00
|
|
|
|
|
|
|
|
|
|
init_flow_set:
|
|
|
|
|
|
|
|
|
|
|
|
//====================================
|
|
|
|
|
|
// Find the switching flow
|
|
|
|
|
|
//====================================
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
int flowSetTime0 = StateMachine.Time;
|
|
|
|
|
|
|
|
|
|
|
|
/// Allocate detection buffers
|
|
|
|
|
|
double[] flowsForDetection = new double[DetectionBufferSize];
|
2019-07-04 13:20:10 +00:00
|
|
|
|
double[,] pulseFreqsForDetection = new double[Config.Data.WMsCount, DetectionBufferSize];
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
/// Current values
|
|
|
|
|
|
flowsForDetection[0] = RefFlow.Val;
|
2019-07-04 13:20:10 +00:00
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++) pulseFreqsForDetection[i, 0] = 0;
|
2017-10-16 14:55:10 +00:00
|
|
|
|
int startTime = StateMachine.Time;
|
|
|
|
|
|
int lastTime = StateMachine.Time;
|
|
|
|
|
|
|
|
|
|
|
|
/// Detection parameters
|
|
|
|
|
|
float rvPulse = (testParams.TargetQ > (test.Qfrom + test.Qto) / 2.0f) ? 0.05f : -0.05f; // rise or fall?
|
|
|
|
|
|
rvPulse *= (100.0f * testParams.RateOfChange);
|
2019-07-04 13:20:10 +00:00
|
|
|
|
|
|
|
|
|
|
bool[] detected = new bool[Config.Data.WMsCount];
|
|
|
|
|
|
double[] detectedFlow = new double[Config.Data.WMsCount];
|
|
|
|
|
|
for (int i = 0; i < detectedFlow.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
detected[i] = false;
|
|
|
|
|
|
detectedFlow[i] = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
bool allDetected = false;
|
2017-10-16 14:55:10 +00:00
|
|
|
|
bool targetReached = false;
|
|
|
|
|
|
|
|
|
|
|
|
int detectionStartTime = StateMachine.Time;
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.SwitchingFlowDetection));
|
|
|
|
|
|
|
|
|
|
|
|
do
|
2019-07-04 13:20:10 +00:00
|
|
|
|
{
|
|
|
|
|
|
//--------------------------------
|
2017-10-16 14:55:10 +00:00
|
|
|
|
State.Create(string.Format("{0}({1}) : Changing the RV position", test.Method, test.Name))
|
2019-07-04 13:20:10 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
2019-03-18 08:14:13 +00:00
|
|
|
|
.AddOperations(readTempPressOps)
|
|
|
|
|
|
.AddOperations(measureOperations)
|
|
|
|
|
|
.AddOperation(outPath.RegulValve.ChangeRegulValvePositionOp(rvPulse))
|
2019-07-04 13:20:10 +00:00
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.SwitchingFlowDetection));
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
if (TestAndLogUiCmdStop(test, e)) goto stopTest;
|
|
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
while (!e.Contains(Event.PositionReached));
|
|
|
|
|
|
|
|
|
|
|
|
{
|
2019-07-04 13:20:10 +00:00
|
|
|
|
/// Last pulses are kept to calculate differences
|
|
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (RegisterReaders[i] != null) lastWMPulses[i] = RegisterReaders[i].WMPulses;
|
|
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
/// Shift data in the detection buffers
|
|
|
|
|
|
for (int j = DetectionBufferSize - 2; j >= 0; j--)
|
|
|
|
|
|
{
|
|
|
|
|
|
flowsForDetection[j + 1] = flowsForDetection[j];
|
|
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++) pulseFreqsForDetection[i, j+1] = pulseFreqsForDetection[i, j];
|
|
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
switch (ReadRegistersTempPressAmbient(measureOperations, false))
|
|
|
|
|
|
{
|
|
|
|
|
|
case Event.Error: { retVal = Event.Error; goto stopTest; }
|
|
|
|
|
|
case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; }
|
|
|
|
|
|
}
|
2019-01-14 13:32:26 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
/// TODO: !!! The following can only be done for compound meters
|
|
|
|
|
|
flowsForDetection[0] = cBrd.ReferenceFreq * outPath.FlowMeter.NominalFlow / 2000.0f;
|
|
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
double diff = (RegisterReaders[i] != null) ? (RegisterReaders[i].WMPulses - lastWMPulses[i]) : 0;
|
|
|
|
|
|
pulseFreqsForDetection[i, 0] = diff / (double)(StateMachine.Time - lastTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
lastTime = StateMachine.Time;
|
|
|
|
|
|
}
|
2019-01-14 13:32:26 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
if (StateMachine.Time - detectionStartTime > 15)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((flowsForDetection[0] > 0) && (flowsForDetection[DetectionBufferSize - 1] > 0))
|
|
|
|
|
|
{
|
|
|
|
|
|
double[] flowBefore = new double[DetectionKernelSize];
|
|
|
|
|
|
double[] flowAfter = new double[DetectionKernelSize];
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < DetectionKernelSize; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
flowBefore[j] = flowsForDetection[DetectionBufferSize - DetectionKernelSize + j];
|
|
|
|
|
|
flowAfter[j] = flowsForDetection[j];
|
|
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
Array.Sort(flowBefore);
|
|
|
|
|
|
Array.Sort(flowAfter);
|
|
|
|
|
|
flowBefore[0] = 0;
|
|
|
|
|
|
flowAfter[0] = 0;
|
|
|
|
|
|
flowBefore[DetectionKernelSize - 1] = 0;
|
|
|
|
|
|
flowAfter[DetectionKernelSize - 1] = 0;
|
|
|
|
|
|
///
|
|
|
|
|
|
double aveFlowBefore = 0;
|
|
|
|
|
|
double aveFlowAfter = 0;
|
|
|
|
|
|
foreach (var f in flowBefore) aveFlowBefore += f;
|
|
|
|
|
|
foreach (var f in flowAfter) aveFlowAfter += f;
|
|
|
|
|
|
aveFlowBefore /= (double)(DetectionKernelSize - 2);
|
|
|
|
|
|
aveFlowAfter /= (double)(DetectionKernelSize - 2);
|
|
|
|
|
|
|
2020-03-05 12:59:43 +00:00
|
|
|
|
//UiBridge.Bridge.OnEvent(this, string.Format("Time={0}: Flow{1}, aveFlowB={2}, aveFlowA={3}\r\n",
|
|
|
|
|
|
// StateMachine.Time - startTime,
|
|
|
|
|
|
// flowsForDetection[0].ToString("F2"),
|
|
|
|
|
|
// aveFlowBefore.ToString("F2"),
|
|
|
|
|
|
// aveFlowAfter.ToString("F2")));
|
2019-07-04 13:20:10 +00:00
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++)
|
|
|
|
|
|
{
|
2020-01-31 14:45:30 +00:00
|
|
|
|
if ((BatchRslts.Batch.WaterMeters[i] != null) && !BatchRslts.Batch.WaterMeters[i].Disabled && (RegisterReaders[i] != null) && !detected[i])
|
2019-07-04 13:20:10 +00:00
|
|
|
|
{
|
|
|
|
|
|
double[] freqBefore = new double[DetectionKernelSize];
|
|
|
|
|
|
double[] freqAfter = new double[DetectionKernelSize];
|
|
|
|
|
|
for (int j = 0; j < DetectionKernelSize; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
freqBefore[j] = pulseFreqsForDetection[i, DetectionBufferSize - DetectionKernelSize + j];
|
|
|
|
|
|
freqAfter[j] = pulseFreqsForDetection[i, j];
|
|
|
|
|
|
}
|
|
|
|
|
|
/// Do NOT skip the smallest and the largest flow
|
|
|
|
|
|
//Array.Sort(freqBefore);
|
|
|
|
|
|
//Array.Sort(freqAfter);
|
|
|
|
|
|
//freqBefore[0] = 0;
|
|
|
|
|
|
//freqAfter[0] = 0;
|
|
|
|
|
|
//freqBefore[DetectionKernelSize - 1] = 0;
|
|
|
|
|
|
//freqAfter[DetectionKernelSize - 1] = 0;
|
|
|
|
|
|
///
|
|
|
|
|
|
double aveFreqBefore = 0;
|
|
|
|
|
|
double aveFreqAfter = 0;
|
|
|
|
|
|
foreach (var f in freqBefore) aveFreqBefore += f;
|
|
|
|
|
|
foreach (var f in freqAfter) aveFreqAfter += f;
|
|
|
|
|
|
aveFreqBefore /= (double)(DetectionKernelSize);
|
|
|
|
|
|
aveFreqAfter /= (double)(DetectionKernelSize);
|
|
|
|
|
|
|
2020-03-05 12:59:43 +00:00
|
|
|
|
//UiBridge.Bridge.OnEvent(this, string.Format(" WM{0}: pulseFreq={1}, aveFreqB={2}, aveFreqA={3}\r\n",
|
|
|
|
|
|
// BatchRslts.Batch.WaterMeters[i].WMPosition,
|
|
|
|
|
|
// pulseFreqsForDetection[i, 0].ToString("F2"),
|
|
|
|
|
|
// aveFreqBefore.ToString("F2"),
|
|
|
|
|
|
// aveFreqAfter.ToString("F2")));
|
2019-07-04 13:20:10 +00:00
|
|
|
|
|
|
|
|
|
|
//detectedFlow[i] = (aveFlowBefore + aveFlowAfter) / 2;
|
|
|
|
|
|
detectedFlow[i] = aveFlowBefore;
|
|
|
|
|
|
|
|
|
|
|
|
if (rvPulse > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// rise
|
|
|
|
|
|
detected[i] = (aveFreqAfter < aveFreqBefore * (1 - testParams.DetectionThreshold));
|
|
|
|
|
|
targetReached = ((aveFlowAfter + aveFlowBefore) / 2) > testParams.TargetQ;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/// fall
|
|
|
|
|
|
detected[i] = (aveFreqAfter > aveFreqBefore * (1 + testParams.DetectionThreshold));
|
|
|
|
|
|
targetReached = ((aveFlowAfter + aveFlowBefore) / 2) < testParams.TargetQ;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
allDetected = true;
|
|
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++)
|
|
|
|
|
|
{
|
2020-01-31 14:45:30 +00:00
|
|
|
|
if ((BatchRslts.Batch.WaterMeters[i] != null) && !BatchRslts.Batch.WaterMeters[i].Disabled && (RegisterReaders[i] != null) && !detected[i]) allDetected = false;
|
2019-07-04 13:20:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!allDetected && !targetReached);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Config.Data.WMsCount; i++)
|
|
|
|
|
|
{
|
2020-03-05 12:59:43 +00:00
|
|
|
|
//UiBridge.Bridge.OnEvent(this, string.Format("detected flow[{0}]={1}\r\n", i+1, detectedFlow[i].ToString("F4")));
|
2019-07-04 13:20:10 +00:00
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
int flowSetTime1 = StateMachine.Time;
|
|
|
|
|
|
|
|
|
|
|
|
Bridge.OnProcessData(this, new ProcessDataEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting));
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting));
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
//State.Create(string.Format("{0}({1}) : Flow sensitivity detected", test.Method, test.Name))
|
|
|
|
|
|
|
|
|
|
|
|
TestEndTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Test_completed);
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
State.Create(string.Format("{0}({1}) : {2}", test.Method, test.Name, Strings.Stop_the_pump))
|
2019-03-18 08:14:13 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperations(readTempPressOps)
|
|
|
|
|
|
.AddOperation((inPath != null && inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOffOp() : null)
|
|
|
|
|
|
.AddOperation(cBrd.SetValvesOp(null, inPath.Pump))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do {
|
2017-10-16 14:55:10 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (TestAndLogUiCmdStop(test,e)) goto stopTest;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
State.Create(string.Format("{0}({1}) : Stopping diverter, gate, etc.", test.Method, test.Name))
|
2018-10-10 12:03:48 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
2019-03-18 08:14:13 +00:00
|
|
|
|
.AddOperations(readTempPressOps)
|
|
|
|
|
|
.AddOperation(cBrd.StopPreviousOp())
|
2018-10-10 12:03:48 +00:00
|
|
|
|
.EnterState();
|
2019-03-18 08:14:13 +00:00
|
|
|
|
do {
|
2017-10-16 14:55:10 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (TestAndLogUiCmdStop(test,e)) goto stopTest;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.PreviousStopped));
|
|
|
|
|
|
|
|
|
|
|
|
/// 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)
|
2020-01-22 12:51:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
Results.Utils.GetCounterStates(tstRslt, Program.LocalSettings.Counters);
|
2017-10-16 14:55:10 +00:00
|
|
|
|
UpdateTempPressDensAmb(tstRslt);
|
|
|
|
|
|
|
|
|
|
|
|
/// Main results
|
2018-02-26 11:18:04 +00:00
|
|
|
|
tstRslt.MethodClass = TbfComponents.FindComponent(test.Method).ClassName;
|
|
|
|
|
|
tstRslt.StartTime = TestStartTime;
|
2017-10-16 14:55:10 +00:00
|
|
|
|
tstRslt.EndTime = TestEndTime;
|
|
|
|
|
|
tstRslt.FlowSetTime = flowSetTime1 - flowSetTime0;
|
|
|
|
|
|
tstRslt.TestTime = cBrd.TTime; /// [s] measurement time
|
|
|
|
|
|
tstRslt.PulsesMaster = 0; /// Pulses of the master flow meter (test total)
|
|
|
|
|
|
tstRslt.MassStartRaw = 0;
|
|
|
|
|
|
tstRslt.MassStart = 0;
|
|
|
|
|
|
tstRslt.MassEndRaw = 0;
|
|
|
|
|
|
tstRslt.MassEnd = 0;
|
2021-01-29 09:46:21 +00:00
|
|
|
|
tstRslt.MassOfEvapWater = 0;
|
2021-04-04 12:49:35 +00:00
|
|
|
|
tstRslt.FlowMass = 0;
|
|
|
|
|
|
tstRslt.FlowVolume = 0;
|
2017-10-16 14:55:10 +00:00
|
|
|
|
tstRslt.VolumeCTV = 0;
|
|
|
|
|
|
tstRslt.VolumeMaster = 0;
|
2018-04-27 09:00:05 +00:00
|
|
|
|
tstRslt.ConstMasterRaw = 0;
|
|
|
|
|
|
tstRslt.ConstMaster = 0;
|
2017-10-16 14:55:10 +00:00
|
|
|
|
tstRslt.ErrorMaster = 0;
|
|
|
|
|
|
|
2021-04-04 12:49:35 +00:00
|
|
|
|
tstRslt.FlowMean = Convert.ToSingle(RefFlowStat.Average);
|
|
|
|
|
|
tstRslt.FlowStart = Convert.ToSingle(RefFlowStat.First);
|
|
|
|
|
|
tstRslt.FlowEnd = Convert.ToSingle(RefFlowStat.Last);
|
|
|
|
|
|
tstRslt.FlowMin = Convert.ToSingle(RefFlowStat.Min);
|
|
|
|
|
|
tstRslt.FlowMax = Convert.ToSingle(RefFlowStat.Max);
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
tstRslt.DiverterStart = switchTimeStart;
|
|
|
|
|
|
tstRslt.DiverterEnd = switchTimeEnd;
|
2019-12-03 09:32:46 +00:00
|
|
|
|
long infoFlags = 0;
|
|
|
|
|
|
tstRslt.ErrorFlags = (ErrorFlagsComp != null) ? ErrorFlagsComp.GetErrorFlags(tstRslt, true, false, switchTimeStart, switchTimeEnd, out infoFlags) : 0;
|
|
|
|
|
|
tstRslt.InfoFlags = infoFlags;
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Config.Entities.CompoundMeterId.Single);
|
|
|
|
|
|
|
2020-11-05 08:31:43 +00:00
|
|
|
|
GenericDevices.IRegReader regReader = sensPath.RegisterReaders[i];
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
if (meterRslt != null && regReader != null)
|
|
|
|
|
|
{
|
2018-04-10 14:10:44 +00:00
|
|
|
|
meterRslt.RegReaderType = (int)regReader.RegisterReaderType;
|
2018-02-26 11:18:04 +00:00
|
|
|
|
meterRslt.PulsesPerLiter = regReader.PulsesPerLtr;
|
2019-07-04 13:20:10 +00:00
|
|
|
|
meterRslt.Error = detectedFlow[i];
|
|
|
|
|
|
meterRslt.Passed = (tstRslt.TestData.ErrLimLo <= detectedFlow[i]) && (detectedFlow[i] <= tstRslt.TestData.ErrLimHi);
|
2017-10-16 14:55:10 +00:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2020-01-31 14:45:30 +00:00
|
|
|
|
if (BatchRslts.Batch != null && BatchRslts.Batch.WaterMeters != null)
|
2017-10-16 14:55:10 +00:00
|
|
|
|
{
|
2020-01-31 14:45:30 +00:00
|
|
|
|
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
|
2017-10-16 14:55:10 +00:00
|
|
|
|
{
|
2020-01-31 14:45:30 +00:00
|
|
|
|
if (BatchRslts.Batch.WaterMeters[i] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
long wmInfoFlags;
|
|
|
|
|
|
BatchRslts.Batch.WaterMeters[i].ErrorFlags = ErrorFlagsComp.GetWMtrErrorFlags(BatchRslts.Batch.WaterMeters[i].MeterTestRslts, out wmInfoFlags);
|
|
|
|
|
|
BatchRslts.Batch.WaterMeters[i].InfoFlags = wmInfoFlags;
|
|
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 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));
|
|
|
|
|
|
|
|
|
|
|
|
///----------------------///
|
|
|
|
|
|
/// Quit this sequence ///
|
|
|
|
|
|
///----------------------///
|
|
|
|
|
|
|
2018-10-10 12:03:48 +00:00
|
|
|
|
if (isLastRepetition)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Stop the pump
|
|
|
|
|
|
State.Create(string.Format("{0}({1}) : Test(s) completed -> Stopping the pump", test.Method, test.Name))
|
2019-03-18 08:14:13 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(cBrd.SetValvesOp(null, inPath.Pump))
|
|
|
|
|
|
.AddOperation((inPath != null && inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOffOp() : null)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do {
|
2018-10-10 12:03:48 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2019-07-04 13:20:10 +00:00
|
|
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
|
2018-10-10 12:03:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet) || ((inPath.Pump is GenericDevices.IPumpFM) && !e.Contains(Event.TurnPumpOnOffDone)));
|
2017-10-16 14:55:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-18 08:14:13 +00:00
|
|
|
|
return new List<Event> { Event.Done };
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
stopTest:
|
|
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
StopRecordingStatistics(); /// Make sure graph files are closed
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// 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));
|
|
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
stopTestWOStoppingDivGateEtc:
|
2017-10-16 14:55:10 +00:00
|
|
|
|
|
2019-07-04 13:20:10 +00:00
|
|
|
|
return new List<Event> { retVal };
|
2019-03-18 08:14:13 +00:00
|
|
|
|
}
|
2017-10-16 14:55:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|