Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using log4net;
|
||||
using TBF.Boxes;
|
||||
|
||||
namespace TBF.Rig.MettlerToledo.Standard
|
||||
{
|
||||
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
|
||||
BalanceDev 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(BalanceDev 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.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 (scale.MsrmntState == MsrmntState.Valid)
|
||||
{
|
||||
tara.Val = scale.Mass;
|
||||
done = true;
|
||||
return Event.BalanceDone; /// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user