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));
|
2015-09-22 16:39:00 +00:00
|
|
|
|
public override string ToString() { return string.Format("StartMeasurementOp(ref={0},pulses={1})", flowMeterNr, refPulses); }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// Set by the constructor
|
|
|
|
|
|
readonly ControlBoardDev controlBoard;
|
2015-09-22 16:39:00 +00:00
|
|
|
|
readonly Elde.RegulValve.RegulValve regulValve;
|
|
|
|
|
|
readonly int regulValveNr;
|
|
|
|
|
|
readonly int flowMeterNr;
|
|
|
|
|
|
readonly float nominalFlow;
|
|
|
|
|
|
readonly float reqFlowLo;
|
|
|
|
|
|
readonly float reqFlowHi;
|
|
|
|
|
|
readonly float reqFlowAve;
|
|
|
|
|
|
readonly float pidCoef;
|
|
|
|
|
|
readonly int refPulses; /// Number of reference pulses for a complete test
|
2014-07-28 07:54:35 +00:00
|
|
|
|
readonly TestMethods testMethod;
|
2014-07-30 22:50:42 +00:00
|
|
|
|
readonly float filterConstant;
|
2015-09-22 16:39:00 +00:00
|
|
|
|
readonly int diverterNr;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
bool started = false;
|
|
|
|
|
|
|
2015-09-22 16:39:00 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Internal states of this operation
|
|
|
|
|
|
///
|
|
|
|
|
|
enum OpState
|
|
|
|
|
|
{
|
|
|
|
|
|
StartingTest,
|
|
|
|
|
|
TestStarted,
|
|
|
|
|
|
ValveMoveToFlow,
|
|
|
|
|
|
OpCompleted,
|
|
|
|
|
|
}
|
|
|
|
|
|
OpState opState;
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Starts the measurement.
|
|
|
|
|
|
/// Events: MeasurementStarted
|
|
|
|
|
|
/// </summary>
|
2015-09-22 14:59:17 +00:00
|
|
|
|
/// <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>
|
2015-09-22 16:39:00 +00:00
|
|
|
|
public StartMeasurementOp(ControlBoardDev controlBoard, OutputPath outputPath, TestMethods method,
|
|
|
|
|
|
float requiredFlowLo, float requiredFlowHi,
|
|
|
|
|
|
int refPulses, float filterConstant)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2015-09-22 14:59:17 +00:00
|
|
|
|
if (controlBoard == null) throw new ArgumentNullException("controlBoardDev");
|
|
|
|
|
|
this.controlBoard = controlBoard;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2015-09-22 14:59:17 +00:00
|
|
|
|
if (outputPath.FlowMeter is Elde.FlowMeter.FlowMeter)
|
2014-09-12 05:17:30 +00:00
|
|
|
|
{
|
2015-09-22 16:39:00 +00:00
|
|
|
|
flowMeterNr = (outputPath.FlowMeter as Elde.FlowMeter.FlowMeter).Idx1;
|
2014-09-12 05:17:30 +00:00
|
|
|
|
}
|
2015-09-22 14:59:17 +00:00
|
|
|
|
else if (outputPath.FlowMeter is Elde.FlowMeterTwins.FlowMeter)
|
2014-09-12 05:17:30 +00:00
|
|
|
|
{
|
2015-09-22 16:39:00 +00:00
|
|
|
|
flowMeterNr = 0;
|
2014-09-12 05:17:30 +00:00
|
|
|
|
}
|
2017-01-25 16:59:26 +00:00
|
|
|
|
else if (outputPath.FlowMeter is Dummy.FlowMeter.FlowMeter)
|
|
|
|
|
|
{
|
|
|
|
|
|
flowMeterNr = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2014-09-12 05:17:30 +00:00
|
|
|
|
{
|
2017-01-25 16:59:26 +00:00
|
|
|
|
throw new ArgumentException("Flowmeter is not compatible with Elde Control Board");
|
2014-09-12 05:17:30 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-01-25 16:59:26 +00:00
|
|
|
|
if (outputPath.RegulValve is Elde.RegulValve.RegulValve)
|
|
|
|
|
|
{
|
|
|
|
|
|
regulValve = outputPath.RegulValve as Elde.RegulValve.RegulValve;
|
|
|
|
|
|
regulValveNr = this.regulValve.Idx1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!(outputPath.RegulValve is Dummy.RegulValve.RegulValve))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentNullException("Regulation valve is not compatible with Elde Control Board");
|
|
|
|
|
|
}
|
2015-09-22 16:39:00 +00:00
|
|
|
|
|
2015-09-22 14:59:17 +00:00
|
|
|
|
if (outputPath.Diverter is Elde.Diverter.Diverter)
|
2015-08-14 16:14:08 +00:00
|
|
|
|
{
|
2015-09-22 16:39:00 +00:00
|
|
|
|
diverterNr = (outputPath.Diverter as Elde.Diverter.Diverter).AdcNr - 4;
|
2015-08-14 16:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-09-22 16:39:00 +00:00
|
|
|
|
nominalFlow = outputPath.FlowMeter.NominalFlow;
|
|
|
|
|
|
|
|
|
|
|
|
this.reqFlowLo = requiredFlowLo;
|
|
|
|
|
|
this.reqFlowHi = requiredFlowHi;
|
|
|
|
|
|
this.reqFlowAve = (reqFlowLo + reqFlowHi) / 2.0f;
|
|
|
|
|
|
this.pidCoef = outputPath.PidCoef;
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
2015-07-03 07:40:34 +00:00
|
|
|
|
controlBoard.SyncRoute();
|
2016-06-22 14:54:16 +00:00
|
|
|
|
#if IPERLST || IPERLST_SPECIAL || BADGER_VELKA_TRAT || SLM_50
|
2016-02-07 21:27:32 +00:00
|
|
|
|
int flowMeterIdxAndDiv = flowMeterNr + 16 * diverterNr;
|
2015-08-14 16:14:08 +00:00
|
|
|
|
#else
|
2016-04-07 13:37:49 +00:00
|
|
|
|
int flowMeterIdxAndDiv = flowMeterNr;
|
2015-08-14 16:14:08 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2016-04-04 07:23:07 +00:00
|
|
|
|
controlBoard.SendCommand(Command.Start, flowMeterIdxAndDiv, controlBoard.Route,
|
|
|
|
|
|
refPulses, refPulses, testMethod,
|
2014-07-30 22:50:42 +00:00
|
|
|
|
filterConstant, 20, 0, StopDevs.None);
|
2015-09-22 16:39:00 +00:00
|
|
|
|
|
|
|
|
|
|
opState = OpState.StartingTest;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Run this operation</summary>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// Event.FlowInDone or Event.FlowOutDone
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public Event Run()
|
|
|
|
|
|
{
|
2015-09-22 16:39:00 +00:00
|
|
|
|
if (opState == OpState.StartingTest)
|
|
|
|
|
|
{
|
|
|
|
|
|
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");
|
|
|
|
|
|
opState = OpState.TestStarted;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (opState == OpState.TestStarted)
|
|
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Done once, issues an appropriate ValveMove(...) command
|
|
|
|
|
|
///
|
|
|
|
|
|
if (reqFlowLo >= reqFlowHi || reqFlowLo > nominalFlow || reqFlowHi <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Event.OpArgumentError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
|
|
|
|
|
regulValveNr, flowMeterNr, reqFlowLo, reqFlowHi);
|
|
|
|
|
|
|
|
|
|
|
|
float freqLo = 2000.0f * reqFlowLo / nominalFlow;
|
|
|
|
|
|
float freqHi = 2000.0f * reqFlowHi / nominalFlow;
|
|
|
|
|
|
controlBoard.ValveMove(regulValveNr, RegulValveMode.TargetFrequency,
|
|
|
|
|
|
new float[2] { freqLo, freqHi },
|
|
|
|
|
|
regulValve.StableTime);
|
|
|
|
|
|
|
|
|
|
|
|
opState = OpState.OpCompleted;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (opState == OpState.OpCompleted)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Event.MeasurementStarted;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|