tbf/TestBenchFramework/BenchControl/MettlerToledo/ReadMassOp.cs
Milan Hanajik 74a6800f9e Changes done on Fuzhou300 system:
- ControlComDev.SetFMFreq() modifications (array size)
- StatusP and Route logging
- StatusP bit assignments: bit3 -> bit5
- MettlerToledo logging
2014-09-05 22:14:12 +02:00

73 lines
2.0 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 (balanceDev.MsrmntState == MsrmntState.Valid)
{
result.Val = balanceDev.Mass;
done = true;
log.InfoFormat("ReadMassOp.Run() ... mass={0} ... returning Event.BalanceDone", balanceDev.Mass);
balanceDev.GetImmediateMassMeasurement(); /// Start another measurement
return Event.BalanceDone; /// Mass read OK
}
else if (done)
{
return Event.BalanceDone; /// Mass has already been read (at least once)
}
else
{
return Event.None;
}
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}