MettlerToledo.Standard (1) Always reads imm.mass when idle (2) Changes in logging

This commit is contained in:
Milan Hanajik 2020-10-29 10:29:32 +01:00
parent a2556bec35
commit e1a185efdf
18 changed files with 261 additions and 258 deletions

View File

@ -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;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="requiredReadingsCount">Required mass readings count (>= 3)</param>
/// <param name="result">Reference to the measured mass in kg</param>
public KeepReadingMassesOp()
{
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
done = false;
for (int i = 0; i < Standard.BalanceDev.BalancesCount; i++)
{
Standard.BalanceDev.Balances[i].GetImmediateMassMeasurement();
}
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None
/// </returns>
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;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}

View File

@ -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();
}
}

View File

@ -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,
}
/// <summary>
/// Mettler Toledo ICS4_5 Weighting terminal connected via serial interface (RS232)
/// </summary>
@ -62,7 +69,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>
@ -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
/// <summary>
/// Get a stable mass measurement
/// </summary>
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
/// <summary>
/// Get an immediate mass measurement
/// </summary>
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
/// </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;
@ -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
/// <summary>Run this device</summary>
public void RunDeviceAfter()
{
if (Activity == Activity.Idle)
{
SendImmediateMeasurementCmd();
Activity = Activity.ImmediateMeasurement;
}
base.RunAfter();
}

View File

@ -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
/// <summary>
/// Get the serial number
/// </summary>
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");
}
/// <summary>
@ -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)

View File

@ -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();
}
/// <summary>
/// Parse characters received from the serial port
/// </summary>
@ -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)

View File

@ -14,6 +14,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// Set by the constructor
BalanceNewDev scale;
string serialNumber;
bool activityStarted;
/// <summary>
/// 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
/// <summary>Start this operation</summary>
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;
}
}
/// <summary>Run this operation</summary>
/// <returns>
@ -44,27 +52,33 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// </returns>
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
}
/// <summary>Stop this operation</summary>
public void Stop()
{
log.DebugFormat("{0} - Stop()", scale.Name);
if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
scale.Activity = Activity.Idle;
}
}
}

View File

@ -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;
/// <summary>
/// Events: BalanceDone, Error
/// Events: BalanceDone (always)
/// </summary>
/// <param name="scale">Balance device instance</param>
/// <param name="requiredReadingsCount">Required mass readings count (>= 3)</param>
/// <param name="result">Reference to the measured mass in kg</param>
public ReadMassOp(BalanceDev scale, ref DoubleBox result)
{
if (scale == null) throw new ArgumentNullException("balanceDev");
this.scale = scale;
this.result = result;
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
scale.GetImmediateMassMeasurement();
started = true;
done = false;
result.Val = scale.Mass;
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None
/// Event.BalanceDone
/// Event.Error . . . . . Current.Tick == null
/// </returns>
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;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}
}

View File

@ -27,7 +27,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard
double[] sortedMassReadings;
int currentReadingsCount;
bool activityStarted;
bool measurementCompleted;
int timeout;
/// <summary>
/// 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());
}
/// <summary>
/// Call scale.XYStartMeasurement() function and set measurementStarted flag.
/// </summary>
void StartMeasurement()
{
if (method == Config.Entities.MassMethod.Scale)
scale.SendStableMeasurementCmd();
else
scale.SendImmediateMeasurementCmd();
}
/// <summary>Start this operation</summary>
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;
}
}
/// <summary>Run this operation</summary>
/// <returns>
@ -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
/// <summary>Stop this operation</summary>
public void Stop()
{
}
if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
scale.Activity = Activity.Idle;
}
}
}

View File

@ -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;
/// <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 serialNumber</param>
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
/// <summary>Start this operation</summary>
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;
}
}
/// <summary>Run this operation</summary>
/// <returns>
@ -48,15 +57,25 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// </returns>
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
}
/// <summary>Stop this operation</summary>
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);
}
}
}

View File

@ -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;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="scale">Balance device instance</param>
/// <param name="result">Reference to variable for 'tara' in kg</param>
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
/// <summary>Start this operation</summary>
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;
}
}
/// <summary>Run this operation</summary>
/// <returns>
@ -49,32 +59,42 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// </returns>
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;
}
/// <summary>Stop this operation</summary>
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);
}
}
}

View File

@ -14,17 +14,18 @@ namespace TBF.BenchControl.MettlerToledo.Standard
bool done;
/// Set by the constructor
BalanceDev balanceDev;
BalanceDev scale;
bool activityStarted;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="scale">Balance device instance</param>
/// <param name="result">Reference to variable for 'tara' in kg</param>
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
/// <summary>Start this operation</summary>
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;
}
}
/// <summary>Run this operation</summary>
/// <returns>
@ -45,30 +56,40 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// </returns>
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;
}
/// <summary>Stop this operation</summary>
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);
}
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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();

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -667,7 +667,6 @@
<DependentUpon>TempMeterCfgCtrl.cs</DependentUpon>
</Compile>
<Compile Include="BenchControl\Keithley\TempMeter\Factory.cs" />
<Compile Include="BenchControl\MettlerToledo\KeepReadingMassesOp.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\BalanceCfg.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\BalanceCfgCtrl.cs">
<SubType>UserControl</SubType>