diff --git a/TBF/BenchControl/MettlerToledo/KeepReadingMassesOp.cs b/TBF/BenchControl/MettlerToledo/KeepReadingMassesOp.cs
deleted file mode 100644
index f81fe8d73..000000000
--- a/TBF/BenchControl/MettlerToledo/KeepReadingMassesOp.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-///
-/// Copyright (c) 2013-2015 Sensus Metering Systems
-///
-using System;
-using log4net;
-
-namespace TBF.BenchControl.MettlerToledo
-{
- public class KeepReadingMassesOp : IOperation
- {
- private static readonly ILog log = LogManager.GetLogger(typeof(KeepReadingMassesOp));
- public override string ToString() { return string.Format("KeepReadingMassesOp()"); }
-
- bool done;
-
- ///
- /// Events: BalanceDone, Error
- ///
- /// Balance device instance
- /// Required mass readings count (>= 3)
- /// Reference to the measured mass in kg
- public KeepReadingMassesOp()
- {
- log.Debug(this.ToString());
- }
-
- /// Start this operation
- public void Start()
- {
- done = false;
-
- for (int i = 0; i < Standard.BalanceDev.BalancesCount; i++)
- {
- Standard.BalanceDev.Balances[i].GetImmediateMassMeasurement();
- }
- }
-
- /// Run this operation
- ///
- /// Event.None
- ///
- public Event Run()
- {
- if (done) return Event.BalanceDone; /// Mass has already been read
-
- for (int i = 0; i < Standard.BalanceDev.BalancesCount; i++)
- {
- if (Standard.BalanceDev.Balances[i].MsrmntState != MsrmntState.Busy)
- {
- Standard.BalanceDev.Balances[i].GetImmediateMassMeasurement();
- }
- }
- return Event.None;
- }
-
- /// Stop this operation
- public void Stop()
- {
- }
- }
-}
diff --git a/TBF/BenchControl/MettlerToledo/ReadMassesOp.cs b/TBF/BenchControl/MettlerToledo/ReadMassesOp.cs
index 3af02322b..13c149b85 100644
--- a/TBF/BenchControl/MettlerToledo/ReadMassesOp.cs
+++ b/TBF/BenchControl/MettlerToledo/ReadMassesOp.cs
@@ -31,7 +31,7 @@ namespace TBF.BenchControl.MettlerToledo
for (int i = 0; i < Standard.BalanceDev.BalancesCount; i++)
{
- Standard.BalanceDev.Balances[i].GetImmediateMassMeasurement();
+ Standard.BalanceDev.Balances[i].SendImmediateMeasurementCmd();
}
}
diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs
index 02889d5b4..ceb08cd0d 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
+/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -15,6 +15,13 @@ using TBF.Resources;
namespace TBF.BenchControl.MettlerToledo.Standard
{
+ public enum Activity
+ {
+ Idle,
+ ImmediateMeasurement,
+ RunningOperation,
+ }
+
///
/// Mettler Toledo ICS4_5 Weighting terminal connected via serial interface (RS232)
///
@@ -62,7 +69,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// The state of the mass measurement
- public MsrmntState MsrmntState { get { return msrmntState; } }
+ public Activity Activity;
+ public MsrmntState MsrmntState { get { return msrmntState; } set { msrmntState = value; } }
protected MsrmntState msrmntState;
/// Time since the last serial command in seconds
@@ -114,6 +122,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;
@@ -171,7 +180,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return (mass >= thld);
}
- public void ZeroWhenStable()
+ public virtual void SendZeroWhenStableCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -181,7 +190,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;
@@ -189,7 +198,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
serialPort.Write("Z\r\n");
}
- public virtual void Taring()
+ public void SendTaraCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -199,7 +208,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;
@@ -210,7 +219,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
///
/// Get a stable mass measurement
///
- public void GetStableMassMeasurement()
+ public void SendStableMeasurementCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -220,7 +229,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;
@@ -231,7 +240,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
///
/// Get an immediate mass measurement
///
- public void GetImmediateMassMeasurement()
+ public void SendImmediateMeasurementCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate || serialPort == null) return;
@@ -241,7 +250,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;
@@ -263,7 +272,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Get the serial number
///
/// After a successful SetUnits(kg) mass is still sent in g. MH 15.10.2013
- public void SetUnits(Units unit)
+ public void SendSetUnitsCmd(Units unit)
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -273,17 +282,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;
}
}
@@ -311,6 +333,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)
@@ -494,6 +521,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Run this device
public void RunDeviceAfter()
{
+ if (Activity == Activity.Idle)
+ {
+ SendImmediateMeasurementCmd();
+ Activity = Activity.ImmediateMeasurement;
+ }
base.RunAfter();
}
diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceNewDev.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceNewDev.cs
index 9ecd0baef..d177eed8f 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/BalanceNewDev.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceNewDev.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2013-2017 Sensus Metering Systems
+/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
///
using System;
using System.Globalization;
@@ -41,7 +41,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
///
/// Get the serial number
///
- public void GetSerialNumber()
+ public void SendGetSerialNumberCmd()
{
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@@ -51,11 +51,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return;
}
- log.WarnFormat("{0} - GetSerialNumber()", Name);
+ log.WarnFormat("{0} - GetSerialNumber() - \"I4\\r\\n\"", Name);
msrmntState = MsrmntState.Busy;
stringBuilder.Clear();
- serialPort.Write(new byte[] { (byte)'I', (byte)'4', (byte)0x0D, (byte)0x0A }, 0, 4);
+ serialPort.Write("I4\r\n");
}
///
@@ -84,6 +84,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard
log.DebugFormat("{0} - RunDevice()", Name);
if (base.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)
diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceOld.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceOld.cs
index 91e9d427a..0126bb30d 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/BalanceOld.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceOld.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2016-2017 Sensus Metering Systems
+/// Copyright (c) 2016-2020 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -27,9 +27,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
private static readonly ILog log = LogManager.GetLogger(typeof(BalanceOld));
public override string ToString() { return string.Format("MettlerToledo.Standard.BalanceOld({0})", Cfg.ToString(1)); }
- public BalanceOld()
- {
- }
+ public BalanceOld() { }
public BalanceOld(Generic.IComponentCfg cfg)
: base(cfg)
@@ -37,25 +35,13 @@ namespace TBF.BenchControl.MettlerToledo.Standard
log.Debug(this.ToString());
}
- public override void Taring()
+
+ public override void SendZeroWhenStableCmd()
{
- if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
-
- if (msrmntState == MsrmntState.Busy)
- {
- log.WarnFormat("{0} - Taring() returns without starting taring the scale because measurementState == MeasurementState.Busy", Name);
- return;
- }
-
- log.InfoFormat("{0} - Taring()", Name);
-
- stringBuilder.Clear();
- serialPort.Write("T\r\n");
-
- mass = 0;
- msrmntState = MsrmntState.Valid;
+ base.SendTaraCmd();
}
+
///
/// Parse characters received from the serial port
///
@@ -78,9 +64,14 @@ namespace TBF.BenchControl.MettlerToledo.Standard
return;
}
- log.DebugFormat("{0} - RunDevice()", Name);
+ log.DebugFormat("{0} - RunDeviceBefore()", Name);
if (base.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)
diff --git a/TBF/BenchControl/MettlerToledo/Standard/GetSerNumOp.cs b/TBF/BenchControl/MettlerToledo/Standard/GetSerNumOp.cs
index 047f8ac26..987b9df3b 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/GetSerNumOp.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/GetSerNumOp.cs
@@ -14,6 +14,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Set by the constructor
BalanceNewDev scale;
string serialNumber;
+ bool activityStarted;
///
/// Events: BalanceDone, Error
@@ -24,7 +25,6 @@ namespace TBF.BenchControl.MettlerToledo.Standard
{
if (scale == null) throw new ArgumentNullException("balanceDev");
this.scale = scale;
-
this.serialNumber = serialNumber;
log.Debug(this.ToString());
@@ -33,9 +33,17 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Start this operation
public void Start()
{
- log.DebugFormat("{0} - Start()", scale.Name);
- scale.GetSerialNumber();
- }
+ if (scale.Activity == Activity.Idle)
+ {
+ scale.SendGetSerialNumberCmd();
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ }
+ else
+ {
+ activityStarted = false;
+ }
+ }
/// Run this operation
///
@@ -44,27 +52,33 @@ namespace TBF.BenchControl.MettlerToledo.Standard
///
public Event Run()
{
- log.DebugFormat("{0} - GetSerNumOp.Run() ... MsrmntState = {1}", scale.Name, scale.MsrmntState);
+ if (!activityStarted && scale.Activity == Activity.Idle)
+ {
+ scale.SendGetSerialNumberCmd();
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ return Event.Busy;
+ }
- if (scale.MsrmntState == MsrmntState.Valid)
+ if (scale.MsrmntState == MsrmntState.Valid)
{
serialNumber = scale.SerialNumber;
- return Event.BalanceDone; /// S/N read successful
+ return Event.BalanceDone; /// S/N read successful
}
- else if (scale.MsrmntState == MsrmntState.Failed)
+
+ if (scale.MsrmntState == MsrmntState.Failed)
{
return Event.Error; /// S/N read failed
}
- else
- {
- return Event.Busy; /// No result yet
- }
+
+ return Event.Busy; /// No result yet
}
/// Stop this operation
public void Stop()
{
- log.DebugFormat("{0} - Stop()", scale.Name);
+ if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
+ scale.Activity = Activity.Idle;
}
}
}
diff --git a/TBF/BenchControl/MettlerToledo/Standard/ReadMassOp.cs b/TBF/BenchControl/MettlerToledo/Standard/ReadMassOp.cs
index d6719f520..e5b3185a9 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/ReadMassOp.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/ReadMassOp.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2013-2017 Sensus Metering Systems
+/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
///
using System;
using log4net;
@@ -12,84 +12,42 @@ namespace TBF.BenchControl.MettlerToledo.Standard
private static readonly ILog log = LogManager.GetLogger(typeof(ReadMassOp));
public override string ToString() { return string.Format("ReadMassOp(.,.)"); }
- bool started;
- bool done;
-
/// Set by the constructor
BalanceDev scale;
DoubleBox result;
///
- /// Events: BalanceDone, Error
+ /// Events: BalanceDone (always)
///
/// Balance device instance
- /// Required mass readings count (>= 3)
/// Reference to the measured mass in kg
public ReadMassOp(BalanceDev scale, ref DoubleBox result)
{
if (scale == null) throw new ArgumentNullException("balanceDev");
this.scale = scale;
-
this.result = result;
-
log.Debug(this.ToString());
}
/// Start this operation
public void Start()
{
- scale.GetImmediateMassMeasurement();
- started = true;
- done = false;
+ result.Val = scale.Mass;
}
/// Run this operation
///
- /// Event.None
/// Event.BalanceDone
- /// Event.Error . . . . . Current.Tick == null
///
public Event Run()
{
- scale.MsrmntTime++;
-
- if (!started)
- {
- scale.GetImmediateMassMeasurement();
- started = true;
- done = false;
- 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
- }
+ result.Val = scale.Mass;
+ return Event.BalanceDone;
}
/// Stop this operation
public void Stop()
{
- }
+ }
}
}
diff --git a/TBF/BenchControl/MettlerToledo/Standard/ReadStableMassOp.cs b/TBF/BenchControl/MettlerToledo/Standard/ReadStableMassOp.cs
index 3383dc38a..1df92b710 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/ReadStableMassOp.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/ReadStableMassOp.cs
@@ -27,7 +27,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard
double[] sortedMassReadings;
int currentReadingsCount;
+ bool activityStarted;
bool measurementCompleted;
+ int timeout;
///
/// Events: BalanceDone, Error
@@ -45,28 +47,46 @@ namespace TBF.BenchControl.MettlerToledo.Standard
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];
currentReadingsCount = 0;
- measurementCompleted = false;
+ activityStarted = false;
+ measurementCompleted = false;
+ timeout = (method == Config.Entities.MassMethod.Scale) ? 60 : 2;
log.Debug(this.ToString());
}
+ ///
+ /// Call scale.XYStartMeasurement() function and set measurementStarted flag.
+ ///
+ void StartMeasurement()
+ {
+ if (method == Config.Entities.MassMethod.Scale)
+ scale.SendStableMeasurementCmd();
+ else
+ scale.SendImmediateMeasurementCmd();
+ }
+
/// Start this operation
public void Start()
{
- currentReadingsCount = 0;
- measurementCompleted = false;
+ currentReadingsCount = 0;
+ measurementCompleted = false;
- if (method == Config.Entities.MassMethod.Scale)
- scale.GetStableMassMeasurement();
+ if (scale.Activity == Activity.Idle)
+ {
+ StartMeasurement();
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ }
else
- scale.GetImmediateMassMeasurement();
- }
+ {
+ activityStarted = false;
+ }
+ }
/// Run this operation
///
@@ -78,21 +98,23 @@ namespace TBF.BenchControl.MettlerToledo.Standard
{
scale.MsrmntTime++;
- if (measurementCompleted) return Event.BalanceDone;
+ if (!activityStarted && scale.Activity == Activity.Idle)
+ {
+ StartMeasurement();
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ return Event.None;
+ }
+
+ if (measurementCompleted)
+ {
+ return Event.BalanceDone;
+ }
if (scale.MsrmntState == MsrmntState.Busy)
{
- /// 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();
- }
-
+ /// Measurement is in progress - resend command if timeout occurs
+ if (scale.MsrmntTime >= timeout) StartMeasurement();
return Event.None; /// Wait for a mass measurement
}
@@ -177,14 +199,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
}
else
{
- ///
- /// Start a new measurement
- ///
- if (method == Config.Entities.MassMethod.Scale)
- scale.GetStableMassMeasurement();
- else
- scale.GetImmediateMassMeasurement();
-
+ StartMeasurement(); /// Start a new measurement
return Event.None;
}
}
@@ -192,6 +207,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Stop this operation
public void Stop()
{
- }
+ if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
+ scale.Activity = Activity.Idle;
+ }
}
}
diff --git a/TBF/BenchControl/MettlerToledo/Standard/SetUnitsOp.cs b/TBF/BenchControl/MettlerToledo/Standard/SetUnitsOp.cs
index 7f0031993..dca688038 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/SetUnitsOp.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/SetUnitsOp.cs
@@ -1,6 +1,5 @@
///
-/// Copyright (c) 2013-2015 Sensus Metering Systems
-/// Author: Milan Hanajik
+/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -16,19 +15,19 @@ namespace TBF.BenchControl.MettlerToledo.Standard
public override string ToString() { return string.Format("SetUnitsOp({0})", units); }
/// Set by the constructor
- BalanceDev balanceDev;
+ BalanceDev scale;
BalanceDev.Units units;
+ bool activityStarted;
///
/// Events: BalanceDone, Error
///
- /// Balance device instance
+ /// Balance device instance
/// Reference to the serialNumber
- public SetUnitsOp(BalanceDev balanceDev, BalanceDev.Units units)
+ public SetUnitsOp(BalanceDev scale, BalanceDev.Units units)
{
- if (balanceDev == null) throw new ArgumentNullException("balanceDev");
- this.balanceDev = balanceDev;
-
+ if (scale == null) throw new ArgumentNullException("balanceDev");
+ this.scale = scale;
this.units = units;
log.Debug(this.ToString());
@@ -37,9 +36,19 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Start this operation
public void Start()
{
- log.DebugFormat("{0} - Start()", balanceDev.Name);
- balanceDev.SetUnits(units);
- }
+ log.DebugFormat("{0} - SetUnitsOp - Start()", scale.Name);
+
+ if (scale.Activity == Activity.Idle)
+ {
+ scale.SendSetUnitsCmd(units);
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ }
+ else
+ {
+ activityStarted = false;
+ }
+ }
/// Run this operation
///
@@ -48,15 +57,25 @@ namespace TBF.BenchControl.MettlerToledo.Standard
///
public Event Run()
{
- if (balanceDev.MsrmntState == MsrmntState.Valid) return Event.BalanceDone; /// Units set
- if (balanceDev.MsrmntState == MsrmntState.Failed) return Event.Error; /// Failed
+ if (!activityStarted && scale.Activity == Activity.Idle)
+ {
+ scale.SendSetUnitsCmd(units);
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ return Event.None;
+ }
+
+ if (scale.MsrmntState == MsrmntState.Valid) return Event.BalanceDone; /// Units set
+ if (scale.MsrmntState == MsrmntState.Failed) return Event.Error; /// Failed
return Event.None; /// No result yet
}
/// Stop this operation
public void Stop()
{
- log.DebugFormat("{0} - Stop()", balanceDev.Name);
+ if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
+ scale.Activity = Activity.Idle;
+ log.DebugFormat("{0} - SetUnitsOp - Stop()", scale.Name);
}
}
}
diff --git a/TBF/BenchControl/MettlerToledo/Standard/TaringOp.cs b/TBF/BenchControl/MettlerToledo/Standard/TaringOp.cs
index 24e524463..f346ac2bf 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/TaringOp.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/TaringOp.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2013-2016 Sensus Metering Systems
+/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
///
using System;
using log4net;
@@ -15,19 +15,19 @@ namespace TBF.BenchControl.MettlerToledo.Standard
bool done;
/// Set by the constructor
- BalanceDev balanceDev;
+ BalanceDev scale;
DoubleBox tara;
+ bool activityStarted;
///
/// Events: BalanceDone, Error
///
- /// Balance device instance
+ /// Balance device instance
/// Reference to variable for 'tara' in kg
- public TaringOp(BalanceDev balanceDev, ref DoubleBox tara)
+ public TaringOp(BalanceDev scale, ref DoubleBox tara)
{
- if (balanceDev == null) throw new ArgumentNullException("balanceDev");
- this.balanceDev = balanceDev;
-
+ if (scale == null) throw new ArgumentNullException("balanceDev");
+ this.scale = scale;
this.tara = tara;
log.Debug(this.ToString());
@@ -36,10 +36,20 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Start this operation
public void Start()
{
- log.DebugFormat("{0} - Start()", balanceDev.Name);
+ log.DebugFormat("{0} - TaringOp - tart()", scale.Name);
+
done = false;
- balanceDev.Taring();
- }
+ if (scale.Activity == Activity.Idle)
+ {
+ scale.SendTaraCmd();
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ }
+ else
+ {
+ activityStarted = false;
+ }
+ }
/// Run this operation
///
@@ -49,32 +59,42 @@ namespace TBF.BenchControl.MettlerToledo.Standard
///
public Event Run()
{
- if (done) return Event.BalanceDone; /// Taring has been done already
-
- if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.Busy;
-
- if (balanceDev.MsrmntState == MsrmntState.Overload)
+ if (!activityStarted && scale.Activity == Activity.Idle)
{
- tara.Val = balanceDev.Capacity;
+ scale.SendTaraCmd();
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ return Event.Busy;
+ }
+
+ if (done) return Event.BalanceDone; /// Taring has been done already
+
+ if (scale.MsrmntState == MsrmntState.Busy) return Event.Busy;
+
+ if (scale.MsrmntState == MsrmntState.Overload)
+ {
+ tara.Val = scale.Capacity;
done = true;
return Event.BalanceOverload;
}
- if (balanceDev.MsrmntState == MsrmntState.Valid)
+ if (scale.MsrmntState == MsrmntState.Valid)
{
- tara.Val = balanceDev.Mass;
+ tara.Val = scale.Mass;
done = true;
return Event.BalanceDone; /// Taring completed
}
- balanceDev.Taring(); /// Failed -> repeat taring
+ scale.SendTaraCmd(); /// Failed -> repeat taring
return Event.Busy;
}
/// Stop this operation
public void Stop()
{
- log.DebugFormat("{0} - Stop()", balanceDev.Name);
+ if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
+ scale.Activity = Activity.Idle;
+ log.DebugFormat("{0} - TaringOp - Stop()", scale.Name);
}
}
}
diff --git a/TBF/BenchControl/MettlerToledo/Standard/ZeroOp.cs b/TBF/BenchControl/MettlerToledo/Standard/ZeroOp.cs
index 7d44fc472..bd93d2013 100644
--- a/TBF/BenchControl/MettlerToledo/Standard/ZeroOp.cs
+++ b/TBF/BenchControl/MettlerToledo/Standard/ZeroOp.cs
@@ -14,17 +14,18 @@ namespace TBF.BenchControl.MettlerToledo.Standard
bool done;
/// Set by the constructor
- BalanceDev balanceDev;
+ BalanceDev scale;
+ bool activityStarted;
///
/// Events: BalanceDone, Error
///
- /// Balance device instance
+ /// Balance device instance
/// Reference to variable for 'tara' in kg
- public ZeroOp(BalanceDev balanceDev)
+ public ZeroOp(BalanceDev scale)
{
- if (balanceDev == null) throw new ArgumentNullException("balanceDev");
- this.balanceDev = balanceDev;
+ if (scale == null) throw new ArgumentNullException("balanceDev");
+ this.scale = scale;
log.Debug(this.ToString());
}
@@ -32,10 +33,20 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Start this operation
public void Start()
{
- log.DebugFormat("{0} - Start()", balanceDev.Name);
+ log.DebugFormat("{0} - ZeroOp - Start()", scale.Name);
+
done = false;
- balanceDev.ZeroWhenStable();
- }
+ if (scale.Activity == Activity.Idle)
+ {
+ scale.SendZeroWhenStableCmd();
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ }
+ else
+ {
+ activityStarted = false;
+ }
+ }
/// Run this operation
///
@@ -45,30 +56,40 @@ namespace TBF.BenchControl.MettlerToledo.Standard
///
public Event Run()
{
- if (done) return Event.BalanceDone; /// Zeroing has been done already
+ if (!activityStarted && scale.Activity == Activity.Idle)
+ {
+ scale.SendZeroWhenStableCmd();
+ activityStarted = true;
+ scale.Activity = Activity.RunningOperation;
+ return Event.Busy;
+ }
- if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.Busy;
+ if (done) return Event.BalanceDone; /// Zeroing has been done already
- if (balanceDev.MsrmntState == MsrmntState.Overload)
+ if (scale.MsrmntState == MsrmntState.Busy) return Event.Busy;
+
+ if (scale.MsrmntState == MsrmntState.Overload)
{
done = true;
return Event.BalanceOverload;
}
- if (balanceDev.MsrmntState == MsrmntState.Valid)
+ if (scale.MsrmntState == MsrmntState.Valid)
{
done = true;
return Event.BalanceDone; /// Zeroing completed
}
- balanceDev.ZeroWhenStable(); /// Failed -> repeat zeroing
+ scale.SendZeroWhenStableCmd(); /// Failed -> repeat zeroing
return Event.Busy;
}
/// Stop this operation
public void Stop()
{
- log.DebugFormat("{0} - Stop()", balanceDev.Name);
+ if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
+ scale.Activity = Activity.Idle;
+ log.DebugFormat("{0} - ZeroOp - Stop()", scale.Name);
}
}
}
diff --git a/TBF/BenchControl/Sequences/SequenceBase.cs b/TBF/BenchControl/Sequences/SequenceBase.cs
index 2ca9a15b8..e3b95cf87 100644
--- a/TBF/BenchControl/Sequences/SequenceBase.cs
+++ b/TBF/BenchControl/Sequences/SequenceBase.cs
@@ -537,7 +537,6 @@ namespace TBF.BenchControl.Sequences
State.Create("SequenceBase : Transition : TestEnd - Default action")
.AddOperation(checkUiOp)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen,
StateMachine.DefaultValvesClose))
.EnterState();
@@ -651,7 +650,6 @@ namespace TBF.BenchControl.Sequences
.Create(string.Format("SequenceBase.Transition() : Step {0} start, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose))
.AddOperation(checkUiOp)
.AddOperation(conditionOperation)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step)));
for (int j = 0; j <= i; j++)
{
@@ -673,8 +671,7 @@ namespace TBF.BenchControl.Sequences
.Create(string.Format("SequenceBase.Transition() : Step {0} delay {1}s, opening={2}, closing={3}", step.ItemNr + 1, delay, step.ValvesOpen, step.ValvesClose))
.AddOperation(checkUiOp)
.AddOperation(conditionOperation)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
- .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step)))
+ .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step)))
.AddOperation(new TimerOp(delay));
for (int j = 0; j <= lastStartedRV; j++)
{
@@ -720,7 +717,6 @@ namespace TBF.BenchControl.Sequences
.Create(string.Format("SequenceBase.Transition() : Step {0} stop, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose))
.AddOperation(checkUiOp)
.AddOperation(conditionOperation)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step)));
for (int j = first; j <= lastStartedRV; j++)
{
@@ -779,7 +775,6 @@ namespace TBF.BenchControl.Sequences
{
State.Create("SequenceBase : Transition : TestStart - Default action")
.AddOperation(checkUiOp)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard
.SetValvesOp(GenericDevices.ValveBase.Merge(inPath.ValvesOpen, benchPath.ValvesOpen, outPath.ValvesOpen),
GenericDevices.ValveBase.Merge(inPath.ValvesClose, benchPath.ValvesClose, outPath.ValvesClose)))
@@ -799,7 +794,6 @@ namespace TBF.BenchControl.Sequences
/// Set route for the next test
State.Create("SequenceBase : AfterTestWithOverlap : Default action")
.AddOperation(checkUiOp)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard
.SetValvesOp(GenericDevices.ValveBase.Merge(nextInPath.ValvesOpen, nextBenchPath.ValvesOpen, nextOutPath.ValvesOpen),
GenericDevices.ValveBase.Merge(nextInPath.ValvesClose, nextBenchPath.ValvesClose, nextOutPath.ValvesClose)))
@@ -825,7 +819,6 @@ namespace TBF.BenchControl.Sequences
/// Set flow for the next test
State.Create(string.Format("SequenceBase : AfterTestWithOverlap - Setting the flow to {0} - {1} m3/h", nextQfrom, nextQto))
.AddOperation(checkUiOp)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(nextOutPath.RegulValve.SetFlowAndMeasureOp(nextOutPath.FlowMeter, nextQfrom, nextQto, RefFlow, FlowSettingTimeoutSec, 0))
.EnterState();
do {
diff --git a/TBF/BenchControl/TestMethods/DiverterTest/DiverterTestSeq.cs b/TBF/BenchControl/TestMethods/DiverterTest/DiverterTestSeq.cs
index 33a28a9f4..fda3dfc7a 100644
--- a/TBF/BenchControl/TestMethods/DiverterTest/DiverterTestSeq.cs
+++ b/TBF/BenchControl/TestMethods/DiverterTest/DiverterTestSeq.cs
@@ -610,7 +610,6 @@ namespace TBF.BenchControl.TestMethods.DiverterTest
State.Create("SequenceBase : Transition : TestEnd - Default action")
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
.EnterState();
do {
diff --git a/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs
index 45110db1f..b48079553 100644
--- a/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs
+++ b/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs
@@ -646,8 +646,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl
State.Create("SequenceBase : Transition : TestEnd - Default action")
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
- .AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
+ .AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
diff --git a/TBF/BenchControl/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs
index 327a404bf..4bd4798f9 100644
--- a/TBF/BenchControl/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs
+++ b/TBF/BenchControl/TestMethods/FlyingStartMassCollComparative/FlyingStartMassCollComparativeSeq.cs
@@ -750,7 +750,6 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollComparative
State.Create("SequenceBase : Transition : TestEnd - Default action")
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
.EnterState();
do {
diff --git a/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs
index 79e0b774c..e4ca3b342 100644
--- a/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs
+++ b/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs
@@ -769,7 +769,6 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged
State.Create("SequenceBase : Transition : TestEnd - Default action")
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
.EnterState();
do {
diff --git a/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs
index b6c5fba5a..54f27e14b 100644
--- a/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs
+++ b/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs
@@ -636,7 +636,6 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection
State.Create("SequenceBase : Transition : TestEnd - Default action")
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
- .AddOperation(new MettlerToledo.KeepReadingMassesOp())
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
.EnterState();
do {
diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj
index 7a68c1e7c..3bc609335 100644
--- a/TBF/TBF.csproj
+++ b/TBF/TBF.csproj
@@ -667,7 +667,6 @@
TempMeterCfgCtrl.cs
-
UserControl