StartMeasurementOp, ver. 3.1.1628
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using log4net;
|
||||
using TBF.Rig.GenericDevices;
|
||||
|
||||
namespace TBF.Rig.ControlBoard.Uni
|
||||
{
|
||||
public class StartMeasurementOp : IOperation
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(StartMeasurementOp));
|
||||
public override string ToString() { return string.Format("StartMeasurementOp()"); }
|
||||
|
||||
/// Set by the constructor
|
||||
readonly UniCB uniCB;
|
||||
readonly TBF.Rig.Uni.RegValve.RegValve regValve;
|
||||
readonly TBF.Rig.Uni.FlowMeter.FlowMeter flowMeter;
|
||||
readonly TBF.Rig.Uni.Diverter.Diverter diverter;
|
||||
readonly int regulValveStableTime;
|
||||
readonly double maximalFlow;
|
||||
readonly double qFrom;
|
||||
readonly double qTo;
|
||||
readonly int totalRefPulses; /// Number of reference pulses for a complete test
|
||||
readonly int massRefPulses; /// Number of reference pulses for mass collection
|
||||
readonly int delayBeforeFlowRegulation; /// Delay before flow control starts in seconds
|
||||
readonly TestMethods testMethod;
|
||||
|
||||
///
|
||||
/// Internal states of this operation
|
||||
///
|
||||
enum OpState
|
||||
{
|
||||
StartingTest,
|
||||
ResendCommand,
|
||||
WaitingBeforeValveMove,
|
||||
StartingFlowRegulation,
|
||||
OpCompleted,
|
||||
}
|
||||
OpState opState;
|
||||
|
||||
|
||||
int delayStartTime; /// StateMachine.Time snapshot when delay before flow regulation starts
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Starts the measurement.
|
||||
/// Events: MeasurementStarted
|
||||
/// </summary>
|
||||
/// <param name="cb">Control board component reference</param>
|
||||
/// <param name="devices">Specifies used components</param>
|
||||
/// <param name="method">Test method</param>
|
||||
/// <param name="totalRefPulses">Test duration in number of reference flowmeter pulses</param>
|
||||
/// <param name="filterConstant">Specifies filter for watermeter pulses</param>
|
||||
public StartMeasurementOp(IControlBoard cb, OutputPath devices, TestMethods method, double qFrom, double qTo,
|
||||
int refPulses, int delayBeforeFlowRegulation = 0)
|
||||
: this(cb, devices, method, qFrom, qTo, refPulses, refPulses, delayBeforeFlowRegulation)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the measurement.
|
||||
/// Events: MeasurementStarted
|
||||
/// </summary>
|
||||
/// <param name="cb">Control board component reference</param>
|
||||
/// <param name="devices">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 StartMeasurementOp(IControlBoard cb, OutputPath devices, TestMethods method, double qFrom, double qTo,
|
||||
int totalRefPulses, int massRefPulses, int delayBeforeFlowRegulation = 0)
|
||||
{
|
||||
this.uniCB = cb as UniCB;
|
||||
if (uniCB == null) throw new ArgumentNullException("Invalid control board");
|
||||
|
||||
flowMeter = devices.FlowMeter as TBF.Rig.Uni.FlowMeter.FlowMeter;
|
||||
if (flowMeter == null) throw new ArgumentNullException("Invalid flow meter");
|
||||
|
||||
regValve = devices.RegValve as TBF.Rig.Uni.RegValve.RegValve;
|
||||
if (regValve == null) throw new ArgumentNullException("Invalid regulation");
|
||||
|
||||
diverter = devices.Diverter as TBF.Rig.Uni.Diverter.Diverter;
|
||||
if (diverter == null) throw new ArgumentNullException("Invalid diverter");
|
||||
|
||||
this.testMethod = method;
|
||||
this.qFrom = qFrom;
|
||||
this.qTo = qTo;
|
||||
this.totalRefPulses = totalRefPulses;
|
||||
this.massRefPulses = massRefPulses;
|
||||
this.delayBeforeFlowRegulation = delayBeforeFlowRegulation;
|
||||
|
||||
maximalFlow = 1.25 * flowMeter.NominalFlow;
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
void SendStartCommand()
|
||||
{
|
||||
//uniCB.SyncRoute();
|
||||
uniCB.StartTest(false, flowMeter.Idx1, diverter.DiverterNr, 20,
|
||||
testMethod == TestMethods.Diverter || testMethod == TestMethods.MassAndContinue || testMethod == TestMethods.Synchro,
|
||||
testMethod == TestMethods.Diverter || testMethod == TestMethods.MassAndContinue,
|
||||
testMethod == TestMethods.FixedStart,
|
||||
totalRefPulses, massRefPulses);
|
||||
}
|
||||
|
||||
/// <summary>Start this operation</summary>
|
||||
public void Start()
|
||||
{
|
||||
SendStartCommand();
|
||||
opState = OpState.StartingTest;
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
/// <returns>
|
||||
/// Event.FlowInDone or Event.FlowOutDone
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
if (opState == OpState.StartingTest)
|
||||
{
|
||||
ulong state = uniCB.State;
|
||||
log.DebugFormat("state = {0} {1} {2} {3}",
|
||||
(((ulong)state >> 48) & 0xFFFF).ToString("X4"),
|
||||
(((ulong)state >> 32) & 0xFFFF).ToString("X4"),
|
||||
(((ulong)state >> 16) & 0xFFFF).ToString("X4"),
|
||||
((ulong)state & 0xFFFF).ToString("X4"));
|
||||
|
||||
if ((state & (ulong)StatusP.TestInProgress) != 0)
|
||||
{
|
||||
log.Info("Test started");
|
||||
if (delayBeforeFlowRegulation > 0)
|
||||
{
|
||||
delayStartTime = StateMachine.Time;
|
||||
opState = OpState.WaitingBeforeValveMove;
|
||||
}
|
||||
else
|
||||
{
|
||||
opState = OpState.StartingFlowRegulation;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//opState = OpState.ResendCommand;
|
||||
}
|
||||
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.ResendCommand)
|
||||
{
|
||||
SendStartCommand();
|
||||
opState = OpState.StartingTest;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.WaitingBeforeValveMove)
|
||||
{
|
||||
if (StateMachine.Time - delayStartTime >= delayBeforeFlowRegulation)
|
||||
{
|
||||
opState = OpState.StartingFlowRegulation;
|
||||
}
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.StartingFlowRegulation)
|
||||
{
|
||||
///
|
||||
/// Done once, issues an appropriate ValveMove(...) command
|
||||
///
|
||||
if ((qFrom >= qTo) || (qFrom > maximalFlow) || (qTo <= 0))
|
||||
{
|
||||
return Event.OpArgumentError;
|
||||
}
|
||||
|
||||
log.InfoFormat("Run(): rv#={0} flowMtr#={1} TARGET: flowLo={2} flowHi={3}",
|
||||
regValve.Idx1, flowMeter.Idx1, qFrom, qTo);
|
||||
|
||||
double freqLo = 2000 * qFrom / flowMeter.NominalFlow;
|
||||
double freqHi = 2000 * qTo / flowMeter.NominalFlow;
|
||||
uniCB.SetFlow(false, regValve.Idx1, 2000 * qFrom / flowMeter.NominalFlow, 2000 * qTo / flowMeter.NominalFlow);
|
||||
opState = OpState.OpCompleted;
|
||||
return Event.None;
|
||||
}
|
||||
else if (opState == OpState.OpCompleted)
|
||||
{
|
||||
return Event.MeasurementStarted;
|
||||
}
|
||||
|
||||
return Event.None;
|
||||
}
|
||||
|
||||
/// <summary>Stop this operation</summary>
|
||||
public void Stop() { }
|
||||
}
|
||||
}
|
||||
@@ -472,11 +472,12 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
///
|
||||
public IOperation SetFlowOp(double flowLimLo, double flowLimHi, TBF.Boxes.DoubleBox measuredFlow, int timeout)
|
||||
{
|
||||
return Devices.RegValve.SetFlowOp(Devices.FlowMeter,flowLimLo, flowLimHi, measuredFlow, timeout);
|
||||
return Devices.RegValve.SetFlowOp(Devices.FlowMeter, flowLimLo, flowLimHi, measuredFlow, timeout);
|
||||
}
|
||||
|
||||
public IOperation StopFlowRegulationOp()
|
||||
{
|
||||
Stop(false);
|
||||
//scheduledActionQueue.Enqueue(Action.Stop());
|
||||
return null;
|
||||
}
|
||||
@@ -490,6 +491,93 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
/// <returns>Operation</returns>
|
||||
public IOperation StartTestOp(Test test, int iParam = 0, double dParam1 = 0, double dParam2 = 0)
|
||||
{
|
||||
|
||||
/// Get total number of pulses
|
||||
int totalPulses = Convert.ToInt32(Math.Round(test.Volume / devices.FlowMeter.LtrPerPulse));
|
||||
|
||||
/// Get method class string
|
||||
string methodClass;
|
||||
if (!StateMachine.TestMethod2Class.TryGetValue(test.Name, out methodClass)) return null;
|
||||
|
||||
if (methodClass.Contains("TestMethods.Adjustment."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, TestMethods.Synchro, test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.CombinedWithDetection."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.Synchro), dParam1, dParam2, totalPulses);
|
||||
}
|
||||
if (methodClass == "TestMethods.DiverterTest")
|
||||
{
|
||||
if (iParam == 0) return null;
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.Synchro), test.Qfrom, test.Qto, totalPulses / iParam);
|
||||
}
|
||||
if (methodClass == "TestMethods.Dummy")
|
||||
{
|
||||
}
|
||||
if (methodClass == "TestMethods.Endurance")
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, TestMethods.Synchro, test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FixedStart."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, TestMethods.Synchro, test.Qfrom, test.Qto, 2 * totalPulses, 10);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FixedStartAdvanced."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, TestMethods.Synchro, test.Qfrom, test.Qto, 2 * totalPulses, 10);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FixedStartDefferedEval."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, TestMethods.Synchro, test.Qfrom, test.Qto, 2 * totalPulses, 10);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FixedStartMassCollDeferredEval."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.Synchro), test.Qfrom, test.Qto, 2 * totalPulses, 10);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FixedStartMassCollection."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.FixedStart), test.Qfrom, test.Qto, 2 * totalPulses, 10);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FixedStartTankCollection."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.Synchro), test.Qfrom, test.Qto, (totalPulses * 5 / 4), 10);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FlyingStart."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, TestMethods.Synchro, test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FlyingStartFirstRepetWithMassColl."))
|
||||
{
|
||||
TestMethods tm = (iParam == 1) ? (TestMethods.Diverter | TestMethods.Synchro) : TestMethods.Synchro;
|
||||
return new StartMeasurementOp(this, devices, tm, test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FlyingStartMassCollComparative."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.Synchro), test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FlyingStartMassCollection."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.Synchro), test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FlyingStartMassCollProlonged."))
|
||||
{
|
||||
if (iParam == 0) return null;
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.Synchro), test.Qfrom, test.Qto, totalPulses, iParam);
|
||||
}
|
||||
if (methodClass.Contains("TestMethods.FlyingStartTankCollection."))
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, (TestMethods.Diverter | TestMethods.Synchro), test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
if (methodClass == "TestMethods.PulsesTest")
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, TestMethods.Synchro, test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
if (methodClass == "TestMethods.PulsesTestManual")
|
||||
{
|
||||
return new StartMeasurementOp(this, devices, TestMethods.Synchro, test.Qfrom, test.Qto, totalPulses);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user