163 lines
5.8 KiB
C#
163 lines
5.8 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.Resources;
|
|
using TBF.UiBridge;
|
|
|
|
namespace TBF.BenchControl.TestMethods.CameraRoiDetection
|
|
{
|
|
public class RoiDetectionSeq : Sequences.SequenceBase
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(RoiDetectionSeq));
|
|
|
|
|
|
public IList<Event> Execute(Test test)
|
|
{
|
|
Elde.ControlBoardDev cBrd = StateMachine.ControlBoard;
|
|
|
|
IList<Event> e = new List<Event>(); /// Events from currently running operations
|
|
Event retVal = Event.Done;
|
|
|
|
/// Operations
|
|
checkUiOp = new Operations.CheckUIOp(true);
|
|
processDataLoggingOp = null;
|
|
|
|
//====================================
|
|
/// Start the test, initialize test results
|
|
Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, 1, inPath, benchPath, outPath, sensPath, 0));
|
|
TestResult tstRslt = new TestResult(test, 1, MetersKind.Single);
|
|
tstRslt.DoNotEvaluate = true;
|
|
tstRslt.DoNotPublish = true;
|
|
|
|
|
|
//====================================
|
|
// Transition or SetRoute - Start
|
|
//====================================
|
|
switch (Transition(transitionBefore, TransitionContext.BeforeTest))
|
|
{
|
|
case Event.Error: { retVal = Event.Error; goto stopTest; }
|
|
case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Setting_the_flow);
|
|
//------------------------------------------------
|
|
if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower);
|
|
State.Create("RoiDetection : Starting the pump")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(cBrd.SetValvesOp(inPath.Pump, null))
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
//--------------------------------
|
|
State.Create("RoiDetection : Setting the flow")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(outPath.RegulValve.SetFlowOp(outPath.FlowMeter, test.Qfrom, test.Qto, outPath.PidCoef, RefFlow, 600)) /// timeout = 10 min.
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; }
|
|
if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
if (e.Contains(Event.RegulValveTimeOut))
|
|
{
|
|
Bridge.OnError(this, Strings.Timeout);
|
|
retVal = Event.Done;
|
|
goto stopTest;
|
|
}
|
|
if (e.Contains(Event.Next)) goto flow_set;
|
|
}
|
|
while (!e.Contains(Event.FlowReached));
|
|
|
|
flow_set:
|
|
int time = StateMachine.Time;
|
|
float currentFlow = RefFlow.Val;
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.ROI_Detection_in_Progress);
|
|
//------------------------------------------------
|
|
State detection = State.Create("RoiDetection : Detection of ROI-s")
|
|
.AddOperation(checkUiOp);
|
|
/// Extract cameras from the current sensors path, add operations to the detection state
|
|
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
|
|
{
|
|
GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi;
|
|
if (cameraRoi != null)
|
|
{
|
|
detection.AddOperation(cameraRoi.DetectOp());
|
|
}
|
|
}
|
|
detection.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error))
|
|
{
|
|
retVal = Event.Error;
|
|
goto stopTest;
|
|
}
|
|
if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
while (e.Contains(Event.CameraBusy));
|
|
|
|
if (e.Contains(Event.CameraOpFailed))
|
|
{
|
|
retVal = Event.Error;
|
|
Bridge.OnActivity(this, Strings.Camera_error);
|
|
goto stopTest;
|
|
}
|
|
else if (e.Contains(Event.DetectionFailed))
|
|
{
|
|
retVal = Event.Error;
|
|
Bridge.OnActivity(this, Strings.Detection_failed);
|
|
goto stopTest;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Detection_completed);
|
|
//------------------------------------------------
|
|
|
|
stopTest:
|
|
|
|
///----------------------///
|
|
/// Quit this sequence ///
|
|
///----------------------///
|
|
|
|
State.Create("FlyingStartCollectionMethod : Stopping diverter, gate, etc.")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(cBrd.StopPreviousOp())
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.UiCmdStop)) { retVal = Event.UiCmdStop; goto stopTest; }
|
|
}
|
|
while (!e.Contains(Event.PreviousStopped));
|
|
|
|
/// Transition sequence at the end of test
|
|
/// Prevent overwriting 'retVal' in case it was set to non-default value earlier
|
|
switch (Transition(transitionAfter, TransitionContext.AfterTest))
|
|
{
|
|
case Event.Error: { if (retVal == Event.Done) retVal = Event.Error; break; }
|
|
case Event.UiCmdStop: { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; }
|
|
}
|
|
|
|
/// Create a list with one item 'retVal' (default is Event.Done) and return it
|
|
IList<Event> retList = new List<Event>(1);
|
|
retList.Add(retVal);
|
|
return retList;
|
|
}
|
|
}
|
|
}
|