tbf/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionSeq.cs
Milan Hanajik 836daaa5a1 - German translations
- IBox, FloatBox, IntBox related changes
2014-07-31 22:17:48 +02:00

246 lines
9.2 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;
/// Operations running in more then one state
checkUiOp = new Operations.CheckUIOp(true);
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));
/// Fetch the test, the paths
bool success = StateMachine.GetPaths(test, out inPath, out benchPath, out outPath, out sensPath,
out transitionStart, out transitionStop);
if (!success) goto error;
//====================================
/// 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
//====================================
if (transitionStart != null)
{
switch (Transition(transitionStart, "RoiDetection : " + Strings.Test_start_sequence_i_n))
{
case Event.Error: goto error;
case Event.UiCmdStop: goto stop;
}
}
else
{
//--------------------------------
State.Create("RoiDetection : Setting the route")
.AddOperation(checkUiOp)
.AddOperation(cBrd.SetValvesOp(GenericDevices.ValveBase.Merge(inPath.ValvesOpen, benchPath.ValvesOpen, outPath.ValvesOpen),
GenericDevices.ValveBase.Merge(inPath.ValvesClose, benchPath.ValvesClose, outPath.ValvesClose)))
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.UiCmdStop)) goto stop;
}
while (!e.Contains(Event.ValvesSet));
}
//------------------------------------------------
Bridge.OnActivity(this, Strings.Setting_the_flow);
//------------------------------------------------
State.Create("RoiDetection : Starting the pump")
.AddOperation(checkUiOp)
.AddOperation((inPath != null && inPath.Pump is GenericDevices.IPumpFM) ? (inPath.Pump as GenericDevices.IPumpFM).TurnOn() : null)
.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.CurrentTime;
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).TurnOff() : 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).TurnOff() : 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
if (transitionStop != null)
{
switch (Transition(transitionStop, "RoiDetection : " + Strings.Test_stop_sequence_i_n))
{
case Event.Error: goto error;
case Event.UiCmdStop: goto stop;
}
}
else
{
State.Create("RoiDetection : Detection completed -> Closing the valves")
.AddOperation(checkUiOp)
.AddOperation(cBrd.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) goto error;
}
while (!e.Contains(Event.ValvesSet));
}
/// 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).TurnOff() : 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).TurnOff() : 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;
}
}
}