Uni.FlyingStartStopTestOp merged with Uni.FlyingStartStopTestWithDivOp, IAdvancedControlBoard. ver. 3.1.1601

This commit is contained in:
Milan Hanajik
2021-03-22 09:08:00 +01:00
parent 747195fc10
commit 8f5291332f
14 changed files with 142 additions and 280 deletions
@@ -10,33 +10,54 @@ namespace TBF.Rig.ControlBoard.Uni
public class FlyingStartStopTestOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(FlyingStartStopTestOp));
public override string ToString() { return string.Format("FlyingStartStopTestOp()"); }
public override string ToString() { return string.Format("FlyingStartStopTestWithDivOp()"); }
/// Arguments of the constructor
readonly UniCB uniCB;
readonly TBF.Rig.Uni.RegValve.RegValve regV;
readonly TBF.Rig.Uni.FlowMeter.FlowMeter flowMeter;
readonly double qFrom;
readonly double qTo;
readonly int pulsesCount; /// Number of reference pulses for a complete test
readonly int pulsesCount; /// Number of reference pulses for a complete test
readonly bool withDiverter;
readonly bool isProlonged;
readonly int massPulsesCount; /// Number of reference pulses for mass collection
readonly bool readDivTransition;
readonly TBF.Rig.Uni.RegValve.RegValve regV;
readonly TBF.Rig.Uni.FlowMeter.FlowMeter flowMeter;
readonly int diverterNr;
readonly int divThreshold;
/// <summary>
/// Operation for a Flying start-stop test (constructor)
/// Operation for a Flying start-stop test with a diverter (constructor)
///
/// Events: OpArgumentError .... invalid arguments, test cannot be started
/// StartingTest ....... starting a test
/// TestInProgress ..... test was successfully started, test is running
/// TestCompleted ...... test was successfully completed
/// Error .............. unspecified error while running a test
/// Events: OpArgumentError ...... invalid arguments, test cannot be started
/// StartingTest ......... starting a test
/// TestInProgress ....... test was successfully started, test is running
/// TestPart1InProgress .. test was successfully started, part1 of a prolonged test (collecting water) is running
/// TestPart2InProgress .. first part of a prolonged test was successfully completed, part2 is in progress.
/// Prolonged method only: (massPulsesCount GT 0) and (massPulsesCount LT pulsesCount)
/// TestCompleted ........ test was successfully completed
/// Error ................ unspecified error while running a test
/// </summary>
/// <param name="cb">Control board component</param>
/// <param name="devices">Components used by the test</param>
/// <param name="devices">Components used by the test</param>
/// <param name="qFrom">Flow lower limit</param>
/// <param name="qTo">Flow upper limit</param>
/// <param name="pulsesCount">Test duration - number of reference flow meter pulses</param>
public FlyingStartStopTestOp(UniCB cb, OutputPath devices, double qFrom, double qTo, int pulsesCount)
/// <param name="withDiverter">true = Test with diverter</param>
/// <param name="isProlonged">true = Prolonged test with diverter</param>
/// <param name="massPulsesCount">Test part 1 duration - number of reference flow meter pulses<</param>
/// <param name="readDivTransition">true = Read diverter transition</param>
public FlyingStartStopTestOp(UniCB cb, OutputPath devices, double qFrom, double qTo, int pulsesCount,
bool withDiverter, bool isProlonged, int massPulsesCount, bool readDivTransition)
{
this.uniCB = cb;
this.qFrom = qFrom;
this.qTo = qTo;
this.pulsesCount = pulsesCount;
this.withDiverter = withDiverter;
this.isProlonged = withDiverter && isProlonged;
this.massPulsesCount = massPulsesCount;
this.readDivTransition = withDiverter && readDivTransition;
flowMeter = devices.FlowMeter as TBF.Rig.Uni.FlowMeter.FlowMeter;
if (flowMeter == null) throw new ArgumentNullException("Invalid flow meter");
@@ -44,18 +65,23 @@ namespace TBF.Rig.ControlBoard.Uni
regV = devices.RegValve as TBF.Rig.Uni.RegValve.RegValve;
if (regV == null) throw new ArgumentNullException("Invalid regulation valve");
this.qFrom = qFrom;
this.qTo = qTo;
this.pulsesCount = pulsesCount;
diverterNr = (withDiverter && devices.Diverter is TBF.Rig.Uni.Diverter.Diverter)
? (devices.Diverter as TBF.Rig.Uni.Diverter.Diverter).DiverterNr : 0;
divThreshold = (withDiverter && devices.Diverter is TBF.Rig.Uni.Diverter.Diverter)
? (devices.Diverter as TBF.Rig.Uni.Diverter.Diverter).StartThreshold : 0;
log.Debug(this.ToString());
}
/// Internal state of this operation
/// Internal states of this operation
enum OpState
{
StartingTest,
ReadingDivTransition,
TestInProgress,
TestPart1InProgress, /// prolonged test only
TestPart2InProgress, /// prolonged test only
TestCompleted,
}
@@ -66,10 +92,10 @@ namespace TBF.Rig.ControlBoard.Uni
/// </summary>
public void Start()
{
log.InfoFormat("Op.Start() RV#={0} Et#={1} Qfrom={2} Qto={3}", regV.Idx1, flowMeter.Idx1, qFrom, qTo);
log.InfoFormat("Op.Start() RV#={0} Et#={1} Div#={2} Qfrom={3} Qto={4}", regV.Idx1, flowMeter.Idx1, diverterNr, qFrom, qTo);
/// Start the test (and the flow measurement)
uniCB.StartTest(false, flowMeter.Idx1, 0, 0, true, false, false, false, pulsesCount, 0);
uniCB.StartTest(false, flowMeter.Idx1, diverterNr, divThreshold, true, withDiverter, false, isProlonged, pulsesCount, massPulsesCount);
opState = OpState.StartingTest;
}
@@ -78,12 +104,15 @@ namespace TBF.Rig.ControlBoard.Uni
/// Run this operation
/// </summary>
/// <returns>
/// Event.OpArgumentError .... invalid arguments, test cannot be started
/// Event.StartingTest ....... starting a test
/// Event.TestInProgress ..... test was successfully started, test is running
/// Event.TestCompleted ...... test was successfully completed
/// Event.Error .............. unspecified error while running a test
/// </returns>
/// Event.OpArgumentError ...... invalid arguments, test cannot be started
/// Event.StartingTest ......... starting a test
/// Event.TestInProgress ....... test was successfully started, test is running
/// Event.TestPart1InProgress .. test was successfully started, part1 of a prolonged test (collecting water) is running
/// Event.TestPart2InProgress .. first part of a prolonged test was successfully completed, part2 is in progress.
/// Prolonged method only: (massPulsesCount GT 0) and (massPulsesCount LT pulsesCount)
/// Event.TestCompleted ........ test was successfully completed
/// Event.Error ................ unspecified error while running a test
/// </returns>
public Event Run()
{
log.DebugFormat("Op.Run() opState={0}", opState);
@@ -96,12 +125,16 @@ namespace TBF.Rig.ControlBoard.Uni
{
return Event.OpArgumentError; /// Invalid qFrom, qTo
}
if (isProlonged && (massPulsesCount <= 0 || massPulsesCount >= pulsesCount))
{
return Event.OpArgumentError; /// Invalid qFrom, qTo
}
if (!flowMeter.MsrmntAvailable || /// Flow measurement not started yet
(uniCB.State & (ulong)StatusP.ReadingCounters) == 0 || /// Test was not started yet
uniCB.RefFrequency == 0) /// Measured flow is 0
{
return Event.StartingTest; /// Flow regulation cannot be started
return Event.StartingTest; /// Flow regulation cannot be started
}
/// Start flow regulation
@@ -112,8 +145,17 @@ namespace TBF.Rig.ControlBoard.Uni
uniCB.SetFlow(false, regV.Idx1, 2000 * reqFlowLo / flowMeter.NominalFlow,
2000 * reqFlowHi / flowMeter.NominalFlow);
opState = OpState.TestInProgress;
return Event.TestInProgress;
opState = readDivTransition ? OpState.ReadingDivTransition
: (isProlonged ? OpState.TestPart1InProgress : OpState.TestInProgress);
return isProlonged ? Event.TestPart1InProgress : Event.TestInProgress;
case OpState.ReadingDivTransition:
/// Read diverter transition data
uniCB.ReadDiverterTransition(false, diverterNr);
opState = isProlonged ? OpState.TestPart1InProgress : OpState.TestInProgress;
return isProlonged ? Event.TestPart1InProgress : Event.TestInProgress;
case OpState.TestInProgress:
@@ -124,11 +166,30 @@ namespace TBF.Rig.ControlBoard.Uni
opState = OpState.TestCompleted;
return Event.TestCompleted;
case OpState.TestPart1InProgress:
if ((uniCB.State & (ulong)StatusP.DirectionOfDiverter) != 0)
{
return Event.TestPart1InProgress; /// Test was not completed yet
}
opState = OpState.TestPart2InProgress;
return Event.TestPart2InProgress;
case OpState.TestPart2InProgress:
if ((uniCB.State & (ulong)StatusP.TestCompleted) == 0)
{
/// Test was not completed yet
return Event.TestPart2InProgress;
}
opState = OpState.TestCompleted;
return Event.TestCompleted;
case OpState.TestCompleted:
default:
return Event.TestCompleted;
}
}
}
/// <summary>
/// Stop this operation
@@ -1,189 +0,0 @@
///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using log4net;
using TBF.Rig.GenericDevices;
namespace TBF.Rig.ControlBoard.Uni
{
public class FlyingStartStopTestWithDivOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(FlyingStartStopTestWithDivOp));
public override string ToString() { return string.Format("FlyingStartStopTestWithDivOp()"); }
/// Arguments of the constructor
readonly UniCB uniCB;
readonly TBF.Rig.Uni.RegValve.RegValve regV;
readonly TBF.Rig.Uni.FlowMeter.FlowMeter flowMeter;
readonly TBF.Rig.Uni.Diverter.Diverter div;
readonly double qFrom;
readonly double qTo;
readonly int pulsesCount; /// Number of reference pulses for a complete test
readonly int massPulsesCount; /// Number of reference pulses for mass collection
readonly bool readDivTransition;
readonly bool isProlongedTest;
/// <summary>
/// Operation for a Flying start-stop test with a diverter (constructor)
///
/// Events: OpArgumentError ...... invalid arguments, test cannot be started
/// StartingTest ......... starting a test
/// TestInProgress ....... test was successfully started, test is running
/// TestPart2InProgress .. first part when water is diverted to a tank was successfully completed, part2 in progress,
/// prolonged method only: (massPulsesCount GT 0) and (massPulsesCount LT pulsesCount)
/// TestCompleted ........ test was successfully completed
/// Error ................ unspecified error while running a test
/// </summary>
/// <param name="cb">Control board component</param>
/// <param name="devices">Components used by the test</param>
/// <param name="qFrom">Flow lower limit</param>
/// <param name="qTo">Flow upper limit</param>
/// <param name="pulsesCount">Test duration - number of reference flow meter pulses</param>
/// <param name="massPulsesCount">Test part 1 duration - number of reference flow meter pulses<</param>
public FlyingStartStopTestWithDivOp(UniCB cb, OutputPath devices, double qFrom, double qTo,
int pulsesCount, int massPulsesCount, bool readDivTransition)
{
this.uniCB = cb;
flowMeter = devices.FlowMeter as TBF.Rig.Uni.FlowMeter.FlowMeter;
if (flowMeter == null) throw new ArgumentNullException("Invalid flow meter");
regV = devices.RegValve as TBF.Rig.Uni.RegValve.RegValve;
if (regV == null) throw new ArgumentNullException("Invalid regulation valve");
div = devices.Diverter as TBF.Rig.Uni.Diverter.Diverter;
if (div == null) throw new ArgumentNullException("Invalid diverter");
this.qFrom = qFrom;
this.qTo = qTo;
this.pulsesCount = pulsesCount;
this.massPulsesCount = massPulsesCount;
this.readDivTransition = readDivTransition;
this.isProlongedTest = (0 < massPulsesCount) && (massPulsesCount < pulsesCount);
log.Debug(this.ToString());
}
/// Internal states of this operation
enum OpState
{
StartingTest,
ReadingDivTransition,
TestInProgress,
TestPart1InProgress, /// prolonged test only
TestPart2InProgress, /// prolonged test only
TestCompleted,
}
OpState opState;
/// <summary>
/// Start this operation
/// </summary>
public void Start()
{
log.InfoFormat("Op.Start() RV#={0} Et#={1} Div#={2} Qfrom={3} Qto={4}", regV.Idx1, flowMeter.Idx1, div.DiverterNr, qFrom, qTo);
/// Start the test (and the flow measurement)
uniCB.StartTest(false, flowMeter.Idx1, div.DiverterNr, div.StartThreshold, true, true, false, isProlongedTest, pulsesCount, massPulsesCount);
opState = OpState.StartingTest;
}
/// <summary>
/// Run this operation
/// </summary>
/// <returns>
/// Event.OpArgumentError ...... invalid arguments, test cannot be started
/// Event.StartingTest ......... starting a test
/// Event.TestInProgress ....... test was successfully started, test is running
/// Event.TestPart1InProgress .. first part when water is diverted to a tank was successfully completed, part2 in progress,
/// Event.TestPart2InProgress .. first part when water is diverted to a tank was successfully completed, part2 in progress,
/// prolonged method only: (massPulsesCount GT 0) and (massPulsesCount LT pulsesCount)
/// Event.TestCompleted ........ test was successfully completed
/// Event.Error ................ unspecified error while running a test
/// </returns>
public Event Run()
{
log.DebugFormat("Op.Run() opState={0}", opState);
switch (opState)
{
case OpState.StartingTest:
if (qFrom < 0 || qFrom >= qTo || qTo > 1.25 * flowMeter.NominalFlow)
{
return Event.OpArgumentError; /// Invalid qFrom, qTo
}
if (!flowMeter.MsrmntAvailable || /// Flow measurement not started yet
(uniCB.State & (ulong)StatusP.ReadingCounters) == 0 || /// Test was not started yet
uniCB.RefFrequency == 0) /// Measured flow is 0
{
return Event.StartingTest; /// Flow regulation cannot be started
}
/// Start flow regulation
double reqFlowAve = (qFrom + qTo) / 2;
double reqFlowLo = (0.7 * qFrom) + (0.3 * reqFlowAve); /// Move the lower limit 15% of the range up
double reqFlowHi = (0.7 * qTo) + (0.3 * reqFlowAve); /// Move the upper limit 15% of the range down
///
uniCB.SetFlow(false, regV.Idx1, 2000 * reqFlowLo / flowMeter.NominalFlow,
2000 * reqFlowHi / flowMeter.NominalFlow);
opState = readDivTransition ? OpState.ReadingDivTransition
: (isProlongedTest ? OpState.TestPart1InProgress : OpState.TestInProgress);
return isProlongedTest ? Event.TestPart1InProgress : Event.TestInProgress;
case OpState.ReadingDivTransition:
/// Read diverter transition data
uniCB.ReadDiverterTransition(false, div.DiverterNr);
opState = isProlongedTest ? OpState.TestPart1InProgress : OpState.TestInProgress;
return isProlongedTest ? Event.TestPart1InProgress : Event.TestInProgress;
case OpState.TestInProgress:
if ((uniCB.State & (ulong)StatusP.TestCompleted) == 0)
{
return Event.TestInProgress; /// Test was not completed yet
}
opState = OpState.TestCompleted;
return Event.TestCompleted;
case OpState.TestPart1InProgress:
if ((uniCB.State & (ulong)StatusP.DirectionOfDiverter) != 0)
{
return Event.TestPart1InProgress; /// Test was not completed yet
}
opState = OpState.TestPart2InProgress;
return Event.TestPart2InProgress;
case OpState.TestPart2InProgress:
if ((uniCB.State & (ulong)StatusP.TestCompleted) == 0)
{
/// Test was not completed yet
return Event.TestPart2InProgress;
}
opState = OpState.TestCompleted;
return Event.TestCompleted;
case OpState.TestCompleted:
default:
return Event.TestCompleted;
}
}
/// <summary>
/// Stop this operation
/// </summary>
public void Stop()
{
log.Info("Op.Stop()");
uniCB.Stop(false);
}
}
}
+8 -18
View File
@@ -17,7 +17,7 @@ using TBF.UiBridge;
namespace TBF.Rig.ControlBoard.Uni
{
public class UniCB : ComponentBase, IControlBoard, SchematicDrawing.IDrawingItCmpntWithMeasuredVal
public class UniCB : ComponentBase, IAdvancedControlBoard, SchematicDrawing.IDrawingItCmpntWithMeasuredVal
{
private static readonly ILog log = LogManager.GetLogger(typeof(UniCB));
public override string ToString() { return string.Format("CBoard({0})", cbCfg != null ? cbCfg.ToString(-1) : string.Empty); }
@@ -120,9 +120,8 @@ namespace TBF.Rig.ControlBoard.Uni
/// Depends on the control board configuration
ulong valvesToInvert; /// From configurations of valve and pump components. Inversion is applied when creating
/// a message to be sent by serial port
UInt128 displayedRoute; /// A route displayed on the screen (inversions are not applied)
UInt128 bitsChangedByUI; /// Ones in this word indicate which valves/pumpes were changed in UI by mouse clicks
UInt128 displayedRoutePlusUI; /// A route displayed on the screen plus the modifications from UI (inversions are not applied)
UInt128 bitsChangedByUI; /// Ones in this word indicate which valves/pumpes were changed in UI by mouse clicks
UInt128 outputLatch; /// A copy of data sent to physical digital outputs (inversions are not applied)
///
/// 128-bit word representing the current state of all valves and pumps (inversions are not applied)
@@ -374,12 +373,12 @@ namespace TBF.Rig.ControlBoard.Uni
route = (route & ~bitsChangedByUI) | (displayedRoutePlusUI & bitsChangedByUI);
bitsChangedByUI = 0;
}
displayedRoute = route;
displayedRoutePlusUI = route;
bitsChangedByUI = 0;
}
ProcessData.UpdateMeasuredValuesAndSetpoints();
Bridge.OnStateMachineTick(this, new StateMachineTickEventArgs(displayedRoute, ProcessData.MsrmntAvailableFlags, ProcessData.MeasuredValues,
Bridge.OnStateMachineTick(this, new StateMachineTickEventArgs(route, ProcessData.MsrmntAvailableFlags, ProcessData.MeasuredValues,
ProcessData.AltStrings, ProcessData.Setpoints));
/// Make sure the serial port is open
@@ -543,22 +542,13 @@ namespace TBF.Rig.ControlBoard.Uni
}
/// <summary>
/// Start a flying start-stop test
/// Start a flying start-stop test (opitonally with a diverter, optionally prolonged)
/// </summary>
/// <returns>Operation running a test</returns>
public IOperation FlyingStartStopTestOp(Test test, double qFrom, double qTo, int pulsesCount)
public IOperation FlyingStartStopTestOp(Test test, double qFrom, double qTo, int pulsesCount, bool withDiverter = false,
bool isProlonged = false, int massPulsesCount = 0, bool readDivTransition = true)
{
return new FlyingStartStopTestOp(this, devices, qFrom, qTo, pulsesCount);
}
/// <summary>
/// Start a flying start-stop test with diverter
/// </summary>
/// <returns>Operation running a test</returns>
public IOperation FlyingStartStopTestWithDivOp(Test test, double qFrom, double qTo, int pulsesCount,
int massPulsesCount = 0, bool readDivTransition = true)
{
return new FlyingStartStopTestWithDivOp(this, devices, qFrom, qTo, pulsesCount, massPulsesCount, readDivTransition);
return new FlyingStartStopTestOp(this, devices, qFrom, qTo, pulsesCount, withDiverter, isProlonged, massPulsesCount, readDivTransition);
}
public IOperation ReadDiverterTransitionOp(bool isStart, Sequences.Statistics plotter, int batchNr, string testName, int repetition)