Masses are stored in double variables everywhere.

This commit is contained in:
Milan Hanajik
2016-10-07 14:06:54 +02:00
parent 9f2e8407a0
commit 4160420844
26 changed files with 104 additions and 111 deletions
@@ -1,6 +1,5 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Author: Milan Hanajik
///
using System;
using log4net;
@@ -17,15 +16,15 @@ namespace TBF.BenchControl.MettlerToledo.Standard
public override string ToString() { return string.Format("ReadStableMassOp(.,{0},.)", totalReadingsCount); }
/// Operation specific
float[] massReadings;
double[] massReadings;
int currentReadingsCount;
/// Set by the constructor
BalanceDev balanceDev;
int totalReadingsCount;
float maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues)
double maxSpread; /// Maximum spread of measurements in kg (otherwise the measurement continues)
bool method; /// false = slow (precise), true = fast (immediate)
FloatBox result;
DoubleBox result;
/// <summary>
/// Events: BalanceDone, Error
@@ -35,7 +34,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// <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 FloatBox result, int readingsCount, float maxSpread, bool method)
public ReadStableMassOp(BalanceDev balanceDev, ref DoubleBox result, int readingsCount, double maxSpread, bool method)
{
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
this.balanceDev = balanceDev;
@@ -63,7 +62,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
public void Start()
{
currentReadingsCount = 0;
massReadings = new float[totalReadingsCount];
massReadings = new double[totalReadingsCount];
if (method)
balanceDev.GetImmediateMassMeasurement();
@@ -92,7 +91,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
#if true /// OLD_WAY_OF_MASS_CALCULATION
/// Exclude min. and max. value, calculate average
Array.Sort(massReadings);
float calcMass = 0;
double calcMass = 0;
for (int i = 1; i < totalReadingsCount - 1; i++)
{
calcMass += massReadings[i];
@@ -102,9 +101,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard
result.Val = calcMass;
return Event.BalanceDone; /// Mass has just been calculated
#else
float minimum = float.MaxValue;
float maximum = float.MinValue;
foreach (float val in massReadings)
double minimum = double.MaxValue;
double maximum = double.MinValue;
foreach (double val in massReadings)
{
if (val < minimum) minimum = val;
if (val > maximum) maximum = val;
@@ -112,7 +111,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
if ((maximum - minimum) <= maxSpread)
{
float calcMass = 0;
double calcMass = 0;
for (int i = 0; i < totalReadingsCount; i++)
{
calcMass += massReadings[i];
@@ -132,7 +131,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
currentReadingsCount--;
}
#endif
}
}
}
if (method)