using System; using log4net; namespace TBF.BenchControl.Elde { public class StartMeasurementOp : IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(StartMeasurementOp)); public override string ToString() { return string.Format("StartMeasurementOp(ref={0},pulses={1})", flowMeterIdx, refPulses); } /// Set by the constructor readonly ControlBoardDev controlBoard; readonly int flowMeterIdx; readonly int refPulses; /// Number of reference pulses for a complete test readonly TestMethods testMethod; readonly float filterConstant; bool started = false; /// /// Starts the measurement. /// Events: MeasurementStarted /// /// Control board component reference /// Flow meter component reference /// Register readers references /// Water volume for the test in liters public StartMeasurementOp(ControlBoardDev controlBoardDev, GenericDevices.IFlowMeter flowMeter, int refPulses, TestMethods method, float filterConstant) { if (controlBoardDev == null) throw new ArgumentNullException("controlBoardDev"); this.controlBoard = controlBoardDev; if (flowMeter is Elde.FlowMeter.FlowMeter) { flowMeterIdx = (flowMeter as Elde.FlowMeter.FlowMeter).Idx1; } else if (flowMeter is Elde.FlowMeterTwins.FlowMeter) { flowMeterIdx = 0; } else { throw new ArgumentException("flowMeter is null or is not Elde"); } this.refPulses = refPulses; this.testMethod = method; this.filterConstant = filterConstant; log.Debug(this.ToString()); } /// Start this operation public void Start() { controlBoard.SendCommand(Command.Start, flowMeterIdx, controlBoard.RRoute, refPulses, testMethod, filterConstant, 20, 0, StopDevs.None); } /// Run this operation /// /// Event.FlowInDone or Event.FlowOutDone /// public Event Run() { if (started) return Event.MeasurementStarted; StatusP statusP = controlBoard.StatusP; log.DebugFormat("statusP = {0} {1} {2} {3}", (((ulong)statusP >> 48) & 0xFFFF).ToString("X4"), (((ulong)statusP >> 32) & 0xFFFF).ToString("X4"), (((ulong)statusP >> 16) & 0xFFFF).ToString("X4"), ((ulong)statusP & 0xFFFF).ToString("X4")); if (0 != (statusP & StatusP.TestInProgress)) { log.Info("Test started"); started = true; return Event.MeasurementStarted; } return Event.None; } /// Stop this operation public void Stop() { } } }