2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2017-01-14 15:11:11 +00:00
|
|
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using log4net;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
using TBF.UiBridge;
|
2017-04-06 10:32:46 +00:00
|
|
|
|
using System.IO;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-01-14 15:11:11 +00:00
|
|
|
|
namespace TBF.BenchControl.TestMethods.RoiDetection
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
public class RoiDetectionSeq : Sequences.SequenceBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(RoiDetectionSeq));
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-06 10:32:46 +00:00
|
|
|
|
public IList<Event> Execute(Test test, GenericDevices.ICameraDisplay display, bool outerLoopMode, int outerLoopCounter)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
Elde.ControlBoardDev cBrd = StateMachine.ControlBoard;
|
|
|
|
|
|
|
2014-09-26 15:48:55 +00:00
|
|
|
|
IList<Event> e = new List<Event>(); /// Events from currently running operations
|
2014-09-24 17:58:05 +00:00
|
|
|
|
Event retVal = Event.Done;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-09-27 14:09:23 +00:00
|
|
|
|
/// Operations
|
|
|
|
|
|
checkUiOp = new Operations.CheckUIOp(true);
|
2014-09-24 17:58:05 +00:00
|
|
|
|
processDataLoggingOp = null;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-01-16 14:51:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// LtrPerRefPulse and totalPulses are only to make time estimates
|
|
|
|
|
|
LtrPerRefPulse = outPath.FlowMeter.LtrPerPulse; /// [ltr/pulse], nominal flow in [m3/h]
|
|
|
|
|
|
/// Notes:
|
|
|
|
|
|
/// float timeHr = volumeLtr / (1000.0f * targetFlow);
|
|
|
|
|
|
/// float timeSec = 3600.0f * timeHr;
|
|
|
|
|
|
/// int refPulses = (int)(timeSec * (2000.0f * targetFlow / pOut.FlowMeter.NominalFlow));
|
|
|
|
|
|
int totalPulses = (int)(test.Volume / LtrPerRefPulse + 0.5f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int repetitionNr = outerLoopMode ? outerLoopCounter : 1; /// First test: repetitionNr=1
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-09-24 17:58:05 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
//====================================
|
|
|
|
|
|
// Transition or SetRoute - Start
|
|
|
|
|
|
//====================================
|
2015-05-22 08:29:56 +00:00
|
|
|
|
switch (Transition(transitionBefore, TransitionContext.BeforeTest))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-01-16 14:51:34 +00:00
|
|
|
|
case Event.Error: { retVal = Event.Error; goto stopTest; }
|
|
|
|
|
|
case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-16 14:51:34 +00:00
|
|
|
|
//====================
|
|
|
|
|
|
// Start the test
|
|
|
|
|
|
//====================
|
|
|
|
|
|
Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, totalPulses));
|
|
|
|
|
|
string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr);
|
|
|
|
|
|
TestStartTime = DateTime.Now;
|
|
|
|
|
|
TestProgressEventArgs.SetEstimatedTimes(new int[] { 1, 1, 1, 30, Convert.ToInt32(test.TstTime) + 15, 0, 0 });
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.JustStarted));
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
//------------------------------------------------
|
2017-01-16 14:51:34 +00:00
|
|
|
|
Bridge.OnActivity(this, Strings.Starting_the_pump);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
//------------------------------------------------
|
2017-01-16 14:51:34 +00:00
|
|
|
|
///
|
2015-01-17 03:52:42 +00:00
|
|
|
|
if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower);
|
2014-09-09 07:14:47 +00:00
|
|
|
|
State.Create("RoiDetection : Starting the pump")
|
2014-07-28 07:54:35 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
2017-01-16 14:51:34 +00:00
|
|
|
|
.AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp())
|
|
|
|
|
|
.AddOperation(inPath.Pump != null ? cBrd.SetValvesOp(inPath.Pump, null) : null)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2017-01-16 14:51:34 +00:00
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting));
|
|
|
|
|
|
|
|
|
|
|
|
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
|
|
|
|
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2017-01-16 14:51:34 +00:00
|
|
|
|
while (e.Contains(Event.ValvesBusy));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-01-16 14:51:34 +00:00
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Setting_the_flow);
|
|
|
|
|
|
//------------------------------------------------
|
2014-07-28 07:54:35 +00:00
|
|
|
|
State.Create("RoiDetection : Setting the flow")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
2015-12-20 19:48:50 +00:00
|
|
|
|
.AddOperation(outPath.RegulValve.SetFlowOp(outPath.FlowMeter, test.Qfrom, test.Qto, outPath.PidCoef, RefFlow, 600)) /// timeout = 10 min.
|
2014-07-28 07:54:35 +00:00
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2017-01-16 14:51:34 +00:00
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting));
|
2014-09-24 17:58:05 +00:00
|
|
|
|
|
2017-01-16 14:51:34 +00:00
|
|
|
|
if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; }
|
|
|
|
|
|
if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; }
|
2015-01-12 04:56:19 +00:00
|
|
|
|
if (e.Contains(Event.RegulValveTimeOut))
|
|
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnError(this, Strings.Timeout);
|
|
|
|
|
|
retVal = Event.Done;
|
|
|
|
|
|
goto stopTest;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (e.Contains(Event.Next)) goto flow_set;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.FlowReached));
|
|
|
|
|
|
|
|
|
|
|
|
flow_set:
|
2017-01-16 14:51:34 +00:00
|
|
|
|
|
2014-08-01 06:36:17 +00:00
|
|
|
|
int time = StateMachine.Time;
|
2016-10-07 14:22:36 +00:00
|
|
|
|
double currentFlow = RefFlow.Val;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-04-06 10:32:46 +00:00
|
|
|
|
string[] imageNames = new string[sensPath.RegisterReaders.Length];
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
|
2017-01-16 14:51:34 +00:00
|
|
|
|
{
|
2017-04-06 10:32:46 +00:00
|
|
|
|
GenericDevices.IRoi roi = sensPath.RegisterReaders[i] as GenericDevices.IRoi;
|
|
|
|
|
|
if (roi != null)
|
|
|
|
|
|
{
|
2017-04-06 14:54:27 +00:00
|
|
|
|
roi.ClearRoi();
|
2017-04-06 10:32:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
imageNames[i] = null;
|
|
|
|
|
|
}
|
2017-01-16 14:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-06 10:32:46 +00:00
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.ROI_Detection_in_Progress);
|
|
|
|
|
|
//----------------------------------------------------------
|
2017-01-16 14:51:34 +00:00
|
|
|
|
detection_loop:
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
State detection = State.Create("RoiDetection : Detection of ROI-s")
|
|
|
|
|
|
.AddOperation(checkUiOp);
|
2017-04-06 10:32:46 +00:00
|
|
|
|
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-04-06 10:32:46 +00:00
|
|
|
|
GenericDevices.IRoi roi = sensPath.RegisterReaders[i] as GenericDevices.IRoi;
|
|
|
|
|
|
if (roi != null && !roi.Detected)
|
2017-01-16 14:51:34 +00:00
|
|
|
|
{
|
2017-04-06 10:32:46 +00:00
|
|
|
|
detection.AddOperation(roi.RoiDetectionOp());
|
2017-04-06 16:00:33 +00:00
|
|
|
|
imageNames[i] = roi.DetectedImageName;
|
2017-01-16 14:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
detection.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2017-01-16 14:51:34 +00:00
|
|
|
|
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test));
|
|
|
|
|
|
|
2014-10-02 18:56:24 +00:00
|
|
|
|
if (e.Contains(Event.Error))
|
|
|
|
|
|
{
|
|
|
|
|
|
retVal = Event.Error;
|
|
|
|
|
|
goto stopTest;
|
|
|
|
|
|
}
|
2017-04-06 08:00:14 +00:00
|
|
|
|
if (TestAndLogUiCmdStop(test,e))
|
|
|
|
|
|
{
|
|
|
|
|
|
retVal = Event.UiCmdStop;
|
|
|
|
|
|
goto stopTest;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
while (e.Contains(Event.CameraBusy));
|
|
|
|
|
|
|
2017-04-06 10:32:46 +00:00
|
|
|
|
string title = Strings.Do_you_want_to_retry_RoI_detection;
|
|
|
|
|
|
///
|
2017-01-16 14:51:34 +00:00
|
|
|
|
if (e.Contains(Event.RoiDetectionPreviousFailed))
|
2017-04-06 10:32:46 +00:00
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Camera_error);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (e.Contains(Event.RoiDetectionFailed))
|
|
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Detection_failed);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Detection_completed);
|
|
|
|
|
|
}
|
|
|
|
|
|
///
|
|
|
|
|
|
State.Create("RoiDetection : Do you want to retry RoI detection?")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation((display == null) ? null : display.ShowStaticImageOp(imageNames, title))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2017-01-16 14:51:34 +00:00
|
|
|
|
|
2017-04-06 10:32:46 +00:00
|
|
|
|
if (TestAndLogUiCmdStop(test, e))
|
|
|
|
|
|
{
|
|
|
|
|
|
retVal = Event.UiCmdStop;
|
|
|
|
|
|
goto stopTest;
|
2017-01-16 14:51:34 +00:00
|
|
|
|
}
|
2017-04-06 10:32:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
while (e.Contains(Event.ModelessFormIsOpen));
|
|
|
|
|
|
|
|
|
|
|
|
if (e.Contains(Event.Retry))
|
|
|
|
|
|
{
|
2017-04-06 21:49:51 +00:00
|
|
|
|
for (int i = 0; i < display.SelectedImages.Length; i++)
|
2017-04-06 14:54:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
GenericDevices.IRoi roi = sensPath.RegisterReaders[i] as GenericDevices.IRoi;
|
|
|
|
|
|
if (roi != null && display.SelectedImages[i])
|
|
|
|
|
|
{
|
|
|
|
|
|
roi.ClearRoi();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-06 10:32:46 +00:00
|
|
|
|
goto detection_loop;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (e.Contains(Event.Abort))
|
|
|
|
|
|
{
|
|
|
|
|
|
retVal = Event.UiCmdStop;
|
|
|
|
|
|
goto stopTest;
|
2017-01-16 14:51:34 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Detection_completed);
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
|
2017-01-16 14:51:34 +00:00
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.TransitionAfter));
|
|
|
|
|
|
|
2014-09-24 17:58:05 +00:00
|
|
|
|
stopTest:
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
///----------------------///
|
|
|
|
|
|
/// Quit this sequence ///
|
|
|
|
|
|
///----------------------///
|
|
|
|
|
|
|
2016-01-03 01:05:35 +00:00
|
|
|
|
State.Create("RoiDetection : Stopping diverter, gate, etc.")
|
2014-09-24 17:58:05 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(cBrd.StopPreviousOp())
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2014-09-24 17:58:05 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2017-01-16 14:51:34 +00:00
|
|
|
|
if (TestAndLogUiCmdStop(test, e)) { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; }
|
|
|
|
|
|
}
|
2014-09-24 17:58:05 +00:00
|
|
|
|
while (!e.Contains(Event.PreviousStopped));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-09-24 17:58:05 +00:00
|
|
|
|
/// Transition sequence at the end of test
|
|
|
|
|
|
/// Prevent overwriting 'retVal' in case it was set to non-default value earlier
|
2016-02-07 21:27:32 +00:00
|
|
|
|
switch (Transition(transitionAfter, (retVal == Event.Done) ? TransitionContext.AfterTest : TransitionContext.Stop))
|
2014-09-24 17:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
case Event.Error: { if (retVal == Event.Done) retVal = Event.Error; break; }
|
|
|
|
|
|
case Event.UiCmdStop: { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; }
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-01-16 14:51:34 +00:00
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Completed));
|
|
|
|
|
|
|
2014-09-24 17:58:05 +00:00
|
|
|
|
/// Create a list with one item 'retVal' (default is Event.Done) and return it
|
2015-02-02 22:18:28 +00:00
|
|
|
|
IList<Event> retList = new List<Event>(1);
|
2014-09-24 17:58:05 +00:00
|
|
|
|
retList.Add(retVal);
|
|
|
|
|
|
return retList;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|