MettlerToledo.Standard : Timeout in ReadMassOp and ReadStableMassOp, ver. 2.18.892
This commit is contained in:
@@ -62,6 +62,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
public MsrmntState MsrmntState { get { return msrmntState; } }
|
||||
protected MsrmntState msrmntState;
|
||||
|
||||
/// <summary>Time since the last serial command in seconds</summary>
|
||||
public int MsrmntTime;
|
||||
|
||||
/// <summary>The mass after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
|
||||
public double Mass { get { return mass; } }
|
||||
protected double mass;
|
||||
@@ -105,6 +108,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
base.Initalize();
|
||||
|
||||
msrmntState = MsrmntState.Failed; /// Data not valid yet
|
||||
MsrmntTime = 0;
|
||||
|
||||
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
|
||||
|
||||
@@ -140,6 +144,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
log.InfoFormat("{0} - ZeroWhenStable()", Name);
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
MsrmntTime = 0;
|
||||
stringBuilder.Clear();
|
||||
serialPort.Write("Z\r\n");
|
||||
}
|
||||
@@ -157,6 +162,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
log.InfoFormat("{0} - Taring()", Name);
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
MsrmntTime = 0;
|
||||
stringBuilder.Clear();
|
||||
serialPort.Write("T\r\n");
|
||||
}
|
||||
@@ -177,6 +183,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
log.InfoFormat("{0} - GetStableMassMeasurement()", Name);
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
MsrmntTime = 0;
|
||||
stringBuilder.Clear();
|
||||
serialPort.Write("S\r\n");
|
||||
}
|
||||
@@ -197,6 +204,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
log.InfoFormat("{0} - GetImmediateMassMeasurement()", Name);
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
MsrmntTime = 0;
|
||||
stringBuilder.Clear();
|
||||
serialPort.Write("SI\r\n");
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
|
||||
string received = stringBuilder.ToString();
|
||||
|
||||
/// Eliminate double spaces in the received string
|
||||
while (true)
|
||||
{
|
||||
string tmp = received.Replace(" ", " ");
|
||||
|
||||
@@ -51,6 +51,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
scale.MsrmntTime++;
|
||||
|
||||
if (!started)
|
||||
{
|
||||
scale.GetImmediateMassMeasurement();
|
||||
@@ -58,19 +60,31 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
done = false;
|
||||
return Event.Busy;
|
||||
}
|
||||
else if (started && scale.MsrmntState != MsrmntState.Busy)
|
||||
{
|
||||
if (scale.MsrmntState == MsrmntState.Valid) result.Val = scale.Mass;
|
||||
log.InfoFormat("ReadMassOp.Run() ... state={0}, mass={1} ... returning Event.BalanceDone",
|
||||
scale.MsrmntState, scale.Mass);
|
||||
done = true;
|
||||
started = false;
|
||||
return Event.BalanceDone; /// Mass read OK
|
||||
}
|
||||
else
|
||||
{
|
||||
return Event.Busy;
|
||||
}
|
||||
else if (started && scale.MsrmntState == MsrmntState.Busy)
|
||||
{
|
||||
/// Measurement is in progress
|
||||
|
||||
if (scale.MsrmntTime >= 2)
|
||||
{
|
||||
/// Timeout - no response from the scale within 2 seconds - send command again
|
||||
scale.GetImmediateMassMeasurement();
|
||||
started = true;
|
||||
done = false;
|
||||
}
|
||||
|
||||
return Event.Busy;
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Measurement completed or failed: (started == true) && (scale.MsrmntState != MsrmntState.Busy)
|
||||
|
||||
if (scale.MsrmntState == MsrmntState.Valid) result.Val = scale.Mass;
|
||||
log.InfoFormat("ReadMassOp.Run() ... state={0}, mass={1} ... returning Event.BalanceDone",
|
||||
scale.MsrmntState, scale.Mass);
|
||||
done = true;
|
||||
started = false;
|
||||
return Event.BalanceDone; /// Mass read OK
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Stop this operation</summary>
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
public override string ToString() { return string.Format("ReadStableMassOp(.,{0},.)", totalReadingsCount); }
|
||||
|
||||
/// Set by the constructor
|
||||
BalanceDev balanceDev;
|
||||
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
|
||||
@@ -31,18 +31,18 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
/// <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 (>= 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 balanceDev, ref DoubleBox result, int readingsCount, double maxSpread, Config.Entities.MassMethod method)
|
||||
public ReadStableMassOp(BalanceDev scale, ref DoubleBox result, int readingsCount, double maxSpread, Config.Entities.MassMethod method)
|
||||
{
|
||||
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
|
||||
this.balanceDev = balanceDev;
|
||||
if (scale == null) throw new ArgumentNullException("balanceDev");
|
||||
this.scale = scale;
|
||||
|
||||
this.totalReadingsCount = (readingsCount < 4) ? 5 : readingsCount; /// readingsCount is at least 4
|
||||
this.maxSpread = (maxSpread == 0) ? (balanceDev.Capacity / 20000.0) : maxSpread;
|
||||
this.maxSpread = (maxSpread == 0) ? (scale.Capacity / 20000.0) : maxSpread;
|
||||
this.method = method;
|
||||
|
||||
this.result = result;
|
||||
@@ -61,9 +61,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
measurementCompleted = false;
|
||||
|
||||
if (method == Config.Entities.MassMethod.Scale)
|
||||
balanceDev.GetStableMassMeasurement();
|
||||
scale.GetStableMassMeasurement();
|
||||
else
|
||||
balanceDev.GetImmediateMassMeasurement();
|
||||
scale.GetImmediateMassMeasurement();
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
@@ -74,19 +74,32 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
if (measurementCompleted) return Event.BalanceDone;
|
||||
scale.MsrmntTime++;
|
||||
|
||||
if (balanceDev.MsrmntState == MsrmntState.Busy)
|
||||
if (measurementCompleted) return Event.BalanceDone;
|
||||
|
||||
if (scale.MsrmntState == MsrmntState.Busy)
|
||||
{
|
||||
return Event.None; /// Wait for a mass measurement
|
||||
/// Measurement is in progress - resend command if timeout occurs
|
||||
|
||||
if (method == Config.Entities.MassMethod.Scale)
|
||||
{
|
||||
if (scale.MsrmntTime >= 60) scale.GetStableMassMeasurement();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scale.MsrmntTime >= 2) scale.GetImmediateMassMeasurement();
|
||||
}
|
||||
|
||||
return Event.None; /// Wait for a mass measurement
|
||||
}
|
||||
|
||||
if (balanceDev.MsrmntState == MsrmntState.Valid)
|
||||
if (scale.MsrmntState == MsrmntState.Valid)
|
||||
{
|
||||
/// Save the measurement
|
||||
if (currentReadingsCount < totalReadingsCount)
|
||||
{
|
||||
massReadings[currentReadingsCount++] = balanceDev.Mass;
|
||||
massReadings[currentReadingsCount++] = scale.Mass;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -95,7 +108,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
{
|
||||
massReadings[i - 1] = massReadings[i];
|
||||
}
|
||||
massReadings[totalReadingsCount - 1] = balanceDev.Mass;
|
||||
massReadings[totalReadingsCount - 1] = scale.Mass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,9 +178,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard
|
||||
/// Start a new measurement
|
||||
///
|
||||
if (method == Config.Entities.MassMethod.Scale)
|
||||
balanceDev.GetStableMassMeasurement();
|
||||
scale.GetStableMassMeasurement();
|
||||
else
|
||||
balanceDev.GetImmediateMassMeasurement();
|
||||
scale.GetImmediateMassMeasurement();
|
||||
|
||||
return Event.None;
|
||||
}
|
||||
|
||||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.18.891.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.891.0")]
|
||||
[assembly: AssemblyVersion("2.18.892.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.892.0")]
|
||||
|
||||
Reference in New Issue
Block a user