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
@@ -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
}
}