Prolonged method fixed, ver. 3.1.1603

This commit is contained in:
Milan Hanajik
2021-03-23 08:50:40 +01:00
parent ef96c06328
commit 061ab99486
19 changed files with 165 additions and 272 deletions
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.1.1602.0")]
[assembly: AssemblyFileVersion("3.1.1602.0")]
[assembly: AssemblyVersion("3.1.1603.0")]
[assembly: AssemblyFileVersion("3.1.1603.0")]
+1 -1
View File
@@ -51,7 +51,7 @@ namespace TBF.Rig.Dummy.Balance
return this;
}
public IOperation ReadStableMassOp(ref Boxes.DoubleBox mass, int readingsCount, double maxSpread, Config.Entities.MassMethod method)
public IOperation ReadStableMassOp(ref Boxes.DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread)
{
mass.Val = 0;
return this;
+1
View File
@@ -86,6 +86,7 @@ namespace TBF.Rig
AmbientDone,
BalanceDone,
BalanceOverload,
ScaleTimeout,
PressureDone,
PressureInDone,
PressureOutDone,
+2 -2
View File
@@ -28,14 +28,14 @@ namespace TBF.Rig.GenericDevices
IOperation ReadMassOp(ref DoubleBox mass);
/// <summary>
/// Events: BalanceDone, Error
/// Events: BalanceDone, Timeout, Error
/// </summary>
/// <param name="result">Reference to a variable for the measured mass in kg</param>
/// <param name="readingsCount">Required mass readings count (>= 3)</param>
/// <param name="maxSpread">Maximum spread of measurements in kg (otherwise the measurement continues)</param>
/// <param name="method">Method: false = slow (precise), true = fast (immediate)</param>
/// <returns>ReadMassAverageOp instance reference casted to IOperaton</returns>
IOperation ReadStableMassOp(ref DoubleBox mass, int readingsCount, double maxSpread, Config.Entities.MassMethod method);
IOperation ReadStableMassOp(ref DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread);
/// <summary>
/// Events: Done, Error
+2 -2
View File
@@ -335,9 +335,9 @@ namespace TBF.Rig.MettlerToledo.Multi
/// <param name="maxSpread">Maximum spread of measurements in kg (otherwise the measurement continues)</param>
/// <param name="method">Method: false = slow (precise), true = fast (immediate)</param>
/// <returns>ReadMassAverageOp instance reference casted to IOperaton</returns>
public IOperation ReadStableMassOp(ref DoubleBox mass, int readingsCount, double maxSpread, Config.Entities.MassMethod method)
public IOperation ReadStableMassOp(ref DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread)
{
return new ReadStableMassOp(this, ref mass, readingsCount, maxSpread, method);
return new ReadStableMassOp(this, ref mass, delayBefore, method, readingsCount, maxSpread);
}
/// <summary>
+41 -21
View File
@@ -3,6 +3,7 @@
///
using System;
using log4net;
using Config.Entities;
using TBF.Boxes;
namespace TBF.Rig.MettlerToledo.Multi
@@ -20,32 +21,35 @@ namespace TBF.Rig.MettlerToledo.Multi
int currentReadingsCount;
/// Set by the constructor
BalanceDev balanceDev;
int totalReadingsCount;
double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues)
Config.Entities.MassMethod method; /// false = slow (precise), true = fast (immediate)
DoubleBox result;
readonly BalanceDev scale;
readonly DoubleBox result;
readonly int delayBefore;
readonly MassMethod method; /// false = slow (precise), true = fast (immediate)
readonly int totalReadingsCount;
readonly double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues)
bool started;
int startTime;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="scale">Balance device instance</param>
/// <param name="result">Reference to the measured mass in kg</param>
/// <param name="readingsCount">Required mass readings count (>= 3)</param>
/// <param name="maxSpread">Maximum spread of measurements in kg (otherwise the measurement continues)</param>
/// <param name="method">Method: false = slow (precise), true = fast (immediate)</param>
public ReadStableMassOp(BalanceDev balanceDev, ref DoubleBox result, int readingsCount, double maxSpread, Config.Entities.MassMethod method)
public ReadStableMassOp(BalanceDev scale, ref DoubleBox result, int delayBefore, MassMethod method,
int readingsCount, double maxSpread)
{
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
this.balanceDev = balanceDev;
this.scale = scale;
if (this.scale == null) throw new ArgumentNullException("balanceDev");
this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4
this.maxSpread = (maxSpread == 0) ? (balanceDev.Capacity / 20000.0) : maxSpread;
this.method = method;
this.result = result;
this.result = result;
this.delayBefore = delayBefore;
this.method = method;
this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4
this.maxSpread = (maxSpread == 0) ? (scale.Capacity / 20000.0) : maxSpread;
log.Debug(this.ToString());
}
@@ -54,11 +58,18 @@ namespace TBF.Rig.MettlerToledo.Multi
/// <summary>Start this operation</summary>
public void Start()
{
started = false;
startTime = StateMachine.Time;
currentReadingsCount = 0;
massReadings = new double[totalReadingsCount];
started = BalanceDev.GetImmediateMassMeasurement(balanceDev.IdNr, balanceDev.Name);
}
if (delayBefore == 0)
{
started = BalanceDev.GetImmediateMassMeasurement(scale.IdNr, scale.Name);
}
else
{
started = false;
}
}
/// <summary>Run this operation</summary>
/// <returns>
@@ -68,13 +79,22 @@ namespace TBF.Rig.MettlerToledo.Multi
/// </returns>
public Event Run()
{
if (!started)
{
if (StateMachine.Time >= startTime + delayBefore)
{
started = BalanceDev.GetImmediateMassMeasurement(scale.IdNr, scale.Name);
}
return Event.None;
}
if (currentReadingsCount >= totalReadingsCount) return Event.BalanceDone; /// Mass has already been calculated
if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.None;
if (scale.MsrmntState == MsrmntState.Busy) return Event.None;
if (balanceDev.MsrmntState == MsrmntState.Valid)
if (scale.MsrmntState == MsrmntState.Valid)
{
massReadings[currentReadingsCount++] = balanceDev.Mass;
massReadings[currentReadingsCount++] = scale.Mass;
if (currentReadingsCount == totalReadingsCount)
{
@@ -124,7 +144,7 @@ namespace TBF.Rig.MettlerToledo.Multi
}
}
BalanceDev.GetImmediateMassMeasurement(balanceDev.IdNr, balanceDev.Name);
BalanceDev.GetImmediateMassMeasurement(scale.IdNr, scale.Name);
return Event.None;
}
+2 -2
View File
@@ -579,9 +579,9 @@ namespace TBF.Rig.MettlerToledo.Standard
/// <param name="maxSpread">Maximum spread of measurements in kg (otherwise the measurement continues)</param>
/// <param name="method">Method: false = slow (precise), true = fast (immediate)</param>
/// <returns>ReadMassAverageOp instance reference casted to IOperaton</returns>
public IOperation ReadStableMassOp(ref DoubleBox mass, int readingsCount, double maxSpread, Config.Entities.MassMethod method)
public IOperation ReadStableMassOp(ref DoubleBox mass, int delayBefore, Config.Entities.MassMethod method, int readingsCount, double maxSpread)
{
return new ReadStableMassOp(this, ref mass, readingsCount, maxSpread, method);
return new ReadStableMassOp(this, ref mass, delayBefore, method, readingsCount, maxSpread);
}
/// <summary>
@@ -3,6 +3,7 @@
///
using System;
using log4net;
using Config.Entities;
using TBF.Boxes;
namespace TBF.Rig.MettlerToledo.Standard
@@ -16,17 +17,19 @@ namespace TBF.Rig.MettlerToledo.Standard
public override string ToString() { return string.Format("ReadStableMassOp(.,{0},.)", totalReadingsCount); }
/// Set by the constructor
BalanceDev scale;
int totalReadingsCount;
double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues)
Config.Entities.MassMethod method; /// by the scale, mass spread threshold or mass standard deviation threshold
DoubleBox result;
readonly BalanceDev scale;
readonly DoubleBox result;
readonly int delayBefore;
readonly MassMethod method; /// by the scale, mass spread threshold or mass standard deviation threshold
readonly int totalReadingsCount;
readonly double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues)
/// Operation specific
double[] massReadings;
double[] sortedMassReadings;
int currentReadingsCount;
int startTime;
bool activityStarted;
bool measurementCompleted;
int timeout;
@@ -39,15 +42,17 @@ namespace TBF.Rig.MettlerToledo.Standard
/// <param name="readingsCount">Required mass readings count (>= 4)</param>
/// <param name="maxSpread">Maximum spread of measurements in kg (otherwise the measurement continues)</param>
/// <param name="method">Method: false = slow (precise), true = fast (immediate)</param>
public ReadStableMassOp(BalanceDev scale, ref DoubleBox result, int readingsCount, double maxSpread, Config.Entities.MassMethod method)
public ReadStableMassOp(GenericDevices.IScale scale, ref DoubleBox result, int delayBefore, MassMethod method,
int readingsCount, double maxSpread)
{
if (scale == null) throw new ArgumentNullException("balanceDev");
this.scale = scale;
this.scale = scale as BalanceDev;
if (this.scale == null) throw new ArgumentNullException("balanceDev");
this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4
this.result = result;
this.delayBefore = delayBefore;
this.method = method;
this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4
this.maxSpread = (maxSpread == 0) ? (scale.Capacity / 20000.0) : maxSpread;
this.method = method;
this.result = result;
massReadings = new double[totalReadingsCount];
sortedMassReadings = new double[totalReadingsCount];
@@ -59,6 +64,15 @@ namespace TBF.Rig.MettlerToledo.Standard
log.Debug(this.ToString());
}
/// Internal states of this operation
enum OpState
{
WaitingBeforeMeasurment,
MassMeasurement,
}
OpState opState;
/// <summary>
/// Call scale.XYStartMeasurement() function and set measurementStarted flag.
/// </summary>
@@ -73,18 +87,21 @@ namespace TBF.Rig.MettlerToledo.Standard
/// <summary>Start this operation</summary>
public void Start()
{
startTime = StateMachine.Time;
currentReadingsCount = 0;
measurementCompleted = false;
if (scale.Activity == Activity.Idle)
if (delayBefore == 0 && scale.Activity == Activity.Idle)
{
StartMeasurement();
activityStarted = true;
scale.Activity = Activity.RunningOperation;
opState = OpState.MassMeasurement;
}
else
{
activityStarted = false;
opState = OpState.WaitingBeforeMeasurment;
}
}
@@ -96,16 +113,21 @@ namespace TBF.Rig.MettlerToledo.Standard
/// </returns>
public Event Run()
{
scale.MsrmntTime++;
if (!activityStarted && scale.Activity == Activity.Idle)
if (opState == OpState.WaitingBeforeMeasurment)
{
StartMeasurement();
activityStarted = true;
scale.Activity = Activity.RunningOperation;
if (StateMachine.Time >= startTime + delayBefore && scale.Activity == Activity.Idle)
{
StartMeasurement();
activityStarted = true;
scale.Activity = Activity.RunningOperation;
opState = OpState.MassMeasurement;
}
return Event.None;
}
scale.MsrmntTime++;
if (measurementCompleted)
{
return Event.BalanceDone;
@@ -153,7 +175,7 @@ namespace TBF.Rig.MettlerToledo.Standard
result.Val = (massSum / (totalReadingsCount - 2));
log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", result.Val);
measurementCompleted = true;
measurementCompleted = true;
return Event.BalanceDone; /// Mass has just been calculated
}
}
@@ -172,8 +194,8 @@ namespace TBF.Rig.MettlerToledo.Standard
result.Val = ave;
log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", result.Val);
measurementCompleted = true;
return Event.BalanceDone; /// Mass has just been calculated
measurementCompleted = true;
return Event.BalanceDone; /// Mass has just been calculated
}
}
else
@@ -187,8 +209,8 @@ namespace TBF.Rig.MettlerToledo.Standard
result.Val = (massSum / (totalReadingsCount - 2));
log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", result.Val);
measurementCompleted = true;
return Event.BalanceDone; /// Mass has just been calculated
measurementCompleted = true;
return Event.BalanceDone; /// Mass has just been calculated
}
}
@@ -540,7 +540,7 @@ namespace TBF.Rig.TestMethods.CombinedWithDetection
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(measureOperations)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.EnterState();
do {
@@ -638,7 +638,7 @@ namespace TBF.Rig.TestMethods.CombinedWithDetection
State.Create(string.Format("{0}({1}) : Measuring the mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.EnterState();
do {
@@ -459,7 +459,7 @@ namespace TBF.Rig.TestMethods.DiverterTest
.AddOperation(checkUiOp)
.AddOperations(measureOperations)
.AddOperation(processDataLoggingOp)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperations(readTempPressOps)
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.EnterState();
@@ -664,7 +664,7 @@ namespace TBF.Rig.TestMethods.DiverterTest
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -372,7 +372,7 @@ namespace TBF.Rig.TestMethods.FixedStartAdvanced
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(measureOperations)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -503,7 +503,7 @@ namespace TBF.Rig.TestMethods.FixedStartAdvanced
State.Create("FixedStartAdvanced : Measuring the end mass")
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -272,7 +272,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollAdvanced
State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -649,7 +649,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollAdvanced
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -534,7 +534,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollDeferredEval
State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -817,7 +817,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollDeferredEval
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -510,7 +510,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollection
State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -811,7 +811,7 @@ namespace TBF.Rig.TestMethods.FixedStartMassCollection
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -550,7 +550,7 @@ namespace TBF.Rig.TestMethods.FlyingStartFirstRepetWithMassColl
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(cameraMeasurementOps)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -691,7 +691,7 @@ namespace TBF.Rig.TestMethods.FlyingStartFirstRepetWithMassColl
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -581,7 +581,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(cameraMeasurementOps)
.AddOperation(scale.ReadStableMassOp(ref measuredRefMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -649,7 +649,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(cameraMeasurementOps)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -797,7 +797,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollComparative
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -519,21 +519,6 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged
Bridge.OnActivity(this, Strings.Measuring_the_weight);
//------------------------------------------------
if (test.TimeFlow2Mass > 0)
{
State.Create(string.Format("{0}({1}) : Waiting before 1st mass measurement", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(new Operations.TimerOp(test.TimeFlow2Mass))
.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));
}
LogProcessDataTestInfo(processDataLogger, test.Procedure.Name, test.Name);
if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Start mass");
@@ -543,7 +528,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged
.AddOperation(checkUiOp)
.AddOperations(cameraMeasurementOps)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.TimeFlow2Mass, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -574,31 +559,19 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged
/// Measurement loop preparation
int estimtdEndTime = StateMachine.Time + (int)test.TestTime;
int remainingTime;
StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, 0);
bool isTestPart2Completed = false;
var prolongedTest = cBrd.FlyingStartStopTestOp(test, test.Qfrom, test.Qto, targetTotalPulses, true, true, targetMassPulses);
IList<IOperation> testInProgressOps = new List<IOperation>();
testInProgressOps.Add(checkUiOp);
foreach (var op in readTempPressOps)
testInProgressOps.Add(op);
foreach (var op in cameraMeasurementOps)
testInProgressOps.Add(op);
testInProgressOps.Add(prolongedTest); /// Event.MeasurementCompleted
testInProgressOps.Add(processDataLoggingOp);
IList<IOperation> testCompletedOps = new List<IOperation>();
testCompletedOps.Add(checkUiOp);
foreach (var op in readTempPressOps)
testCompletedOps.Add(op);
testCompletedOps.Add(processDataLoggingOp);
///
/// Measurement loop - 1st part
///
State.Create(string.Format("{0}({1}) : Starting the test", test.Method, test.Name))
.AddOperations(testInProgressOps)
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(cameraMeasurementOps)
.AddOperation(prolongedTest)
.AddOperation(processDataLoggingOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
@@ -607,179 +580,56 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
/// Proceed to 2nd part of the test when diverter turns back to sink, 'Next' button can be used in Debug version
}
/// Proceed to 2nd part of test when diverter turns back to sink, 'Next' button can be used in Debug version
while (!e.Contains(Event.TestPart2InProgress) && !e.Contains(Event.Next));
///
/// Waiting before the 2nd mass measurement
/// 2nd part of the test and simultaneous measurement the end mass
///
bool waitingBeforeEndMassMeasurementCompleted = false;
IOperation stop2MassTimerOp = new Operations.TimerOp(test.TimeStop2Mass);
do {
State.Create(string.Format("{0}({1}) : Waiting before the 2nd mass measurement", test.Method, test.Name))
.AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps)
.AddOperation(stop2MassTimerOp)
.EnterState();
if (!isTestPart2Completed)
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true;
waitingBeforeEndMassMeasurementCompleted = (e.Contains(Event.TimerExpired) && e.Contains(Event.BalanceDone));
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
}
while (!isTestPart2Completed && !waitingBeforeEndMassMeasurementCompleted);
}
else
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
waitingBeforeEndMassMeasurementCompleted = (e.Contains(Event.TimerExpired) && e.Contains(Event.BalanceDone));
}
while (!waitingBeforeEndMassMeasurementCompleted);
}
}
while (!waitingBeforeEndMassMeasurementCompleted);
if (heatMetersPath == null)
LogProcessDataHeader(processDataLogger, "End mass");
else
LogProcessDataHeaderHeatMeters(processDataLogger, "End mass");
///
/// Measuring the end mass
///
Bridge.OnActivity(this, Strings.Measuring_the_weight);
IOperation readStableMassOp = scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod);
IOperation massMsrmntTimerOp = new Operations.TimerOp(StableMassMsrmntTimeoutSec);
bool measuringEndMassCompleted = false;
do
{
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps)
.AddOperation(readStableMassOp)
.AddOperation(massMsrmntTimerOp)
.EnterState();
if (!isTestPart2Completed)
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.TimerExpired))
{
Bridge.OnError(this, Strings.Mass_measurement_timeout);
retVal = Event.RecoverableError;
goto stopTest;
}
if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true;
measuringEndMassCompleted = e.Contains(Event.BalanceDone);
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime, false);
}
while (!isTestPart2Completed && !measuringEndMassCompleted);
}
else
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.TimerExpired))
{
Bridge.OnError(this, Strings.Mass_measurement_timeout);
retVal = Event.RecoverableError;
goto stopTest;
}
measuringEndMassCompleted = e.Contains(Event.BalanceDone);
}
while (!measuringEndMassCompleted);
}
}
while (!measuringEndMassCompleted);
///
tMass2 = StateMachine.Time;
log.WarnFormat("End mass = {0}kg", EndMass);
TestEndTime = DateTime.Now;
if (test.DoDrainingAfter)
{
///
/// Draining after the 2nd mass measurement enabled, empty the tank
///
IOperation setValvesOp = cBrd.SetValvesOp(scale.DrainValve, null);
bool openingDrainValveCompleted = false;
do {
State.Create(string.Format("{0}({1}) : Open the drain valve", test.Method, test.Name))
.AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps)
.AddOperation(setValvesOp)
.EnterState();
if (!isTestPart2Completed)
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true;
openingDrainValveCompleted = !e.Contains(Event.ValvesBusy);
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
}
while (!isTestPart2Completed && !openingDrainValveCompleted);
}
else
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
openingDrainValveCompleted = !e.Contains(Event.ValvesBusy);
}
while (!openingDrainValveCompleted);
}
}
while (!openingDrainValveCompleted);
}
if (!isTestPart2Completed)
{
///
/// Measurement loop - 2nd part, diverter is in state 'To sink'
///
State.Create(string.Format("{0}({1}) : Reading watermeters", test.Method, test.Name))
.AddOperations(testInProgressOps)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
}
while (!e.Contains(Event.TestCompleted) && !e.Contains(Event.Next)); /// Quit the measurement loop when there is Event.MeasurementCompleted
/// 'Next' button can be used in Debug version
}
test_completed:
StopRecordingStatistics();
State.Create(string.Format("{0}({1}) : Stopping flow regulation", test.Method, test.Name))
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(cBrd.StopFlowRegulationOp())
.AddOperations(cameraMeasurementOps)
.AddOperation(prolongedTest)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.TimeStop2Mass, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(processDataLoggingOp)
.EnterState();
do {
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.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; }
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
/// Continue in 2nd part of the test when mass measurement is completed, 'Next' button can be used in Debug version
}
while (!e.Contains(Event.FlowRegulationStopped));
while (!e.Contains(Event.BalanceDone) && !e.Contains(Event.ScaleTimeout) && !e.Contains(Event.Next));
///
/// 2nd part of the test and optional opening of the drain valve
///
State.Create(string.Format("{0}({1}) : 2nd part of the test is running", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(cameraMeasurementOps)
.AddOperation(prolongedTest)
.AddOperation(test.DoDrainingAfter ? cBrd.SetValvesOp(scale.DrainValve, null) : null)
.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; }
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
}
while (!e.Contains(Event.TestCompleted) && !e.Contains(Event.Next));
StopRecordingStatistics();
///
/// (Berlin:) Water is stopped immediately after the test and before the 2nd mass measurement in case:
@@ -539,7 +539,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection
.AddOperation(checkUiOp)
.AddOperations(cameraMeasurementOps)
.AddOperation(processDataLoggingOp)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperations(readTempPressOps)
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.EnterState();
@@ -684,7 +684,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollection
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
+2 -2
View File
@@ -257,7 +257,7 @@ namespace TBF.Rig.TestMethods.LeakTest
State.Create(string.Format("{0}({1}) : Measuring the start mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.EnterState();
do {
@@ -315,7 +315,7 @@ namespace TBF.Rig.TestMethods.LeakTest
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref EndMass, 0, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.EnterState();
do {