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