206 lines
7.3 KiB
C#
206 lines
7.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using log4net;
|
|
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));
|
|
private static readonly ILog allResults = LogManager.GetLogger("AllResults");
|
|
private static readonly ILog summaryResults = LogManager.GetLogger("SummaryResults");
|
|
|
|
|
|
public IList<Event> Execute(Entities.Test test)
|
|
{
|
|
Elde.ControlBoardDev cBrd = StateMachine.ControlBoard;
|
|
|
|
IList<Event> e; /// Events from currently running operations
|
|
|
|
//--------------------------------
|
|
State.Create("RoiDetection : Starting the detection sequence")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(cBrd.StopPreviousOp())
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
}
|
|
while (!e.Contains(Event.PreviousStopped));
|
|
|
|
|
|
//====================================
|
|
/// Start the test, initialize test results
|
|
Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, 1, inPath, benchPath, outPath, sensPath, 0));
|
|
Entities.TestResult tstRslt = new Entities.TestResult(test, 1, Entities.MetersKind.Single);
|
|
tstRslt.DoNotEvaluate = true;
|
|
tstRslt.DoNotPublish = true;
|
|
|
|
//====================================
|
|
// Transition or SetRoute - Start
|
|
//====================================
|
|
switch (Transition(transitionStart, TransitionContext.TestStart))
|
|
{
|
|
case Event.Error: goto error;
|
|
case Event.UiCmdStop: goto stop;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Setting_the_flow);
|
|
//------------------------------------------------
|
|
foreach (var pump in PumpsWithFM) pump.TurnOnDfltPower();
|
|
State.Create("RoiDetection : Starting the pump")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(cBrd.SetValvesOp(inPath.Pump, null))
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
//--------------------------------
|
|
State.Create("RoiDetection : Setting the flow")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(outPath.RegulValve.SetFlowOp(outPath.FlowMeter, test.Qfrom, test.Qto, refFlow, 600)) /// timeout = 10 min.
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
if (e.Contains(Event.RegulValveTimeOut)) goto error;
|
|
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)) goto error;
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
}
|
|
while (e.Contains(Event.CameraBusy));
|
|
|
|
if (e.Contains(Event.CameraOpFailed)) goto error; /// TODO: resolve in some other way
|
|
|
|
//------------------------------------------------
|
|
Bridge.OnActivity(this, Strings.Detection_completed);
|
|
//------------------------------------------------
|
|
State.Create("RoiDetection : Stopping the pump")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation((inPath != null && inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOffOp() : null)
|
|
.AddOperation(cBrd.SetValvesOp(null, inPath.Pump))
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
//--------------------------------
|
|
State.Create("RoiDetection : Stopping diverter, gate, etc.")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(cBrd.StopPreviousOp())
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
}
|
|
while (!e.Contains(Event.PreviousStopped));
|
|
|
|
///----------------------///
|
|
/// Quit this sequence ///
|
|
///----------------------///
|
|
|
|
/// Stop the pump
|
|
State.Create("RoiDetection : Detection of ROI-s completed -> Stopping the pump")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation(cBrd.SetValvesOp(null, inPath.Pump))
|
|
.AddOperation((inPath != null && inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOffOp() : null)
|
|
.EnterState();
|
|
do {
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error)) goto error;
|
|
}
|
|
while (!e.Contains(Event.ValvesSet) || ((inPath.Pump is GenericDevices.IPumpFM) && !e.Contains(Event.TurnPumpOnOffDone)));
|
|
|
|
/// Transition or SetRoute - End
|
|
switch (Transition(transitionStop, TransitionContext.TestEnd))
|
|
{
|
|
case Event.Error: goto error;
|
|
case Event.UiCmdStop: goto stop;
|
|
}
|
|
|
|
/// Create the return value: a list with one event Event.Done
|
|
IList<Event> retval = new List<Event>();
|
|
retval.Add(Event.Done);
|
|
return retval;
|
|
|
|
//====================================
|
|
stop:
|
|
cBrd.SetFMFreq(0, 0); /// Stop FM controlled pumps
|
|
State.Create("RoiDetection : User selected STOP -> Closing the valves")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation((inPath != null && inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOffOp() : null)
|
|
.AddOperation(cBrd.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error)) goto error;
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
IList<Event> retval2 = new List<Event>();
|
|
retval2.Add(Event.UiCmdStop);
|
|
return retval2;
|
|
|
|
//====================================
|
|
error:
|
|
cBrd.SetFMFreq(0, 0); /// Stop FM controlled pumps
|
|
State.Create("RoiDetection : ERROR -> Closing the valves")
|
|
.AddOperation(checkUiOp)
|
|
.AddOperation((inPath != null && inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOffOp() : null)
|
|
.AddOperation(cBrd.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
|
|
.EnterState();
|
|
do
|
|
{
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
if (e.Contains(Event.Error)) goto error;
|
|
}
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
IList<Event> retval3 = new List<Event>();
|
|
retval3.Add(Event.Error);
|
|
return retval3;
|
|
}
|
|
}
|
|
}
|