ReadStableMassOp uses MassRepeats, MassSpread and MassMethod parameters, ver. 2.12.515
This commit is contained in:
parent
3c4fe34c1d
commit
439d98f99d
@ -33,7 +33,7 @@ namespace Config.Entities
|
||||
public virtual float PumpPower { get; set; } /// Power of the pump in [%] in the range 0 .. 100.0f, use values 0% and 100% for non-FM pumps
|
||||
public virtual int MassRepeats { get; set; } /// Number of mass. measurements at the beginning/end of test, 0 = default (=5)
|
||||
public virtual float MassSpread { get; set; } /// Max spread of mass. measurements at the beginning/end of test, 0 = default
|
||||
public virtual bool MassMethod { get; set; } /// method of mass. measurement at the beginning/end of test: false=slow (precise), true=fast (immediate)
|
||||
public virtual bool MassMethod { get; set; } /// method of mass. measurement at the beginning/end of test: false=slow (precise), true=using immediate mass measurement and evaluation
|
||||
public virtual int TimeBeforeFlow { get; set; } /// Delay time before the start of flow control in [s]
|
||||
public virtual int TimeFlow2Mass { get; set; } /// Delay time from the flow stable to the 1st mass measurement in [s]
|
||||
public virtual int TimePump2StartV { get; set; }/// Delay time from the start of the pump to opening the start valve in [s]
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using log4net;
|
||||
@ -15,16 +15,18 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(ReadStableMassOp));
|
||||
public override string ToString() { return string.Format("ReadStableMassOp(.,{0},.)", totalReadingsCount); }
|
||||
|
||||
/// Operation specific
|
||||
double[] massReadings;
|
||||
int currentReadingsCount;
|
||||
|
||||
/// Set by the constructor
|
||||
BalanceDev balanceDev;
|
||||
int totalReadingsCount;
|
||||
double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues)
|
||||
bool method; /// false = slow (precise), true = fast (immediate)
|
||||
DoubleBox result;
|
||||
DoubleBox result;
|
||||
|
||||
/// Operation specific
|
||||
double[] massReadings;
|
||||
int currentReadingsCount;
|
||||
|
||||
bool measurementCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// Events: BalanceDone, Error
|
||||
@ -39,22 +41,16 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
|
||||
this.balanceDev = balanceDev;
|
||||
|
||||
if (readingsCount == 0)
|
||||
this.totalReadingsCount = 5;
|
||||
else if (readingsCount < 3)
|
||||
this.totalReadingsCount = 3;
|
||||
else
|
||||
this.totalReadingsCount = readingsCount;
|
||||
|
||||
if (maxSpread == 0)
|
||||
this.maxSpread = balanceDev.Capacity / 20000;
|
||||
else
|
||||
this.maxSpread = maxSpread;
|
||||
|
||||
this.method = method;
|
||||
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;
|
||||
|
||||
massReadings = new double[totalReadingsCount];
|
||||
currentReadingsCount = 0;
|
||||
measurementCompleted = false;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
@ -62,7 +58,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
public void Start()
|
||||
{
|
||||
currentReadingsCount = 0;
|
||||
massReadings = new double[totalReadingsCount];
|
||||
measurementCompleted = false;
|
||||
|
||||
if (method)
|
||||
balanceDev.GetImmediateMassMeasurement();
|
||||
@ -78,68 +74,84 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
if (currentReadingsCount >= totalReadingsCount) return Event.BalanceDone; /// Mass has already been calculated
|
||||
|
||||
if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.None;
|
||||
if (measurementCompleted) return Event.BalanceDone;
|
||||
|
||||
if (balanceDev.MsrmntState == MsrmntState.Busy)
|
||||
{
|
||||
return Event.None; /// Wait for a mass measurement
|
||||
}
|
||||
|
||||
if (balanceDev.MsrmntState == MsrmntState.Valid)
|
||||
{
|
||||
massReadings[currentReadingsCount++] = balanceDev.Mass;
|
||||
|
||||
if (currentReadingsCount == totalReadingsCount)
|
||||
/// Save the measurement
|
||||
if (currentReadingsCount < totalReadingsCount)
|
||||
{
|
||||
#if true /// OLD_WAY_OF_MASS_CALCULATION
|
||||
/// Exclude min. and max. value, calculate average
|
||||
Array.Sort(massReadings);
|
||||
double calcMass = 0;
|
||||
for (int i = 1; i < totalReadingsCount - 1; i++)
|
||||
{
|
||||
calcMass += massReadings[i];
|
||||
}
|
||||
calcMass = (calcMass / (totalReadingsCount - 2));
|
||||
log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", calcMass);
|
||||
result.Val = calcMass;
|
||||
return Event.BalanceDone; /// Mass has just been calculated
|
||||
#else
|
||||
double minimum = double.MaxValue;
|
||||
double maximum = double.MinValue;
|
||||
foreach (double val in massReadings)
|
||||
{
|
||||
if (val < minimum) minimum = val;
|
||||
if (val > maximum) maximum = val;
|
||||
}
|
||||
|
||||
if ((maximum - minimum) <= maxSpread)
|
||||
{
|
||||
double calcMass = 0;
|
||||
for (int i = 0; i < totalReadingsCount; i++)
|
||||
{
|
||||
calcMass += massReadings[i];
|
||||
}
|
||||
calcMass = (calcMass / totalReadingsCount);
|
||||
log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", calcMass);
|
||||
result.Val = calcMass;
|
||||
return Event.BalanceDone; /// Mass has just been calculated
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Shift data and decrement 'currentReadingsCount'
|
||||
for (int i = 0; i < totalReadingsCount - 1; i++)
|
||||
{
|
||||
massReadings[i] = massReadings[i + 1];
|
||||
}
|
||||
currentReadingsCount--;
|
||||
}
|
||||
#endif
|
||||
massReadings[currentReadingsCount++] = balanceDev.Mass;
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Shift data in the (already full) buffer, save the mass into the last buffer item
|
||||
for (int i = 1; i < totalReadingsCount; i++)
|
||||
{
|
||||
massReadings[i - 1] = massReadings[i];
|
||||
}
|
||||
massReadings[totalReadingsCount - 1] = balanceDev.Mass;
|
||||
}
|
||||
}
|
||||
|
||||
if (method)
|
||||
balanceDev.GetImmediateMassMeasurement();
|
||||
else
|
||||
balanceDev.GetStableMassMeasurement();
|
||||
|
||||
return Event.None;
|
||||
if (currentReadingsCount >= totalReadingsCount)
|
||||
{
|
||||
#if STABLE_MASS_EXTRAS
|
||||
if (method)
|
||||
{
|
||||
/// Immediate mass measurement, end condition calculated below
|
||||
|
||||
Array.Sort(massReadings);
|
||||
if ((massReadings[totalReadingsCount - 2] - massReadings[1]) <= maxSpread)
|
||||
{
|
||||
double massSum = 0;
|
||||
for (int i = 1; i < totalReadingsCount - 1; i++) massSum += massReadings[i];
|
||||
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
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/// Stable mass measurement
|
||||
|
||||
/// Sort, exclude min. and max. values, calculate the average
|
||||
Array.Sort(massReadings);
|
||||
double massSum = 0;
|
||||
for (int i = 1; i < totalReadingsCount - 1; i++) massSum += massReadings[i];
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (measurementCompleted)
|
||||
{
|
||||
return Event.BalanceDone;
|
||||
}
|
||||
else
|
||||
{
|
||||
///
|
||||
/// Start a new measurement
|
||||
///
|
||||
if (method)
|
||||
balanceDev.GetImmediateMassMeasurement();
|
||||
else
|
||||
balanceDev.GetStableMassMeasurement();
|
||||
|
||||
return Event.None;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Stop this operation</summary>
|
||||
|
||||
@ -942,9 +942,9 @@ namespace TBF
|
||||
///
|
||||
lviParameters.SubItems.Add(test.PumpPower.ToString("F1"));
|
||||
#if STABLE_MASS_EXTRAS
|
||||
lviParameters.SubItems.Add(test.MassRepeats.ToString());
|
||||
lviParameters.SubItems.Add((test.MassRepeats < 4 ? 5 : test.MassRepeats).ToString());
|
||||
lviParameters.SubItems.Add(test.MassSpread.ToString("F4"));
|
||||
lviParameters.SubItems.Add(test.MassMethod ? "fast" : "stable");
|
||||
lviParameters.SubItems.Add(test.MassMethod ? Strings.fast : Strings.stable);
|
||||
#endif
|
||||
lviParameters.SubItems.Add(test.TimePump2StartV.ToString());
|
||||
lviParameters.SubItems.Add(test.TimeBeforeFlow.ToString());
|
||||
@ -1483,6 +1483,25 @@ namespace TBF
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
|
||||
#if STABLE_MASS_EXTRAS
|
||||
if ((e.SubItem == (int)ParametersClmn.MassRepeats) &&
|
||||
(!int.TryParse(e.DisplayText, out itmp) || itmp < 4 || itmp > 100))
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
if ((e.SubItem == (int)ParametersClmn.MassSpread) && !Utils.TryParseUFloat(e.DisplayText, out powerPct))
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
if ((e.SubItem == (int)ParametersClmn.MassMethod) && e.DisplayText != Strings.stable && e.DisplayText != Strings.fast)
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.12.514.1")]
|
||||
[assembly: AssemblyFileVersion("2.12.514.1")]
|
||||
[assembly: AssemblyVersion("2.12.515.1")]
|
||||
[assembly: AssemblyFileVersion("2.12.515.1")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user