2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using log4net;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Elde
|
|
|
|
|
|
{
|
|
|
|
|
|
public class StartMeasurementOp : IOperation
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(StartMeasurementOp));
|
2014-09-12 05:17:30 +00:00
|
|
|
|
public override string ToString() { return string.Format("StartMeasurementOp(ref={0},pulses={1})", flowMeterIdx, refPulses); }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// Set by the constructor
|
|
|
|
|
|
readonly ControlBoardDev controlBoard;
|
2014-09-12 05:17:30 +00:00
|
|
|
|
readonly int flowMeterIdx;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
readonly int refPulses; /// Number of reference pulses for a complete test
|
|
|
|
|
|
readonly TestMethods testMethod;
|
2014-07-30 22:50:42 +00:00
|
|
|
|
readonly float filterConstant;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
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>
|
2014-07-30 22:50:42 +00:00
|
|
|
|
public StartMeasurementOp(ControlBoardDev controlBoardDev, GenericDevices.IFlowMeter flowMeter,
|
|
|
|
|
|
int refPulses, TestMethods method, float filterConstant)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (controlBoardDev == null) throw new ArgumentNullException("controlBoardDev");
|
|
|
|
|
|
this.controlBoard = controlBoardDev;
|
|
|
|
|
|
|
2014-09-12 05:17:30 +00:00
|
|
|
|
if (flowMeter is Elde.FlowMeter.FlowMeter)
|
|
|
|
|
|
{
|
|
|
|
|
|
flowMeterIdx = (flowMeter as Elde.FlowMeter.FlowMeter).Idx1;
|
|
|
|
|
|
}
|
2014-09-15 20:00:30 +00:00
|
|
|
|
else if (flowMeter is Elde.FlowMeterTwins.FlowMeter)
|
2014-09-12 05:17:30 +00:00
|
|
|
|
{
|
|
|
|
|
|
flowMeterIdx = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentException("flowMeter is null or is not Elde");
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
this.refPulses = refPulses;
|
|
|
|
|
|
this.testMethod = method;
|
2014-07-30 22:50:42 +00:00
|
|
|
|
this.filterConstant = filterConstant;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
log.Debug(this.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
2014-09-12 05:17:30 +00:00
|
|
|
|
controlBoard.SendCommand(Command.Start, flowMeterIdx, controlBoard.RRoute, refPulses, testMethod,
|
2014-07-30 22:50:42 +00:00
|
|
|
|
filterConstant, 20, 0, StopDevs.None);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Run this operation</summary>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// Event.FlowInDone or Event.FlowOutDone
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public Event Run()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (started) return Event.MeasurementStarted;
|
2014-09-05 20:14:12 +00:00
|
|
|
|
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))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2014-09-05 20:14:12 +00:00
|
|
|
|
log.Info("Test started");
|
2014-07-28 07:54:35 +00:00
|
|
|
|
started = true;
|
|
|
|
|
|
return Event.MeasurementStarted;
|
|
|
|
|
|
}
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|