103 lines
3.2 KiB
C#
103 lines
3.2 KiB
C#
|
|
///
|
|||
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|||
|
|
///
|
|||
|
|
using System;
|
|||
|
|
using log4net;
|
|||
|
|
using TBF.Boxes;
|
|||
|
|
|
|||
|
|
namespace TBF.BenchControl.Elde
|
|||
|
|
{
|
|||
|
|
public class ReadDiverterTransitionOp : IOperation
|
|||
|
|
{
|
|||
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ReadDiverterTransitionOp));
|
|||
|
|
public override string ToString() { return string.Format("ReadDiverterTransitionOp()"); }
|
|||
|
|
|
|||
|
|
/// Set by the constructor
|
|||
|
|
readonly ControlBoardDev controlBoard;
|
|||
|
|
readonly int runsCountWhenSendingCmd;
|
|||
|
|
readonly int runsCountWhenReadingDiv;
|
|||
|
|
readonly FloatBox tStart;
|
|||
|
|
readonly FloatBox tEnd;
|
|||
|
|
|
|||
|
|
int counter;
|
|||
|
|
bool cmdSent = false;
|
|||
|
|
bool divRead = false;
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Starts the measurement.
|
|||
|
|
/// Events: MeasurementStarted
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="controlBoard">Control board component reference</param>
|
|||
|
|
/// <param name="outputPath">Specifies used components</param>
|
|||
|
|
/// <param name="method">Test method</param>
|
|||
|
|
/// <param name="refPulses">Test duration in number of reference flowmeter pulses</param>
|
|||
|
|
/// <param name="filterConstant">Specifies filter for watermeter pulses</param>
|
|||
|
|
public ReadDiverterTransitionOp(ControlBoardDev controlBoard, int runsCountWhenSendingCmd, int runsCountWhenReadingDiv, FloatBox tStart, FloatBox tEnd)
|
|||
|
|
{
|
|||
|
|
if (controlBoard == null) throw new ArgumentNullException("controlBoardDev");
|
|||
|
|
if (runsCountWhenSendingCmd < 0) throw new ArgumentNullException("runsCountWhenSendingCmd");
|
|||
|
|
if (runsCountWhenReadingDiv <= runsCountWhenSendingCmd) throw new ArgumentNullException("runsCountWhenReadingDiv");
|
|||
|
|
if (tStart == null) throw new ArgumentNullException("tStart");
|
|||
|
|
if (tEnd == null) throw new ArgumentNullException("tEnd");
|
|||
|
|
|
|||
|
|
this.controlBoard = controlBoard;
|
|||
|
|
this.runsCountWhenSendingCmd = runsCountWhenSendingCmd;
|
|||
|
|
this.runsCountWhenReadingDiv = runsCountWhenReadingDiv;
|
|||
|
|
this.tStart = tStart;
|
|||
|
|
this.tEnd = tEnd;
|
|||
|
|
|
|||
|
|
log.Debug(this.ToString());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>Start this operation</summary>
|
|||
|
|
public void Start()
|
|||
|
|
{
|
|||
|
|
counter = 0;
|
|||
|
|
if (runsCountWhenSendingCmd == 0)
|
|||
|
|
{
|
|||
|
|
SendCommand();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>Run this operation</summary>
|
|||
|
|
/// <returns>
|
|||
|
|
/// Event.FlowInDone or Event.FlowOutDone
|
|||
|
|
/// </returns>
|
|||
|
|
public Event Run()
|
|||
|
|
{
|
|||
|
|
counter++;
|
|||
|
|
|
|||
|
|
if (counter == runsCountWhenSendingCmd)
|
|||
|
|
{
|
|||
|
|
SendCommand();
|
|||
|
|
}
|
|||
|
|
else if (counter == runsCountWhenReadingDiv)
|
|||
|
|
{
|
|||
|
|
ReadDiverter();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return Event.None;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>Stop this operation</summary>
|
|||
|
|
public void Stop()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SendCommand()
|
|||
|
|
{
|
|||
|
|
controlBoard.SyncRoute();
|
|||
|
|
controlBoard.SendCommand(Command.ReadDivTransition, 0, controlBoard.Route, 0, 0, 0, 0, 0, 0, StopDevs.None);
|
|||
|
|
cmdSent = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ReadDiverter()
|
|||
|
|
{
|
|||
|
|
tStart.Val = 0.001f * (float)controlBoard.DivTime(1);
|
|||
|
|
tEnd.Val = 0.001F * (float)controlBoard.DivTime(2);
|
|||
|
|
divRead = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|