tbf/TestBenchFramework/BenchControl/Elde/StartMeasurementOp.cs

92 lines
3.2 KiB
C#
Raw Normal View History

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
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;
/// <summary>
/// Starts the measurement.
/// Events: MeasurementStarted
/// </summary>
/// <param name="controlBoardDev">Control board component reference</param>
/// <param name="flowMeter">Flow meter component reference</param>
/// <param name="readers">Register readers references</param>
/// <param name="volume">Water volume for the test in liters</param>
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());
}
/// <summary>Start this operation</summary>
public void Start()
{
controlBoard.SendCommand(Command.Start, flowMeterIdx, controlBoard.RRoute, refPulses, testMethod,
filterConstant, 20, 0, StopDevs.None);
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.FlowInDone or Event.FlowOutDone
/// </returns>
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;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}