- Added Underload measurement state - Detect underload responses from Mettler Toledo scales - Automatically zero the scale after underload detection - Restart mass measurement after successful zeroing - Prevent zeroing response from being used as a valid measurement - Preserve measurement stability by clearing buffered readings after underload
108 lines
2.8 KiB
C#
108 lines
2.8 KiB
C#
///
|
|
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.Rig.Scales.MettlerToledo
|
|
{
|
|
public class TaringOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TaringOp));
|
|
public override string ToString() { return string.Format("TaringOp(.,.)"); }
|
|
|
|
bool done;
|
|
|
|
/// Set by the constructor
|
|
Scale scale;
|
|
DoubleBox tara;
|
|
bool activityStarted;
|
|
|
|
/// <summary>
|
|
/// Events: BalanceDone, Error
|
|
/// </summary>
|
|
/// <param name="scale">Balance device instance</param>
|
|
/// <param name="result">Reference to variable for 'tara' in kg</param>
|
|
public TaringOp(Scale scale, ref DoubleBox tara)
|
|
{
|
|
if (scale == null) throw new ArgumentNullException("balanceDev");
|
|
this.scale = scale;
|
|
this.tara = tara;
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
log.DebugFormat("{0} - TaringOp - tart()", scale.Name);
|
|
|
|
done = false;
|
|
if (scale.Activity == Activity.Idle)
|
|
{
|
|
scale.SendTaraCmd();
|
|
activityStarted = true;
|
|
scale.Activity = Activity.RunningOperation;
|
|
}
|
|
else
|
|
{
|
|
activityStarted = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>
|
|
/// Event.None
|
|
/// Event.BalanceDone
|
|
/// Event.Error . . . . . Current.Tick == null
|
|
/// </returns>
|
|
public Event Run()
|
|
{
|
|
if (!activityStarted && scale.Activity == Activity.Idle)
|
|
{
|
|
scale.SendTaraCmd();
|
|
activityStarted = true;
|
|
scale.Activity = Activity.RunningOperation;
|
|
return Event.Busy;
|
|
}
|
|
|
|
if (done) return Event.ScaleDone; /// Taring has been done already
|
|
|
|
if (scale.MsrmntState == MsrmntState.Busy) return Event.Busy;
|
|
|
|
if (scale.MsrmntState == MsrmntState.Underload)
|
|
{
|
|
tara.Val = scale.Capacity;
|
|
done = true;
|
|
return Event.ScaleUnderload;
|
|
}
|
|
|
|
if (scale.MsrmntState == MsrmntState.Overload)
|
|
{
|
|
tara.Val = scale.Capacity;
|
|
done = true;
|
|
return Event.ScaleOverload;
|
|
}
|
|
|
|
if (scale.MsrmntState == MsrmntState.Valid)
|
|
{
|
|
tara.Val = scale.Mass;
|
|
done = true;
|
|
return Event.ScaleDone; /// Taring completed
|
|
}
|
|
|
|
scale.SendTaraCmd(); /// Failed -> repeat taring
|
|
return Event.Busy;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
if (scale.MsrmntState == MsrmntState.Busy) scale.MsrmntState = MsrmntState.Failed;
|
|
scale.Activity = Activity.Idle;
|
|
log.DebugFormat("{0} - TaringOp - Stop()", scale.Name);
|
|
}
|
|
}
|
|
}
|