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)); public IList Execute(Entities.Test test) { Elde.ControlBoardDev cBrd = StateMachine.ControlBoard; IList e = new List(); /// 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)); 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: { retVal = Event.Error; goto stopTest; } case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } } //------------------------------------------------ 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)) { 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, 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)) { retVal = Event.Error; 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(transitionStop, TransitionContext.TestEnd)) { 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 retList = new List(); retList.Add(retVal); return retList; } } }