MettlerToledo.Standard always reads immediate mass when idle.

This commit is contained in:
Milan Hanajik
2020-11-13 10:23:32 +01:00
parent 54658bdd38
commit 77ad6a529d
18 changed files with 262 additions and 259 deletions
@@ -16,6 +16,13 @@ using TBF.Resources;
namespace TBF.BenchControl.MettlerToledo.Standard
{
public enum Activity
{
Idle,
ImmediateMeasurement,
RunningOperation,
}
/// <summary>
/// Mettler Toledo ICS4_5 Weighting terminal connected via serial interface (RS232)
/// </summary>
@@ -64,7 +71,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// <summary>The state of the mass measurement</summary>
public MsrmntState MsrmntState { get { return msrmntState; } }
public Activity Activity;
public MsrmntState MsrmntState { get { return msrmntState; } set { msrmntState = value; } }
protected MsrmntState msrmntState;
/// <summary>Time since the last serial command in seconds</summary>
@@ -121,6 +129,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
throw new Exception(string.Format("{0}: {1}", Name, Strings.Calibration_certificate_validity_expired));
}
Activity = Activity.Idle;
msrmntState = MsrmntState.Failed; /// Data not valid yet
MsrmntTime = 0;
@@ -178,7 +187,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return (mass >= thld);
}
public void ZeroWhenStable()
public virtual void SendZeroWhenStableCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -188,7 +197,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return;
}
log.InfoFormat("{0} - ZeroWhenStable()", Name);
log.InfoFormat("{0} - SendZeroWhenStableCmd() - \"Z\\r\\n\"", Name);
msrmntState = MsrmntState.Busy;
MsrmntTime = 0;
@@ -196,7 +205,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
serialPort.Write("Z\r\n");
}
public virtual void Taring()
public virtual void SendTaraCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -206,7 +215,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return;
}
log.InfoFormat("{0} - Taring()", Name);
log.InfoFormat("{0} - SendTaraCmd() - - \"T\\r\\n\"", Name);
msrmntState = MsrmntState.Busy;
MsrmntTime = 0;
@@ -217,7 +226,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// <summary>
/// Get a stable mass measurement
/// </summary>
public void GetStableMassMeasurement()
public void SendStableMeasurementCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -227,7 +236,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return;
}
log.InfoFormat("{0} - GetStableMassMeasurement()", Name);
log.InfoFormat("{0} - SendStableMeasurementCmd() - \"S\\r\\n\"", Name);
msrmntState = MsrmntState.Busy;
MsrmntTime = 0;
@@ -238,7 +247,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// <summary>
/// Get an immediate mass measurement
/// </summary>
public void GetImmediateMassMeasurement()
public void SendImmediateMeasurementCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate || serialPort == null) return;
@@ -248,7 +257,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return;
}
log.InfoFormat("{0} - GetImmediateMassMeasurement()", Name);
log.InfoFormat("{0} - SendImmediateMeasurementCmd() - \"SI\\r\\n\"", Name);
msrmntState = MsrmntState.Busy;
MsrmntTime = 0;
@@ -270,7 +279,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Get the serial number
/// </summary>
/// <remarks>After a successful SetUnits(kg) mass is still sent in g. MH 15.10.2013</remarks>
public void SetUnits(Units unit)
public void SendSetUnitsCmd(Units unit)
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -280,17 +289,30 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return;
}
log.InfoFormat("{0} - SetUnits({1})", Name, unit);
msrmntState = MsrmntState.Busy;
stringBuilder.Clear();
switch (unit)
{
case Units.g: serialPort.Write("U g\r\n"); break;
case Units.kg: serialPort.Write("U kg\r\n"); break;
case Units.t: serialPort.Write("U t\r\n"); break;
case Units.lb: serialPort.Write("U lb\r\n"); break;
case Units.oz: serialPort.Write("U oz\r\n"); break;
case Units.g:
log.InfoFormat("{0} - SetUnits({1}) - \"U g\\r\\n\"", Name, unit);
serialPort.Write("U g\r\n");
break;
case Units.kg:
log.InfoFormat("{0} - SetUnits({1}) - \"U kg\\r\\n\"", Name, unit);
serialPort.Write("U kg\r\n");
break;
case Units.t:
log.InfoFormat("{0} - SetUnits({1}) - \"U t\\r\\n\"", Name, unit);
serialPort.Write("U t\r\n");
break;
case Units.lb:
log.InfoFormat("{0} - SetUnits({1}) - \"U lb\\r\\n\"", Name, unit);
serialPort.Write("U lb\r\n");
break;
case Units.oz:
log.InfoFormat("{0} - SetUnits({1}) - \"U oz\\r\\n\"", Name, unit);
serialPort.Write("U oz\r\n");
break;
}
}
@@ -318,6 +340,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard
log.DebugFormat("{0} - RunDeviceBefore()", Name);
if (msrmntState != MsrmntState.Busy) return; /// No measurement in progress
///
if (Activity == Activity.ImmediateMeasurement)
{
Activity = Activity.Idle;
}
string justReceived = serialPort.ReadExisting();
if (justReceived != null && justReceived.Length > 0)
@@ -501,6 +528,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// <summary>Run this device</summary>
public void RunDeviceAfter()
{
if (Activity == Activity.Idle)
{
SendImmediateMeasurementCmd();
Activity = Activity.ImmediateMeasurement;
}
base.RunAfter();
}