549 lines
25 KiB
C#
549 lines
25 KiB
C#
///
|
|
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.Rig;
|
|
using TBF.Rig.GenericDevices;
|
|
using TBF.Boxes;
|
|
using TBF.Resources;
|
|
using TBF.UiBridge;
|
|
|
|
namespace TBF.Rig.TestMethods.Adjustment
|
|
{
|
|
public class AdjustmentSeq : Sequences.SequenceBase
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(AdjustmentSeq));
|
|
|
|
/// <summary>
|
|
/// Check capabilities of devces in the output path required for this test method
|
|
/// </summary>
|
|
/// <param name="devices">Devices</param>
|
|
/// <returns>true when capabilities of devices are OK</returns>
|
|
public static bool CheckDeviceCaps(Config.Entities.Test test, OutputPath devices, out string message)
|
|
{
|
|
if (!(StateMachine.ControlBoard is ControlBoard.Uni.UniCB))
|
|
{
|
|
/// Control board does not support this method
|
|
message = string.Format("{0}: {1}", test.Name, Strings.Test_bench_does_not_suport_selected_test_method);
|
|
return false;
|
|
}
|
|
|
|
if (!(devices.FlowMeter is GenericDevices.IFlowMeter))
|
|
{
|
|
/// Flow meter is missing
|
|
message = string.Format("{0}: {1}", test.Name, Strings.Missing_a_flow_meter);
|
|
return false;
|
|
}
|
|
|
|
if (!(devices.RegValve is GenericDevices.IRegValve))
|
|
{
|
|
/// Regulation valve is missing
|
|
message = string.Format("{0}: {1}", test.Name, Strings.Missing_a_regulation_valve);
|
|
return false;
|
|
}
|
|
|
|
message = string.Empty;
|
|
return true;
|
|
}
|
|
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
///
|
|
delegate void ErrorsFormDlgt(AdjustmentSeq myRef, IList<GenericDevices.IWaterMeter> waterMeters);
|
|
///
|
|
void OpenWMErrorsForm(AdjustmentSeq myRef, IList<GenericDevices.IWaterMeter> waterMeters)
|
|
{
|
|
#pragma warning disable 162 /// Disables 'Unreachable code detected' warning
|
|
|
|
if (Config.Data.WMsCount > 24)
|
|
{
|
|
myRef.modelessDlg = new WMErrorsForm48(waterMeters);
|
|
}
|
|
else if (Config.Data.WMsCount > 12)
|
|
{
|
|
myRef.modelessDlg = new WMErrorsForm24(waterMeters);
|
|
}
|
|
else if (Config.Data.WMsCount > 6)
|
|
{
|
|
myRef.modelessDlg = new WMErrorsForm12(waterMeters);
|
|
}
|
|
else
|
|
{
|
|
myRef.modelessDlg = new WMErrorsForm(waterMeters);
|
|
}
|
|
|
|
#pragma warning restore 162 /// Disables 'Unreachable code detected' warning
|
|
|
|
modelessDlg.Show();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adjustment 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(Test test, int repetitionNr, bool isLastRepetition, DebugMode mode)
|
|
{
|
|
float simulatedError = 4.5f; /// %
|
|
|
|
int rangeIx = 0; /// Default range, used for non-Elde flowmeters
|
|
if (outPath.FlowMeter is Uni.FlowMeter.FlowMeter)
|
|
{
|
|
Uni.FlowMeter.FlowMeter eldeFM = outPath.FlowMeter as Uni.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 };
|
|
}
|
|
}
|
|
|
|
|
|
IList<Event> e; /// Events from currently running operations
|
|
Event retVal = Event.Done;
|
|
TBF.Rig.ControlBoard.Uni.UniCB cBrd = StateMachine.ControlBoard as TBF.Rig.ControlBoard.Uni.UniCB;
|
|
checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state
|
|
processDataLoggingOp = new TBF.Rig.Operations.ProcessDataLoggingOp(processDataLogger, this, false);
|
|
|
|
if (cBrd is ControlBoard.Uni.UniCB)
|
|
{
|
|
int[] filters = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
if (sensPath != null && sensPath.RegisterReaders != null)
|
|
{
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
{
|
|
IRegReaderPulses rrPls = rr as IRegReaderPulses;
|
|
if (rrPls != null && rrPls.Position >= 1 && rrPls.Position <= 8)
|
|
{
|
|
filters[rrPls.Position - 1] = rrPls.Filter;
|
|
}
|
|
}
|
|
}
|
|
(cBrd as ControlBoard.Uni.UniCB).SetFiltersPidShortPulses(filters, outPath.PidCoef, test.ShortPulses);
|
|
}
|
|
|
|
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.TempMtrDiv != null) readTempPressOps.Add(outPath.TempMtrDiv.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));
|
|
|
|
LtrPerRefPulse = outPath.FlowMeter.LtrPerPulse; /// [ltr/pulse], nominal flow in [m3/h]
|
|
int flowSetTime = 0;
|
|
|
|
/// Start the test, initialize test results
|
|
Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, heatMetersPath));
|
|
string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr);
|
|
|
|
/// 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));
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting));
|
|
TestStartTime = DateTime.Now;
|
|
int flowSetTime0 = StateMachine.Time;
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Starting_the_pump);
|
|
//------------------------------------------------
|
|
if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower);
|
|
///
|
|
State.Create(string.Format("{0}({1}) : Starting the pump", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.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));
|
|
}
|
|
|
|
//------------------------------------------------
|
|
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(cBrd.SetFlowOp(test.Qfrom, test.Qto, 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:
|
|
|
|
flowSetTime = StateMachine.Time - flowSetTime0;
|
|
|
|
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:
|
|
|
|
/// Show the modeless dialog with error indication
|
|
Program.MainWnd.Invoke(new ErrorsFormDlgt(OpenWMErrorsForm), new object[] { this, WaterMeters });
|
|
|
|
loop:
|
|
int time = StateMachine.Time;
|
|
double currentFlow = RefFlow.Val;
|
|
|
|
|
|
///
|
|
/// Prepare cameras, ROI-s and measurementOperations
|
|
///
|
|
|
|
/// Find ROI-s
|
|
IList<GenericDevices.IRegReaderLiveCamera> rois = new List<GenericDevices.IRegReaderLiveCamera>();
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
{
|
|
GenericDevices.IRegReaderLiveCamera cameraRoI = rr as GenericDevices.IRegReaderLiveCamera;
|
|
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))
|
|
{
|
|
roi.Camera.ClearRoiParams();
|
|
cameras.Add(roi.Camera);
|
|
}
|
|
}
|
|
|
|
/// Register ROI-parameters to cameras
|
|
foreach (var roi in rois) roi.RegisterRoiToCamera();
|
|
|
|
/// Prepare measurementOperations
|
|
IList<IOperation> cameraMeasurementOps = new List<IOperation>();
|
|
foreach (var camera in cameras) cameraMeasurementOps.Add(camera.MeasurementOp());
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Test_in_progress);
|
|
//------------------------------------------------
|
|
if (mode == Config.Entities.DebugMode.Simulate)
|
|
{
|
|
/// TODO: Reimplement
|
|
//tstRslt = MakeSimulated(test, 1, simulatedError);
|
|
simulatedError *= 0.6f;
|
|
|
|
State.Create(string.Format("{0}({1}) : Simulating the test", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperation(new Operations.TimerOp(5))
|
|
.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));
|
|
}
|
|
else
|
|
{
|
|
/// Measurement loop preparation
|
|
int totalPulses = Convert.ToInt32(Math.Round(test.Volume / outPath.FlowMeter.LtrPerPulse));
|
|
StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, 0);
|
|
|
|
/// Measurement loop
|
|
State.Create(string.Format("{0}({1}) : FlyingStartStopTestOp is running", test.Method, test.Name))
|
|
.AddOperation(checkUiOp)
|
|
.AddOperations(readTempPressOps)
|
|
.AddOperations(cameraMeasurementOps)
|
|
.AddOperation(cBrd.FlyingStartStopTestOp(test, test.Qfrom, test.Qto, totalPulses))
|
|
.EnterState();
|
|
do {
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; }
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
|
|
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
|
|
/// Update statistics
|
|
RefFrequency.Val = cBrd.RefFrequency;
|
|
RefFlow.Val = outPath.FlowMeter.ReadFlow();
|
|
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.TestCompleted) && !e.Contains(Event.Next)); /// 'Next' button is enabled in Debug version only
|
|
|
|
/// One test completed
|
|
StopRecordingStatistics();
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Adjustment_in_progress);
|
|
//------------------------------------------------
|
|
|
|
TestEndTime = DateTime.Now;
|
|
|
|
/// Make sure the CycleBeginForm is closed so that water meter data (s/n) can be copied into results
|
|
if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest;
|
|
|
|
///
|
|
/// Populate TestResult data entity with data
|
|
///
|
|
Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(testName, test.Part);
|
|
|
|
if (tstRslt != null)
|
|
{
|
|
Results.Utils.GetCounterStates(tstRslt, Program.LocalSettings.Counters);
|
|
UpdateTempPressDensAmb(tstRslt);
|
|
|
|
/// Main results
|
|
tstRslt.MethodClass = TbfComponents.FindComponent(test.Method).ClassName;
|
|
tstRslt.StartTime = TestStartTime;
|
|
tstRslt.EndTime = TestEndTime;
|
|
tstRslt.FlowSetTime = flowSetTime;
|
|
tstRslt.TestTime = cBrd.TestTime; /// [s] measurement time
|
|
tstRslt.PulsesMaster = Convert.ToDouble(cBrd.RefPulses); /// Pulses of the master flow meter (test total)
|
|
tstRslt.MassStartRaw = 0;
|
|
tstRslt.MassStart = 0;
|
|
tstRslt.MassEndRaw = 0;
|
|
tstRslt.MassEnd = 0;
|
|
tstRslt.FlowMass = 0; /// [kg/h]
|
|
tstRslt.FlowVolume = 3.6 * LtrPerRefPulse * tstRslt.PulsesMaster / tstRslt.TestTime; /// [m3/h]
|
|
tstRslt.Buoyancy = Config.Formulas.Buoyancy();
|
|
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.ConstMasterCorr; /// Corrected master pulses per liter
|
|
tstRslt.VolumeCTV = tstRslt.ConstMaster * tstRslt.PulsesMaster; /// [l] 1000.0f is because density is in [kg/m3]
|
|
tstRslt.ErrorMaster = 0.0f; /// Cannot be determined without the collected water mass measurement
|
|
|
|
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 = 0;
|
|
tstRslt.DiverterEnd = 0;
|
|
long infoFlags = 0;
|
|
tstRslt.ErrorFlags = (ErrorFlagsComp != null) ? ErrorFlagsComp.GetErrorFlags(tstRslt, false, false, 0, 0, out infoFlags) : 0;
|
|
tstRslt.InfoFlags = infoFlags;
|
|
|
|
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
|
|
{
|
|
if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue;
|
|
|
|
Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.Single);
|
|
GenericDevices.IRegReader regReader = sensPath.RegisterReaders[i];
|
|
|
|
if (meterRslt != null && regReader != null)
|
|
{
|
|
meterRslt.RegReaderType = (int)regReader.RegisterReaderType;
|
|
meterRslt.PulsesPerLiter = regReader.PulsesPerLtr;
|
|
meterRslt.PulsesMeter = Convert.ToDouble(regReader.WMPulses);
|
|
meterRslt.PulsesMaster = Convert.ToDouble(regReader.WMRefPulses);
|
|
meterRslt.VolumeStart = 0; /// liter
|
|
meterRslt.VolumeEnd = 0; /// liter
|
|
meterRslt.VolumeMeter = meterRslt.PulsesMeter * regReader.LtrsPerPulse; /// liter
|
|
meterRslt.VolumeRef = meterRslt.PulsesMaster * tstRslt.ConstMaster; /// liter
|
|
meterRslt.TestTime = cBrd.PulsesWM(i + 1);
|
|
meterRslt.Error = Config.Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef);
|
|
meterRslt.Passed = (meterRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty)
|
|
&& (meterRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty);
|
|
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.RegValve != null ? outPath.RegValve.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.Batch.WaterMeters[i] != null && !BatchRslts.Batch.WaterMeters[i].Disabled)
|
|
{
|
|
long wmInfoFlags;
|
|
BatchRslts.Batch.WaterMeters[i].ErrorFlags = ErrorFlagsComp.GetWMtrErrorFlags(BatchRslts.Batch.WaterMeters[i].MeterTestRslts, out wmInfoFlags);
|
|
BatchRslts.Batch.WaterMeters[i].InfoFlags = wmInfoFlags;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Update results
|
|
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(testName, tstRslt));
|
|
}
|
|
/// Add data - end
|
|
}
|
|
|
|
|
|
/// Update modeless dialog error information
|
|
Bridge.OnAdjustmentInProgress(this, new AdjustmentInProgressEventArgs(testName));
|
|
|
|
/// Close the modeless form
|
|
if ((modelessDlg is GenericDevices.IHasCompleted) && !(modelessDlg as GenericDevices.IHasCompleted).Completed)
|
|
{
|
|
goto loop; /// Modeless dilaog not closed, keep looping
|
|
}
|
|
modelessDlg = null; /// Modeless dialog is closed now
|
|
|
|
/// Append the results to the CSV-file
|
|
allResults.Info(TestResult2CsvLine(testName, test.Part));
|
|
|
|
stopTest:
|
|
|
|
/// Close the modeless form
|
|
if ((modelessDlg is GenericDevices.IHasCompleted) && !(modelessDlg as GenericDevices.IHasCompleted).Completed)
|
|
{
|
|
goto loop; /// Modeless dilaog not closed, keep looping
|
|
}
|
|
modelessDlg = null; /// Modeless dialog is closed now
|
|
|
|
///
|
|
/// Quit this sequence
|
|
///
|
|
if (isLastRepetition || retVal == Event.UiCmdStop
|
|
|| retVal == Event.OpArgumentError
|
|
|| retVal == Event.Error
|
|
|| retVal == Event.ConfigurationError)
|
|
{
|
|
cBrd.Stop(false);
|
|
}
|
|
|
|
return new List<Event> { retVal };
|
|
}
|
|
}
|
|
}
|