tbf/TestBenchFramework/BenchControl/MettlerToledo/ReadMassOp.cs
2014-07-31 17:04:09 +02:00

70 lines
1.7 KiB
C#

using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.MettlerToledo
{
public class ReadMassOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ReadMassOp));
public override string ToString() { return string.Format("ReadMassOp(.,.)"); }
bool done;
/// Set by the constructor
BalanceDev balanceDev;
FloatBox result;
/// <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 ReadMassOp(BalanceDev balanceDev, ref FloatBox result)
{
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
this.balanceDev = balanceDev;
this.result = result;
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
done = false;
balanceDev.GetImmediateMassMeasurement();
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None
/// Event.BalanceDone
/// Event.Error . . . . . Current.Tick == null
/// </returns>
public Event Run()
{
if (done) return Event.BalanceDone; /// Mass has already been read
if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.None;
if (balanceDev.MsrmntState == MsrmntState.Valid)
{
result.Val = balanceDev.Mass;
done = true;
return Event.BalanceDone; /// Mass read OK
}
balanceDev.GetImmediateMassMeasurement(); /// Failed -> repeat the measurement
return Event.None;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}