Prolonged method fixed, ver. 3.1.1603

This commit is contained in:
Milan Hanajik
2021-03-23 08:50:40 +01:00
parent ef96c06328
commit 061ab99486
19 changed files with 165 additions and 272 deletions
@@ -519,21 +519,6 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged
Bridge.OnActivity(this, Strings.Measuring_the_weight);
//------------------------------------------------
if (test.TimeFlow2Mass > 0)
{
State.Create(string.Format("{0}({1}) : Waiting before 1st mass measurement", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(new Operations.TimerOp(test.TimeFlow2Mass))
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
}
while (!e.Contains(Event.TimerExpired));
}
LogProcessDataTestInfo(processDataLogger, test.Procedure.Name, test.Name);
if (heatMetersPath == null) LogProcessDataHeader(processDataLogger, "Start mass");
@@ -543,7 +528,7 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged
.AddOperation(checkUiOp)
.AddOperations(cameraMeasurementOps)
.AddOperations(readTempPressOps)
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.MassRepeats, test.MassSpread, test.MassMethod))
.AddOperation(scale.ReadStableMassOp(ref StartMass, test.TimeFlow2Mass, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(new Operations.TimerOp(StableMassMsrmntTimeoutSec))
.AddOperation(processDataLoggingOp)
.EnterState();
@@ -574,31 +559,19 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged
/// Measurement loop preparation
int estimtdEndTime = StateMachine.Time + (int)test.TestTime;
int remainingTime;
StartNewStatistics(StateMachine.Time, BatchRslts.Batch.BatchNr, test.Name, repetitionNr, 0);
bool isTestPart2Completed = false;
var prolongedTest = cBrd.FlyingStartStopTestOp(test, test.Qfrom, test.Qto, targetTotalPulses, true, true, targetMassPulses);
IList<IOperation> testInProgressOps = new List<IOperation>();
testInProgressOps.Add(checkUiOp);
foreach (var op in readTempPressOps)
testInProgressOps.Add(op);
foreach (var op in cameraMeasurementOps)
testInProgressOps.Add(op);
testInProgressOps.Add(prolongedTest); /// Event.MeasurementCompleted
testInProgressOps.Add(processDataLoggingOp);
IList<IOperation> testCompletedOps = new List<IOperation>();
testCompletedOps.Add(checkUiOp);
foreach (var op in readTempPressOps)
testCompletedOps.Add(op);
testCompletedOps.Add(processDataLoggingOp);
///
/// Measurement loop - 1st part
///
State.Create(string.Format("{0}({1}) : Starting the test", test.Method, test.Name))
.AddOperations(testInProgressOps)
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(cameraMeasurementOps)
.AddOperation(prolongedTest)
.AddOperation(processDataLoggingOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
@@ -607,179 +580,56 @@ namespace TBF.Rig.TestMethods.FlyingStartMassCollProlonged
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
/// Proceed to 2nd part of the test when diverter turns back to sink, 'Next' button can be used in Debug version
}
/// Proceed to 2nd part of test when diverter turns back to sink, 'Next' button can be used in Debug version
while (!e.Contains(Event.TestPart2InProgress) && !e.Contains(Event.Next));
///
/// Waiting before the 2nd mass measurement
///
bool waitingBeforeEndMassMeasurementCompleted = false;
IOperation stop2MassTimerOp = new Operations.TimerOp(test.TimeStop2Mass);
do {
State.Create(string.Format("{0}({1}) : Waiting before the 2nd mass measurement", test.Method, test.Name))
.AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps)
.AddOperation(stop2MassTimerOp)
.EnterState();
if (!isTestPart2Completed)
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true;
waitingBeforeEndMassMeasurementCompleted = (e.Contains(Event.TimerExpired) && e.Contains(Event.BalanceDone));
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
}
while (!isTestPart2Completed && !waitingBeforeEndMassMeasurementCompleted);
}
else
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
waitingBeforeEndMassMeasurementCompleted = (e.Contains(Event.TimerExpired) && e.Contains(Event.BalanceDone));
}
while (!waitingBeforeEndMassMeasurementCompleted);
}
}
while (!waitingBeforeEndMassMeasurementCompleted);
if (heatMetersPath == null)
LogProcessDataHeader(processDataLogger, "End mass");
else
LogProcessDataHeaderHeatMeters(processDataLogger, "End mass");
///
/// Measuring the end mass
/// 2nd part of the test and simultaneous measurement the end mass
///
Bridge.OnActivity(this, Strings.Measuring_the_weight);
IOperation readStableMassOp = scale.ReadStableMassOp(ref EndMass, test.MassRepeats, test.MassSpread, test.MassMethod);
IOperation massMsrmntTimerOp = new Operations.TimerOp(StableMassMsrmntTimeoutSec);
bool measuringEndMassCompleted = false;
do
{
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps)
.AddOperation(readStableMassOp)
.AddOperation(massMsrmntTimerOp)
.EnterState();
if (!isTestPart2Completed)
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.TimerExpired))
{
Bridge.OnError(this, Strings.Mass_measurement_timeout);
retVal = Event.RecoverableError;
goto stopTest;
}
if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true;
measuringEndMassCompleted = e.Contains(Event.BalanceDone);
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime, false);
}
while (!isTestPart2Completed && !measuringEndMassCompleted);
}
else
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.TimerExpired))
{
Bridge.OnError(this, Strings.Mass_measurement_timeout);
retVal = Event.RecoverableError;
goto stopTest;
}
measuringEndMassCompleted = e.Contains(Event.BalanceDone);
}
while (!measuringEndMassCompleted);
}
}
while (!measuringEndMassCompleted);
///
tMass2 = StateMachine.Time;
log.WarnFormat("End mass = {0}kg", EndMass);
TestEndTime = DateTime.Now;
if (test.DoDrainingAfter)
{
///
/// Draining after the 2nd mass measurement enabled, empty the tank
///
IOperation setValvesOp = cBrd.SetValvesOp(scale.DrainValve, null);
bool openingDrainValveCompleted = false;
do {
State.Create(string.Format("{0}({1}) : Open the drain valve", test.Method, test.Name))
.AddOperations(isTestPart2Completed ? testCompletedOps : testInProgressOps)
.AddOperation(setValvesOp)
.EnterState();
if (!isTestPart2Completed)
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.TestCompleted)) isTestPart2Completed = true;
openingDrainValveCompleted = !e.Contains(Event.ValvesBusy);
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
}
while (!isTestPart2Completed && !openingDrainValveCompleted);
}
else
{
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
openingDrainValveCompleted = !e.Contains(Event.ValvesBusy);
}
while (!openingDrainValveCompleted);
}
}
while (!openingDrainValveCompleted);
}
if (!isTestPart2Completed)
{
///
/// Measurement loop - 2nd part, diverter is in state 'To sink'
///
State.Create(string.Format("{0}({1}) : Reading watermeters", test.Method, test.Name))
.AddOperations(testInProgressOps)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
}
while (!e.Contains(Event.TestCompleted) && !e.Contains(Event.Next)); /// Quit the measurement loop when there is Event.MeasurementCompleted
/// 'Next' button can be used in Debug version
}
test_completed:
StopRecordingStatistics();
State.Create(string.Format("{0}({1}) : Stopping flow regulation", test.Method, test.Name))
State.Create(string.Format("{0}({1}) : Measuring the end mass", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperation(cBrd.StopFlowRegulationOp())
.AddOperations(cameraMeasurementOps)
.AddOperation(prolongedTest)
.AddOperation(scale.ReadStableMassOp(ref EndMass, test.TimeStop2Mass, test.MassMethod, test.MassRepeats, test.MassSpread))
.AddOperation(processDataLoggingOp)
.EnterState();
do {
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; }
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
/// Continue in 2nd part of the test when mass measurement is completed, 'Next' button can be used in Debug version
}
while (!e.Contains(Event.FlowRegulationStopped));
while (!e.Contains(Event.BalanceDone) && !e.Contains(Event.ScaleTimeout) && !e.Contains(Event.Next));
///
/// 2nd part of the test and optional opening of the drain valve
///
State.Create(string.Format("{0}({1}) : 2nd part of the test is running", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperations(readTempPressOps)
.AddOperations(cameraMeasurementOps)
.AddOperation(prolongedTest)
.AddOperation(test.DoDrainingAfter ? cBrd.SetValvesOp(scale.DrainValve, null) : null)
.AddOperation(processDataLoggingOp)
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; }
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
DoInsideMeasurementLoop(cBrd, heatMetersTestParams, test, repetitionNr, estimtdEndTime);
}
while (!e.Contains(Event.TestCompleted) && !e.Contains(Event.Next));
StopRecordingStatistics();
///
/// (Berlin:) Water is stopped immediately after the test and before the 2nd mass measurement in case: