Files
tbf/TBF/Rig/TestMethods/StandingStart/StandingStartSeq.cs
T
marekf 267159e0a9 <Fix>: RefPulses carry-over by restoring testInProgress behavior in StandingStart, increase revision to 3.9.3134.113
Cause:
1. Background: there was a suspicion that the Bukoven board left RefPulses active across operations; this was investigated and ruled out. The pulse counter is reset by testInProgress when an operation is reused. During the third DataEntry window testInProgress had been temporarily disabled (SLM vs Karlsruhe difference), which allowed RefPulses to appear to persist.
2. Increase revision to 3.9.3134.113

Solution:
1. Restore/ensure testInProgress behavior during the DataEntry sequence and explicitly reset the pulse counter when starting a new operation.
2. Increased revision to 3.9.3134.113
2026-08-24 12:54:15 +02:00

1173 lines
60 KiB
C#

using Common;
using log4net;
///
/// Copyright (c) 2018-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using TBF.Boxes;
using TBF.Resources;
using TBF.Rig.GenericDevices;
using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication.common;
using TBF.UiBridge;
namespace TBF.Rig.TestMethods.StandingStart
{
public class StandingStartSeq : Sequences.SequenceBase
{
private static readonly ILog log = LogManager.GetLogger(typeof(StandingStartSeq));
/// <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.ControlBoardMain 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 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;
}
/// <summary>
/// Fixed start mass collection method sequence
/// </summary>
/// <param name="test">Test entity</param>
/// <returns>
/// Event.Done . . . . . . . OK
/// Event.MakeSecondPass . . OK, 2nd pass (=evaluation) required
/// 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,
bool compound,
HeatMeters.TestParams heatMetersTestParams,
DebugMode debugLevel)
{
ControlBoard.IControlBoard cBrd = StateMachine.ControlBoardMain;
if ((outPath.FlowMeter is IFlowMeterSingle) &&
(outPath.FlowMeter as IFlowMeterSingle).GetRange(test.TempLimLo, test.TempLimHi) == -1)
{
Bridge.OnError(this, Strings.Flow_meter_temperature_range_does_not_fit_this_test_conditions);
return new List<Event> { Event.ConfigurationError }; /// or Event.UiCmdStop ???
}
IList<Event> e; /// Events from currently running operations
int waterMetersCount = Math.Min(BenchInfo.WaterMetersCount, sensPath.RegisterReaders.Length);
DateTimeBox timeStampStart = new DateTimeBox();
DateTimeBox timeStampEnd = new DateTimeBox();
FloatBox startSwitchTime = new FloatBox();
FloatBox stopSwitchTime = new FloatBox();
checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state
processDataLoggingOp = new TBF.Rig.Operations.ProcessDataLoggingOp(processDataLogger, this, heatMetersTestParams != null);
int delay;
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 (benchPath.ElectricMtrUp != null) readTempPressOps.Add(benchPath.ElectricMtrUp.ReadPressureOp(ref ElectricUp));
if (benchPath.ElectricMtrDown != null) readTempPressOps.Add(benchPath.ElectricMtrDown.ReadPressureOp(ref ElectricDown));
if (benchPath.ElectricMtrDelta != null) readTempPressOps.Add(benchPath.ElectricMtrDelta.ReadPressureOp(ref ElectricDelta));
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));
Event retVal = Event.Done;
int totalPulses = Convert.ToInt32(test.Volume / outPath.FlowMeter.LtrPerPulse);
log.InfoFormat(
"{0}({1}) : Test starting... (Repetition {2}, LastRepetition={3}, PumpPower={4})",
test.Method,
test.Name,
repetitionNr,
isLastRepetition,
test.PumpPower);
///============================================================================================
/// 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));
string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr);
///
/// Optionally display prompt to emerge temperature meters to appropriate baths for heat meters test
///
IOperation heatMetersPromptOp = null;
if (heatMetersTestParams != null && !string.IsNullOrEmpty(heatMetersTestParams.Prompt))
{
/// Make sure the CycleBeginForm is closed
if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest;
heatMetersPromptOp = new Operations.MessageBoxOp(heatMetersTestParams.Prompt);
}
//------------------------------------------------
Bridge.OnActivity(this, Strings.Starting_the_pump);
//------------------------------------------------
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, 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(heatMetersPromptOp)
.AddOperation(inPath.Pump != null ? cBrd.SetValvesOp(inPath.Pump, null) : null)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, 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))
.AddOperation(heatMetersPromptOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, 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(cBrd.SetValvesOp(benchPath.StopBFValve, null))
.AddOperation(heatMetersPromptOp)
.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))
.AddOperation(heatMetersPromptOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
while (!e.Contains(Event.TimerExpired));
}
//------------------------------------------------
Bridge.OnActivity(this, Strings.Setting_the_flow);
//------------------------------------------------
if (inPath.Pump is GenericDevices.IPumpFM)
{
(inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower);
}
///
State.Create(string.Format("{0}({1}) : Pump on", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(StateMachine.ControlBoardMain.SetValvesOp(inPath.Pump, null))
.AddOperation(heatMetersPromptOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
while (e.Contains(Event.ValvesBusy));
///
State.Create(string.Format("{0}({1}) : Start valve open", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(cBrd.OpenStartValveOp())
.AddOperation(heatMetersPromptOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.FlowSetting));
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
while (e.Contains(Event.ValvesBusy));
///
State.Create(string.Format("{0}({1}) : Setting the flow", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(cBrd.SetFlowOp(test.QfromM3ph(), test.QtoM3ph(), RefFlow, FlowSettingTimeoutSec))
.AddOperation(heatMetersPromptOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, 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))
{
break; /// Simulate flow is within range
}
}
while (!e.Contains(Event.FlowReached));
///
/// Flow is withing required range at this point
///
int flowSetTime = StateMachine.Time - flowSetTime0;
if (heatMetersTestParams != null && heatMetersPath != null)
{
//---------------------------------------------------
Bridge.OnActivity(this, Strings.Setting_temperature);
//---------------------------------------------------
int lastTimeSec = StateMachine.Time;
double Tw_last = 0;
double Tc_last = 0;
State.Create(string.Format("{0}({1}) : Checking if the temperature is stable", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(heatMetersPromptOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.Next))
{
break; /// Simulate temperature is within range
}
if (TempRefHi1.Val != 0 && TempRefHi2.Val != 0 && TempRefLo1.Val != 0 && TempRefLo2.Val != 0)
{
if (StateMachine.Time - lastTimeSec > 10 || StateMachine.Time - lastTimeSec < 0)
{
double Tw = (TempRefHi1.Val + TempRefHi2.Val) / 2;
double Tc = (TempRefLo1.Val + TempRefLo2.Val) / 2;
if ((heatMetersTestParams.TempWarmLo <= Tw) && (Tw <= heatMetersTestParams.TempWarmHi) &&
(heatMetersTestParams.TempColdLo <= Tc) && (Tc <= heatMetersTestParams.TempColdHi) &&
(Math.Abs(Tw - Tw_last) <= heatMetersTestParams.ChangeInTimeWarm) &&
(Math.Abs(Tc - Tc_last) <= heatMetersTestParams.ChangeInTimeCold) &&
(Math.Abs(TempRefHi1.Val - TempRefHi2.Val) <= heatMetersTestParams.DeltaTempWarm) &&
(Math.Abs(TempRefLo1.Val - TempRefLo2.Val) <= heatMetersTestParams.DeltaTempCold))
{
break; /// Temperature is within required range
}
lastTimeSec = StateMachine.Time;
Tw_last = Tw;
Tc_last = Tc;
}
}
}
while (true);
}
else if (!string.IsNullOrEmpty(test.TempControl) && 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))
{
break; /// Simulate temperature is within range
}
if (TempUp.Val >= test.TempLimLo && TempUp.Val <= test.TempLimHi &&
TempDown.Val >= test.TempLimLo && TempDown.Val <= test.TempLimHi)
{
break; /// Temperature set withing required range
}
}
while (true);
}
///
/// Temperature is withing required range at this point
///
///
/// reading pump power for dynamic using as default test.PumpPower for next test instances in cycle
///
if (inPath.Pump is IPump)
{
test.PumpPower = (float)(inPath.Pump as IPump).Power;
log.InfoFormat(
"PumpPower initialized from operator to '{0}'%",
test.PumpPower);
}
//-----------------------------------------------------------------
Bridge.OnActivity(this, Strings.Stopping_flow_for_the_fixed_start);
//-----------------------------------------------------------------
State.Create(string.Format("{0}({1}) : Stop flow regulation", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.EnterState();
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
IOperation testInProgress = cBrd.StandingStartStopTestOp(test, 2 * totalPulses, false);
IOperation controlFlowOp = cBrd.SetFlowOp(test.QfromM3ph(), test.QtoM3ph(), RefFlow, int.MaxValue, test.TimeBeforeFlow);
State.Create(string.Format("{0}({1}) : Start the standing start/stop test", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(testInProgress)
.EnterState();
for (int i = 0; i < 3; i++)
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
State.Create(string.Format("{0}({1}) : Close the start/stop valve before test", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(testInProgress)
.AddOperation(cBrd.CloseStartValveOp())
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
while (!e.Contains(Event.ValvesSet));
int time = StateMachine.Time;
double currentFlow = RefFlow.Val;
LogProcessDataTestInfo(processDataLogger, test.Procedure.Name, test.Name);
int startPulses = 0;
///...MF
///-----------------
delay = test.TimeFlow2Mass;
if (delay > 0)
{
State.Create(string.Format("{0}({1}) : Delay for meters stabilization <T flow stab. - start = {2}s> ", test.Method, test.Name, delay))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(testInProgress)
.AddOperation(new Operations.TimerOp(delay)) //...develop: step 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; }
/// Show remaining time
if ((delay = Math.Max(delay, 0)) > 60)
Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", "Delay", delay / 60, "min", delay % 60, Strings.sec));
else
Bridge.OnActivity(this, string.Format("{0} ... {1} s", "Delay", delay));
if (delay > 0)
delay--;
}
while (!e.Contains(Event.TimerExpired));
}
///
/// Enter watermeter begin states here
///
GenericDevices.IHasWMStatesForm dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IHasWMStatesForm;
if (dataEntryCmpnt != null)
{
string fileName = string.Format("{0}-start.bmp", test.Name);
if (dataEntryCmpnt is GenericDevices.IDataEntryForCamera)
{
string[] startImages = new string[sensPath.RegisterReaders.Length];
State state2 = State.Create(string.Format("{0}({1}) : Grabbing images", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(testInProgress);
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
{
GenericDevices.IRegReaderStillCamera roi = sensPath.RegisterReaders[i] as GenericDevices.IRegReaderStillCamera;
if (roi != null)
{
string directory = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
Directory.CreateDirectory(directory);
startImages[i] = Path.Combine(directory, fileName);
state2.AddOperation(roi.GrabImageOp(startImages[i]));
}
else
{
/// Camera simulation
string directory = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
Directory.CreateDirectory(directory);
startImages[i] = Path.Combine(directory, fileName);
}
}
state2.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test));
if (e.Contains(Event.Error)) { retVal = Event.Error; break; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; }
}
while (e.Contains(Event.CameraBusy));
(dataEntryCmpnt as GenericDevices.IDataEntryForCamera).StartImages = startImages;
}
long readStartTime = StateMachine.Time;
Bridge.OnActivity(this, Strings.Enter_water_meter_data);
State.Create(string.Format("{0}({1}) : Entering begin-state", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(testInProgress)
.AddOperation((dataEntryCmpnt as GenericDevices.IHasWMStatesForm).ShowTestStartFormOp(sensPath.RegisterReaders))
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
while (!e.Contains(Event.ModelessFormClosed));
long readEndTime = StateMachine.Time;
var elapsed = TimeSpan.FromTicks((readEndTime - readStartTime));
log.Debug($"Read poseidon Begin operation (with dialog) - took:{elapsed.TotalSeconds} => {elapsed:mm\\:ss}");
if (heatMetersTestParams != null)
{
for (int i = 0; i < Data.HeatMetersCount; i++)
{
Rig.RegisterReaders.StandingStartStop.RegisterReader volumeRegisterReader =
sensPath.RegisterReaders[2 * i] as Rig.RegisterReaders.StandingStartStop.RegisterReader;
Rig.RegisterReaders.StandingStartStop.RegisterReader energyRegisterReader =
sensPath.RegisterReaders[2 * i + 1] as Rig.RegisterReaders.StandingStartStop.RegisterReader;
if (volumeRegisterReader != null) volumeRegisterReader.BeginWMState = dataEntryCmpnt.WMStartState(i);
if (energyRegisterReader != null && dataEntryCmpnt is GenericDevices.IHasHeatMtrStatesForm)
{
energyRegisterReader.BeginWMState = (float)(dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).EnergyStartState(i);
}
}
}
else
{
for (int i = 0; i < waterMetersCount; i++)
{
GenericDevices.IRegReader rr = sensPath.RegisterReaders[i];
if (rr is ICommonRegReader)
(rr as ICommonRegReader).BeginWMState = dataEntryCmpnt.WMStartState(i);
if (rr is Rig.RegisterReaders.StandingStartStop.RegisterReader)
(rr as Rig.RegisterReaders.StandingStartStop.RegisterReader).BeginWMState = dataEntryCmpnt.WMStartState(i);
if (rr is Rig.Network.Camera.RoiForFixedStart.Roi)
(rr as Rig.Network.Camera.RoiForFixedStart.Roi).BeginWMState = dataEntryCmpnt.WMStartState(i);
if (rr is Rig.Network.Camera.RoiForFixedStartKeyence.Roi)
(rr as Rig.Network.Camera.RoiForFixedStartKeyence.Roi).BeginWMState = dataEntryCmpnt.WMStartState(i);
if (rr is Rig.Network.Camera.RoiForFixedStartCJMS11.Roi)
(rr as Rig.Network.Camera.RoiForFixedStartCJMS11.Roi).BeginWMState = dataEntryCmpnt.WMStartState(i);
}
}
if (dataEntryCmpnt is GenericDevices.IDataEntryForCamera && (dataEntryCmpnt as GenericDevices.IDataEntryForCamera).SaveImages)
{
/// SaveImages==true ... copy images to the directory that will be archived at the end of the cycle
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
{
GenericDevices.IRegReaderStillCamera roi = sensPath.RegisterReaders[i] as GenericDevices.IRegReaderStillCamera;
if (roi != null)
{
string srcDir = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
string destDir = Path.Combine(Program.ImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
try
{
if (File.Exists(Path.Combine(srcDir, fileName)))
{
Directory.CreateDirectory(destDir);
string destFName = string.IsNullOrEmpty((dataEntryCmpnt as IDataEntryForCamera).TestStartImgName(i, testName))
? fileName : (dataEntryCmpnt as IDataEntryForCamera).TestStartImgName(i, testName);
File.Copy(Path.Combine(srcDir, fileName), Path.Combine(destDir, destFName), true);
}
}
catch (Exception exc)
{
log.ErrorFormat("Failed to copy image {0} to {1}: {2}", fileName, destDir, exc.Message);
}
}
}
}
}
if (heatMetersPath == null)
LogProcessDataHeader(processDataLogger, "Measurement");
else
LogProcessDataHeaderHeatMeters(processDataLogger, "Measurement");
//------------------------------------------------
Bridge.OnActivity(this, Strings.Test_in_progress);
//------------------------------------------------
/// Measurement loop preparation
TestStartTime = DateTime.Now;
StartTime = (double)StateMachine.Time;
int estimtdEndTime = StateMachine.Time + (int)test.TestTime;
int remainingTime;
StartNewStatistics(outPath.FlowMeter, BatchRslts.Batch.BatchNr, test, repetitionNr, Math.Max((int)(test.TestTime / 10), 5));
int initialPulsesCount = RefPulses;
State.Create(string.Format("{0}({1}) : Starting the test", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(cBrd.OpenStartValveOp(timeStampStart, startSwitchTime))
.AddOperation(testInProgress)
.AddOperation(controlFlowOp)
.AddOperation(processDataLoggingOp)
.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; }
/// Show remaining time
if ((remainingTime = Math.Max(estimtdEndTime - StateMachine.Time, 0)) > 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));
/// Update statistics
RefFrequency.Val = cBrd.RefFrequency;
RefFlow.Val = outPath.FlowMeter.ReadFlow();
UpdateAllStatistics();
#region Heat meters
if (heatMetersTestParams != null)
{
/// Update heatmeter volume and energy values
if (lastEnergyUpdateTime == 0)
{
lastEnergyUpdateTime = StateMachine.Time;
}
else
{
//double deltaTime = (double)(StateMachine.Time - lastEnergyUpdateTime);
double T_in = (TempRefHi1.Val + TempRefHi2.Val) / 2; /// [°C]
double T_out = (TempRefLo1.Val + TempRefLo2.Val) / 2; /// [°C]
double deltaVolume = outPath.FlowMeter.LtrPerPulse * RefPulsesDelta; /// [l]
double deltaEnergy = (0.001 * deltaVolume) * (T_in - T_out) * Formulas.HeatCoefficientWater(16, T_in, T_out, heatMetersTestParams.FlowMeasuredAtHiTempPipe); /// [J] = [m3] * [K] * [J/(m3 K)]
Energy.Update(deltaEnergy);
VolumeForEnergy.Update(deltaVolume);
lastEnergyUpdateTime = StateMachine.Time;
}
}
#endregion
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test));
}
while ((cBrd.DebugLevel==DebugMode.Simulate && !e.Contains(Event.FlowReached)) ||
(cBrd.DebugLevel!=DebugMode.Simulate && cBrd.RefPulses < initialPulsesCount + totalPulses && !e.Contains(Event.TestCompleted) && !e.Contains(Event.Next)));
/// Measurement loop end
log.WarnFormat("Start valve switch time on test start = {0} ms", cBrd.ValveOpenCloseTime);
StopRecordingStatistics();
EndTime = (double)StateMachine.Time;
TestEndTime = DateTime.Now;
State.Create(string.Format("{0}({1}) : Closing the start/stop valve at the end of the standing start/stop test", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
//.AddOperation(testInProgress)
.AddOperation(cBrd.CloseStartValveOp(timeStampEnd, stopSwitchTime))
.AddOperation(processDataLoggingOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
}
while (e.Contains(Event.ValvesBusy));
State.Create(string.Format("{0}({1}) : Stop flow regulation", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.EnterState();
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
log.WarnFormat("Start valve switch time on test end = {0} ms", cBrd.ValveOpenCloseTime);
TestEndTime = DateTime.Now;
int endPulses = cBrd.RefPulses;
double flowMID = 3.6 * outPath.FlowMeter.LtrPerPulse * Convert.ToDouble(endPulses - startPulses) / cBrd.TestTime;
double constMasterCorr = outPath.FlowMeter.LtrPerPulseCorrected(flowMID, Convert.ToSingle(TempDownStat.Average));
double volumeCTV = constMasterCorr * Convert.ToDouble(endPulses - startPulses);
double refEnergy = Energy.Sum * volumeCTV / VolumeForEnergy.Sum; /// [J]=[J]*[l]/[l]
///...MF
///-----------------
delay = test.TimeFlow2Mass;
if (delay > 0)
{
State.Create(string.Format("{0}({1}) : Delay for meters stabilization <T flow stab. - start = {2}s> ", test.Method, test.Name, delay))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(testInProgress)
.AddOperation(new Operations.TimerOp(delay)) //...develop: step 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; }
/// Show remaining time
if ((delay = Math.Max(delay, 0)) > 60)
Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", "Delay", delay / 60, "min", delay % 60, Strings.sec));
else
Bridge.OnActivity(this, string.Format("{0} ... {1} s", "Delay", delay));
if (delay > 0)
delay--;
}
while (!e.Contains(Event.TimerExpired));
}
///
/// Enter watermeter end states here
///
if (dataEntryCmpnt != null)
{
string fileName = string.Format("{0}-end.bmp", test.Name);
if (dataEntryCmpnt is GenericDevices.IDataEntryForCamera)
{
string[] endImages = new string[sensPath.RegisterReaders.Length];
State state2 = State.Create(string.Format("{0}({1}) : Grabbing images", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps);
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
{
GenericDevices.IRegReaderStillCamera roi = sensPath.RegisterReaders[i] as GenericDevices.IRegReaderStillCamera;
if (roi != null)
{
string directory = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
Directory.CreateDirectory(directory);
endImages[i] = Path.Combine(directory, fileName);
state2.AddOperation(roi.GrabImageOp(endImages[i]));
}
else
{
/// Camera simulation
string directory = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
Directory.CreateDirectory(directory);
endImages[i] = Path.Combine(directory, fileName);
}
}
state2.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.Test));
if (e.Contains(Event.Error)) { retVal = Event.Error; break; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; }
}
while (e.Contains(Event.CameraBusy));
(dataEntryCmpnt as GenericDevices.IDataEntryForCamera).EndImages = endImages;
}
long readStartTime = DateTime.Now.Ticks;
Bridge.OnActivity(this, Strings.Enter_water_meter_data);
State state = State.Create(string.Format("{0}({1}) : Entering the end-state", test.Method, test.Name));
if (heatMetersTestParams != null && dataEntryCmpnt is GenericDevices.IHasHeatMtrStatesForm)
{
state.AddOperation((dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).
ShowTestEndFormOp(sensPath.RegisterReaders,
volumeCTV, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty,
refEnergy, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty));
}
else
{
state.AddOperation(dataEntryCmpnt.ShowTestEndFormOp(sensPath.RegisterReaders,
volumeCTV, test.ErrLimLo + test.Uncertainty, test.ErrLimHi - test.Uncertainty));
}
state.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
while (!e.Contains(Event.ModelessFormClosed));
long readEndTime = DateTime.Now.Ticks;
var elapsed = TimeSpan.FromTicks((readEndTime - readStartTime));
log.Debug($"Read poseidon End operation (with dialog) - took:{elapsed.TotalSeconds} => {elapsed:mm\\:ss}");
if (heatMetersTestParams != null)
{
for (int i = 0; i < Data.HeatMetersCount; i++)
{
Rig.RegisterReaders.StandingStartStop.RegisterReader volumeRegisterReader =
sensPath.RegisterReaders[2 * i] as Rig.RegisterReaders.StandingStartStop.RegisterReader;
Rig.RegisterReaders.StandingStartStop.RegisterReader energyRegisterReader =
sensPath.RegisterReaders[2 * i + 1] as Rig.RegisterReaders.StandingStartStop.RegisterReader;
if (volumeRegisterReader != null) volumeRegisterReader.EndWMState = dataEntryCmpnt.WMEndState(i);
if (energyRegisterReader != null && dataEntryCmpnt is GenericDevices.IHasHeatMtrStatesForm)
{
energyRegisterReader.EndWMState = (float)(dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).EnergyEndState(i);
}
}
}
else
{
for (int i = 0; i < Data.WMsCount; i++)
{
GenericDevices.IRegReader rr = sensPath.RegisterReaders[i];
if (rr is ICommonRegReader)
(rr as ICommonRegReader).EndWMState = dataEntryCmpnt.WMEndState(i);
if (rr is Rig.RegisterReaders.StandingStartStop.RegisterReader)
(rr as Rig.RegisterReaders.StandingStartStop.RegisterReader).EndWMState = dataEntryCmpnt.WMEndState(i);
if (rr is Rig.Network.Camera.RoiForFixedStart.Roi)
(rr as Rig.Network.Camera.RoiForFixedStart.Roi).EndWMState = dataEntryCmpnt.WMEndState(i);
if (rr is Rig.Network.Camera.RoiForFixedStartKeyence.Roi)
{
(rr as Rig.Network.Camera.RoiForFixedStartKeyence.Roi).EndWMState =
dataEntryCmpnt.WMEndState(i);
log.DebugFormat(" StandingStartMassCollectionSeq.cs - EndWMState [{0}] -> RoiForFixedStartKeyence.Roi",dataEntryCmpnt.WMEndState(i));
}
if(rr is Rig.Network.Camera.RoiForFixedStartCJMS11.Roi)
(rr as Rig.Network.Camera.RoiForFixedStartCJMS11.Roi).EndWMState = dataEntryCmpnt.WMEndState(i);
}
}
if (dataEntryCmpnt is GenericDevices.IDataEntryForCamera && (dataEntryCmpnt as GenericDevices.IDataEntryForCamera).SaveImages)
{
/// SaveImages==true ... copy images to the directory that will be archived at the end of the cycle
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
{
GenericDevices.IRegReaderStillCamera roi = sensPath.RegisterReaders[i] as GenericDevices.IRegReaderStillCamera;
if (roi != null)
{
string srcDir = Path.Combine(Program.TempImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
string destDir = Path.Combine(Program.ImagesDir, BatchRslts.Batch.BatchNr.ToString(), (i + 1).ToString());
try
{
if (File.Exists(Path.Combine(srcDir, fileName)))
{
Directory.CreateDirectory(destDir);
string destFName = string.IsNullOrEmpty((dataEntryCmpnt as IDataEntryForCamera).TestEndImgName(i, testName))
? fileName : (dataEntryCmpnt as IDataEntryForCamera).TestEndImgName(i, testName);
File.Copy(Path.Combine(srcDir, fileName), Path.Combine(destDir, destFName), true);
}
}
catch (Exception exc)
{
log.ErrorFormat("Failed to copy image {0} to {1}: {2}", fileName, destDir, exc.Message);
}
}
}
}
}
//------------------------------------------------
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);
bool stopCycle = false;
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 = Math.Max(1.0, DateTimeBox.DurationSec(timeStampStart, timeStampEnd)); /// Min. 1s to prevent division by zero
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.MassOfEvapWater = 0;
tstRslt.Flow = flowMID; /// [m3/h]
tstRslt.ConstMasterRaw = outPath.FlowMeter.LtrPerPulse; /// Uncorrected master flowmeter coefficient
tstRslt.VolumeMaster = outPath.FlowMeter.LtrPerPulse * tstRslt.PulsesMaster; /// [l] volume from the master flow meter
tstRslt.ConstMasterCorr = constMasterCorr; /// Corrected master pulses per liter
tstRslt.ConstMaster = constMasterCorr; /// Corrected master pulses per liter
tstRslt.VolumeCTV = constMasterCorr * tstRslt.PulsesMaster; /// [l] 1000.0f is because density is in [kg/m3]
tstRslt.ErrorMaster = 0;
/// Flow statistics correction
tstRslt.FlowMean = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Average / tstRslt.ConstMasterRaw);
tstRslt.FlowStart = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.First / tstRslt.ConstMasterRaw);
tstRslt.FlowEnd = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Last / tstRslt.ConstMasterRaw);
tstRslt.FlowMin = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Min / tstRslt.ConstMasterRaw);
tstRslt.FlowMax = Convert.ToSingle(tstRslt.ConstMaster * RefFlowStat.Max / tstRslt.ConstMasterRaw);
tstRslt.DiverterStart = startSwitchTime.Val;
tstRslt.DiverterEnd = stopSwitchTime.Val;
long infoFlags = 0;
tstRslt.ErrorFlags = (ErrorFlagsComp != null) ? ErrorFlagsComp.GetErrorFlags(tstRslt, false, true, startSwitchTime.Val, stopSwitchTime.Val, out infoFlags, out stopCycle) : 0;
tstRslt.InfoFlags = infoFlags;
if (compound)
{
///
/// 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, CompoundMeterId.CompoundMain);
Results.Entities.MeterTestRslt auxMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.CompoundAux);
for (int isAux = 0; isAux <= 1; isAux++) /// 0=main, 1=aux
{
Results.Entities.MeterTestRslt meterRslt = (isAux == 0) ? mainMeterRslt : auxMeterRslt;
GenericDevices.IRegReader regReader = sensPath.RegisterReaders[2 * i + isAux];
if (meterRslt != null && regReader != null)
{
meterRslt.RegReaderType = (int)regReader.RegisterReaderType;
meterRslt.PulsesPerLiter = regReader.PulsesPerLtr;
meterRslt.VolumeStart = regReader.BeginWMState; /// [l]
meterRslt.VolumeEnd = regReader.EndWMState; /// [l]
meterRslt.VolumeMeter = Math.Abs(meterRslt.VolumeEnd - meterRslt.VolumeStart); /// [l]
meterRslt.VolumeRef = tstRslt.VolumeCTV; /// [l]
meterRslt.PulsesMeter = meterRslt.VolumeMeter;
meterRslt.PulsesMaster = tstRslt.PulsesMaster;
meterRslt.TestTime = tstRslt.TestTime;
meterRslt.Error = Formulas.ErrorFromVolumes(meterRslt.VolumeMeter, meterRslt.VolumeRef); /// Not used for evaluation
}
}
Results.Entities.MeterTestRslt compoundMeterRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.Compound);
if (compoundMeterRslt != null && mainMeterRslt != null && auxMeterRslt != null)
{
compoundMeterRslt.VolumeRef = tstRslt.VolumeCTV; /// [l] must be calculated before main & aux. meter error
compoundMeterRslt.VolumeMeter = mainMeterRslt.VolumeMeter + auxMeterRslt.VolumeMeter;
compoundMeterRslt.PulsesMaster = tstRslt.PulsesMaster;
compoundMeterRslt.TestTime = tstRslt.TestTime;
compoundMeterRslt.Error = Formulas.ErrorFromVolumes(compoundMeterRslt.VolumeMeter, compoundMeterRslt.VolumeRef);
compoundMeterRslt.Passed = (compoundMeterRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty)
&& (compoundMeterRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty)
&& (tstRslt.ErrorFlags == 0);
mainMeterRslt.Passed = auxMeterRslt.Passed = compoundMeterRslt.Passed;
mainMeterRslt.TestDone = auxMeterRslt.TestDone = compoundMeterRslt.TestDone = true;
tstRslt.TestDone = true;
}
}
}
else if (heatMetersTestParams != null)
{
///
/// Heat meters
///
tstRslt.RefEnergy = Energy.Sum * tstRslt.VolumeCTV / VolumeForEnergy.Sum; /// [J] = [J] * [l] / [l]
tstRslt.Custom1 = (float)TempRefHiStat.Average;
tstRslt.Custom2 = (float)TempRefHiStat.First;
tstRslt.Custom3 = (float)TempRefHiStat.Last;
tstRslt.Custom4 = (float)TempRefHiStat.Min;
tstRslt.Custom5 = (float)TempRefHiStat.Max;
tstRslt.Custom6 = (float)TempRefLoStat.Average;
tstRslt.Custom7 = (float)TempRefLoStat.First;
tstRslt.Custom8 = (float)TempRefLoStat.Last;
tstRslt.Custom9 = (float)TempRefLoStat.Min;
tstRslt.Custom10 = (float)TempRefLoStat.Max;
for (int i = 0; i < BatchRslts.WMPositionsCount; i++)
{
if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue;
Results.Entities.MeterTestRslt volumeRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.HeatMeterVolume);
Results.Entities.MeterTestRslt energyRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.HeatMeterEnergy);
GenericDevices.IRegReader volumeRegReader =
(sensPath.RegisterReaders.Length > 2 * i) ? sensPath.RegisterReaders[2 * i] : null;
GenericDevices.IRegReader energyRegReader =
(sensPath.RegisterReaders.Length > 2 * i + 1) ? sensPath.RegisterReaders[2 * i + 1] : null;
if (volumeRslt != null && volumeRegReader != null)
{
volumeRslt.PulsesPerLiter = volumeRegReader.PulsesPerLtr;
volumeRslt.VolumeStart = volumeRegReader.BeginWMState;
volumeRslt.VolumeEnd = volumeRegReader.EndWMState;
volumeRslt.VolumeMeter = volumeRslt.VolumeEnd - volumeRslt.VolumeStart;
volumeRslt.VolumeRef = tstRslt.VolumeCTV;
volumeRslt.PulsesMeter = volumeRslt.VolumeMeter;
volumeRslt.PulsesMaster = tstRslt.PulsesMaster; /// <----------------- ???
volumeRslt.TestTime = tstRslt.TestTime;
volumeRslt.Error = Formulas.ErrorFromVolumes(volumeRslt.VolumeMeter, volumeRslt.VolumeRef);
volumeRslt.Passed = !heatMetersTestParams.EvaluateVolume ||
((volumeRslt.Error >= test.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty) &&
(volumeRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty) &&
(tstRslt.ErrorFlags == 0));
volumeRslt.TestDone = true;
tstRslt.TestDone = true;
}
if (energyRslt != null && energyRegReader != null && dataEntryCmpnt is GenericDevices.IHasHeatMtrStatesForm)
{
volumeRslt.PulsesPerLiter = energyRegReader.PulsesPerLtr;
energyRslt.VolumeStart = (dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).EnergyStartState(i);
energyRslt.VolumeEnd = (dataEntryCmpnt as GenericDevices.IHasHeatMtrStatesForm).EnergyEndState(i);
energyRslt.VolumeMeter = energyRslt.VolumeEnd - energyRslt.VolumeStart;
energyRslt.VolumeRef = tstRslt.RefEnergy;
energyRslt.PulsesMeter = energyRslt.VolumeMeter;
energyRslt.PulsesMaster = tstRslt.PulsesMaster; /// <----------------- ???
energyRslt.Error = Formulas.ErrorFromVolumes(energyRslt.VolumeMeter, energyRslt.VolumeRef);
energyRslt.Passed = (energyRslt.Error >= heatMetersTestParams.ErrorLimitLo)
&& (energyRslt.Error <= heatMetersTestParams.ErrorLimitHi)
&& (tstRslt.ErrorFlags == 0);
energyRslt.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;
Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, Common.CompoundMeterId.Single);
GenericDevices.IRegReader regReader = sensPath.RegisterReaders[i];
if (meterRslt != null && regReader != null)
{
meterRslt.RegReaderType = (int)regReader.RegisterReaderType;
meterRslt.PulsesPerLiter = regReader.PulsesPerLtr;
meterRslt.VolumeStart = regReader.BeginWMState;
meterRslt.VolumeEnd = regReader.EndWMState;
meterRslt.VolumeMeter = Math.Abs(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.GetErrLimLo(tstRslt.VolumeCTV, tstRslt.TestTime) + test.Uncertainty)
&& (meterRslt.Error <= test.GetErrLimHi(tstRslt.VolumeCTV, tstRslt.TestTime) - test.Uncertainty)
&& (tstRslt.ErrorFlags == 0);
meterRslt.TestDone = true;
tstRslt.TestDone = true;
if (regReader is ICommonRegReader regReaderCommon)
// if (meterRslt.WaterMeter != null
// && tstRslt is ICommonRegReader tstRsltCommon
// && !string.IsNullOrEmpty(tstRsltCommon.SerialNr))
{
meterRslt.WaterMeter.SerialNr = regReaderCommon.SerialNr;
}
}
}
}
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,
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)
{
if (BatchRslts.Batch != null && BatchRslts.Batch.WaterMeters != 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));
}
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Progress.TransitionAfter));
/// Append the results to the CSV-file
allResults.Info(TestResult2CsvLine(testName, test.Part));
if (stopCycle) retVal = Event.ErrorFlagsStop;
stopTest:
StopRecordingStatistics();
///
/// Quit this sequence
///
if (isLastRepetition || retVal == Event.UiCmdStop
|| retVal == Event.OpArgumentError
|| retVal == Event.RecoverableError
|| retVal == Event.ErrorFlagsStop
|| retVal == Event.Error
|| retVal == Event.ConfigurationError)
{
cBrd.StopAll(false);
}
return new List<Event> { retVal };
}
}
}