using System; using System.Collections.Generic; using log4net; using TBF.UiBridge; using TBF.BenchControl.Operations; using TBF.BenchControl.GenericDevices; using TBF.Boxes; using TBF.Resources; namespace TBF.BenchControl.Sequences { public class MainSeq : SequenceBase, ISequence { private static readonly ILog log = LogManager.GetLogger(typeof(MainSeq)); private static readonly ILog allResults = LogManager.GetLogger("AllResults"); private static readonly ILog summaryResults = LogManager.GetLogger("SummaryResults"); public override string ToString() { return "Sequences.MainSeq"; } /// /// Specifies the selection done in the main sequence /// public enum Selection { None, Cycle, Test, Q1, Q2, Q3, Stop, PurgeBegin, PurgeEnd, EmptyTank1, EmptyTank2, CloseTank1, CloseTank2, } public MainSeq() { } public IList Execute(Entities.Test dummyArg) { Elde.ControlBoardDev cBrd = StateMachine.ControlBoard; /// Operations running in more then one state IOperation checkUiOp = new CheckUIOp(true); IList e; Selection selection; bool benchFilled = false; Entities.TransitionSequence purgeBegin; Entities.TransitionSequence purgeEnd; StateMachine.LoadProcedure(true); // TODO: Implement as an operation so that the worker thread is not blocked Bridge.Bench2UI(ButtonsEtc.StopBtnEn); //------------------------------------------------ Bridge.OnActivity(this, Strings.Measuring_the_weight); //------------------------------------------------ State.Create("MainSeq : Setting valves to the default state") .AddOperation(new MettlerToledo.ReadMassesOp()) .AddOperation(cBrd.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) goto stop; } while (!(e.Contains(Event.ValvesSet) && e.Contains(Event.BalanceDone))); //------------------------------------------------ Bridge.OnActivity(this, Strings.Starting_the_cameras); //------------------------------------------------ State startNew = State.Create("MainSeq : Starting the cameras") .AddOperation(checkUiOp); foreach (var cmpnt in StateMachine.Components) { Cameras.IdcCamera.IdcCamera camera = cmpnt as Cameras.IdcCamera.IdcCamera; if ((camera != null) && (camera.Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) { startNew.AddOperation(camera.StartNewOp()); } } startNew.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 idle: bool emptying1 = false; bool emptying2 = false; do { /// Used for emptying FloatBox mass1 = new FloatBox(); FloatBox mass2 = new FloatBox(); //--------------------------------------------------------- if (emptying1 || emptying2) Bridge.OnActivity(this, Strings.Emptying_tank); else Bridge.OnActivity(this, Strings.Please_select_a_procedure); //--------------------------------------------------------- /// Start something buttons are hidden when emptyign is in progress Bridge.Bench2UI(ButtonsEtc.ProcedureCmbBoxEn | ButtonsEtc.TestCmbBoxEn | ButtonsEtc.StopBtnEn | ((emptying1 || emptying2) ? 0 : (ButtonsEtc.StartCycleBtnEn | ButtonsEtc.StartTestBtnsEn | ButtonsEtc.PurgeBeginBtnEn | ButtonsEtc.SensitivityTestBtnEn | ((Cameras.Count > 0) ? ButtonsEtc.CalibrationBtnEn : 0) | ButtonsEtc.TryOpticalHeadsBtnEn)) | (((StateMachine.Balance1 != null) && !emptying1) ? ButtonsEtc.EmptyTankBtn1En : 0) | (((StateMachine.Balance2 != null) && !emptying2) ? ButtonsEtc.EmptyTankBtn2En : 0)); selection = Selection.None; State.Create("MainSeq : Select a procedure") .AddOperation(checkUiOp) .AddOperation((StateMachine.Balance1 != null) ? StateMachine.Balance1.ReadMassOp(ref mass1) : null) .AddOperation((StateMachine.Balance2 != null) ? StateMachine.Balance2.ReadMassOp(ref mass2) : null) .AddOperation(cBrd.UpdateTankWeightOp()) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdPurgeBegin)) selection = Selection.PurgeBegin; if (e.Contains(Event.UiCmdStartTest)) selection = Selection.Test; if (e.Contains(Event.UiCmdStartQ1)) selection = Selection.Q1; if (e.Contains(Event.UiCmdStartQ2)) selection = Selection.Q2; if (e.Contains(Event.UiCmdStartQ3)) selection = Selection.Q3; if (e.Contains(Event.UiCmdStartCycle)) selection = Selection.Cycle; if (e.Contains(Event.UiCmdStop)) selection = Selection.Stop; if (e.Contains(Event.UiCmdEmptyTank1)) selection = Selection.EmptyTank1; if (e.Contains(Event.UiCmdEmptyTank2)) selection = Selection.EmptyTank2; if (e.Contains(Event.UiCmdCameraTest)) goto camera_test; if ((emptying1 == true) && (mass1.Val < (StateMachine.Balance1.Capacity / 100.0f + 20.0f))) { selection = Selection.CloseTank1; } if ((emptying2 == true) && (mass2.Val < (StateMachine.Balance2.Capacity / 100.0f + 20.0f))) { selection = Selection.CloseTank2; } } while (selection == Selection.None); if (selection == Selection.Stop) { if (emptying1 || emptying2) { IList valvesClose = new List(); if (emptying1) valvesClose.Add(StateMachine.EmptyTankValve1); if (emptying2) valvesClose.Add(StateMachine.EmptyTankValve2); State.Create("MainSeq : Close emptying valve(s)") .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, valvesClose)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); emptying1 = emptying2 = false; } selection = Selection.None; } else if ((selection == Selection.EmptyTank1) && (emptying1 == false)) { emptying1 = true; Bridge.OnActivity(this, Strings.Emptying_tank); Bridge.Bench2UI(ButtonsEtc.ProcedureCmbBoxEn | ButtonsEtc.TestCmbBoxEn | ButtonsEtc.StopBtnEn | (emptying2 ? 0 : ButtonsEtc.EmptyTankBtn2En)); State.Create("MainSeq : Open tank 1") .AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.EmptyTankValve1, null)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); } else if ((selection == Selection.EmptyTank2) && (emptying2 == false)) { emptying2 = true; Bridge.Bench2UI(ButtonsEtc.ProcedureCmbBoxEn | ButtonsEtc.TestCmbBoxEn | ButtonsEtc.StopBtnEn | (emptying1 ? 0 : ButtonsEtc.EmptyTankBtn1En)); Bridge.OnActivity(this, Strings.Emptying_tank); State.Create("MainSeq : Open tank 2") .AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.EmptyTankValve2, null)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); } else if (selection == Selection.CloseTank1) { State.Create("MainSeq : Close tank 1") .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, StateMachine.EmptyTankValve1)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); emptying1 = false; } else if (selection == Selection.CloseTank2) { State.Create("MainSeq : Close tank 2") .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, StateMachine.EmptyTankValve2)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); emptying2 = false; } } while ((selection != Selection.Cycle) && (selection != Selection.Test) && (selection != Selection.Q1) && (selection != Selection.Q2) && (selection != Selection.Q3) || emptying1 || emptying2); //-------------------------------- Bridge.Bench2UI(ButtonsEtc.StopBtnEn); StateMachine.LoadProcedure(false); if (StateMachine.Procedure == null) { goto idle; } StateMachine.LoadProcedureParams(StateMachine.Procedure); ResetResults(); Bridge.OnProcedureSelected(this, new ProcedureSelectedEventArgs(StateMachine.Procedure)); purgeBegin = null; purgeEnd = null; foreach (var transition in StateMachine.TransitionSequences) { if (transition.Name == StateMachine.Procedure.TransitionStart) purgeBegin = transition; if (transition.Name == StateMachine.Procedure.TransitionEnd) purgeEnd = transition; } if (selection == Selection.Q1 || selection == Selection.Q2 || selection == Selection.Q3 || selection == Selection.Test) { goto assume_bench_filled; } else if (selection == Selection.Cycle && benchFilled) { //-------------------------------- State.Create("MainSeq : Answer a question") .AddOperation(new Operations.AskYesNoOp()) .AddOperation(checkUiOp) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.No)) goto assume_bench_filled; if (e.Contains(Event.UiCmdStop)) goto idle; } while (!e.Contains(Event.Yes)); } fill_the_bench: /// Purge - Begin switch (Transition(purgeBegin, Strings.Purging_i_n)) { case Event.Error: goto error; case Event.UiCmdStop: goto stop; } //-------------------------------- GenericDevices.IDataEntry dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry; if (dataEntryCmpnt != null) { Bridge.OnActivity(this, "Enter the water meter data"); State.Create("MainSeq : Enter begin data") .AddPermanentOperation(dataEntryCmpnt.ShowFormAtCycleBeginningOp(WaterMeters)) .AddOperation(checkUiOp) .EnterState(); e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.UiCmdStop)) goto stop; } assume_bench_filled: benchFilled = true; Bridge.Bench2UI(ButtonsEtc.ShowBenchFilled); if (selection != Selection.PurgeBegin) goto cycle_or_test; ready: emptying1 = false; emptying2 = false; do { /// Used for emptying FloatBox mass1 = new FloatBox(); FloatBox mass2 = new FloatBox(); //------------------------------------------------ if (emptying1 || emptying2) Bridge.OnActivity(this, Strings.Emptying_tank); else Bridge.OnActivity(this, Strings.Please_select_a_cycle_a_test_or_empty); //------------------------------------------------ Bridge.Bench2UI(ButtonsEtc.TestCmbBoxEn | ButtonsEtc.StopBtnEn | ((emptying1 || emptying2) ? 0 : (ButtonsEtc.StartCycleBtnEn | ButtonsEtc.StartTestBtnsEn | ButtonsEtc.PurgeBeginBtnEn | ButtonsEtc.SensitivityTestBtnEn | ((Cameras.Count > 0) ? ButtonsEtc.CalibrationBtnEn : 0) | ButtonsEtc.TryOpticalHeadsBtnEn)) | (((StateMachine.Balance1 != null) && !emptying1) ? ButtonsEtc.EmptyTankBtn1En : 0) | (((StateMachine.Balance2 != null) && !emptying2) ? ButtonsEtc.EmptyTankBtn2En : 0)); selection = Selection.None; State.Create("MainSeq : Select an activity for the selected procedure") .AddOperation(checkUiOp) .AddOperation((StateMachine.Balance1 != null) ? StateMachine.Balance1.ReadMassOp(ref mass1) : null) .AddOperation((StateMachine.Balance2 != null) ? StateMachine.Balance2.ReadMassOp(ref mass2) : null) .AddOperation(cBrd.UpdateTankWeightOp()) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) selection = Selection.Stop; if (e.Contains(Event.UiCmdStartTest)) selection = Selection.Test; if (e.Contains(Event.UiCmdStartQ1)) selection = Selection.Q1; if (e.Contains(Event.UiCmdStartQ2)) selection = Selection.Q2; if (e.Contains(Event.UiCmdStartQ3)) selection = Selection.Q3; if (e.Contains(Event.UiCmdStartCycle)) selection = Selection.Cycle; if (e.Contains(Event.UiCmdPurgeBegin)) { selection = Selection.PurgeBegin; goto fill_the_bench; } if (e.Contains(Event.UiCmdPurgeEnd)) goto purge_end; if (e.Contains(Event.UiCmdEmptyTank1)) selection = Selection.EmptyTank1; if (e.Contains(Event.UiCmdEmptyTank2)) selection = Selection.EmptyTank2; if ((emptying1 == true) && (mass1.Val < (StateMachine.Balance1.Capacity / 100.0f + 20.0f))) { selection = Selection.CloseTank1; } if ((emptying2 == true) && (mass2.Val < (StateMachine.Balance2.Capacity / 100.0f + 20.0f))) { selection = Selection.CloseTank2; } if (e.Contains(Event.UiCmdAcceptResults)) goto save_results; } while (selection == Selection.None); if (selection == Selection.Stop) { if (emptying1 || emptying2) { IList valvesClose = new List(); if (emptying1) valvesClose.Add(StateMachine.EmptyTankValve1); if (emptying2) valvesClose.Add(StateMachine.EmptyTankValve2); State.Create("MainSeq : Close emptying valve(s)") .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, valvesClose)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); emptying1 = emptying2 = false; } selection = Selection.None; } else if ((selection == Selection.EmptyTank1) && (emptying1 == false)) { emptying1 = true; Bridge.OnActivity(this, Strings.Emptying_tank); Bridge.Bench2UI(ButtonsEtc.ProcedureCmbBoxEn | ButtonsEtc.TestCmbBoxEn | ButtonsEtc.StopBtnEn | (emptying2 ? 0 : ButtonsEtc.EmptyTankBtn2En)); State.Create("MainSeq : Open emptying valve 1") .AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.EmptyTankValve1, null)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); } else if ((selection == Selection.EmptyTank2) && (emptying2 == false)) { emptying2 = true; Bridge.OnActivity(this, Strings.Emptying_tank); Bridge.Bench2UI(ButtonsEtc.ProcedureCmbBoxEn | ButtonsEtc.TestCmbBoxEn | ButtonsEtc.StopBtnEn | (emptying1 ? 0 : ButtonsEtc.EmptyTankBtn1En)); State.Create("MainSeq : Open emptying valve 2") .AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.EmptyTankValve2, null)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); } else if (selection == Selection.CloseTank1) { State.Create("MainSeq : Close tank 1") .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, StateMachine.EmptyTankValve1)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); emptying1 = false; } else if (selection == Selection.CloseTank2) { State.Create("MainSeq : Close tank 2") .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, StateMachine.EmptyTankValve2)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet)); emptying2 = false; } } while ((selection != Selection.Cycle) && (selection != Selection.Test) && (selection != Selection.Q1) && (selection != Selection.Q2) && (selection != Selection.Q3) || emptying1 || emptying2); cycle_or_test: Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Hide buttons if (selection == Selection.Cycle) { TimeEstimateTotal = 0; foreach (var test in StateMachine.Tests) TimeEstimateTotal += (test.Repeats * (test.TstTime + 10.0f)); TimeEstimateBeginRpts = 0; foreach (var test in StateMachine.Tests) { transitionStart = null; transitionStop = null; foreach (var transition in StateMachine.TransitionSequences) { if (transition.Name == test.TransitionStart) transitionStart = transition; if (transition.Name == test.TransitionEnd) transitionStop = transition; } TimeEstimateOneTest = test.TstTime + 10.0f; //-------------------------------------------------------------- ISequence testMethodSequence = TbfComponents.FindComponent(test.Method) as ISequence; if (testMethodSequence != null) { //-------------------------------------------------------------- var events = testMethodSequence.Execute(test); if (events.Contains(Event.Error)) goto error; if (events.Contains(Event.UiCmdStop)) goto stop; } TimeEstimateBeginRpts += (test.Repeats * TimeEstimateOneTest); } } else { Entities.Test test = StateMachine.GetTest(selection); TimeEstimateTotal = test.Repeats * (test.TstTime + 10.0f); TimeEstimateOneTest = test.TstTime + 10.0f; TimeEstimateBeginRpts = 0; transitionStart = null; transitionStop = null; foreach (var transition in StateMachine.TransitionSequences) { if (transition.Name == test.TransitionStart) transitionStart = transition; if (transition.Name == test.TransitionEnd) transitionStop = transition; } ISequence testMethodSequence = TbfComponents.FindComponent(test.Method) as ISequence; if (testMethodSequence != null) { //-------------------------------------------------------------- e = testMethodSequence.Execute(test); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) goto stop; } } if (ResultsAreComplete(StateMachine.Tests)) { Bridge.Bench2UI(ButtonsEtc.AcceptResultsBtnEn | ButtonsEtc.ResetResultsBtnEn); } else { Bridge.Bench2UI(ButtonsEtc.ResetResultsBtnEn); } goto ready; purge_end: save_results: Bridge.Bench2UI(ButtonsEtc.StopBtnEn); // Hide the most of buttons //-------------------------------- string protocolTitle = string.Empty; dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry; if (dataEntryCmpnt != null) { Bridge.OnActivity(this, "Enter the protocol data"); if (!State.LastEvents.Contains(Event.ModelessFormClosed)) { /// Wait until modeless dialg is closed State.Create("MainSeq : Check whether the entry form is closed") .AddOperation(checkUiOp) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.UiCmdStop)) goto stop; } while (!e.Contains(Event.ModelessFormClosed)); } /// A state without any dataEntryCmpnt operation so that Stop() when entering /// this state and Start() when entering the following state are executed. State.Create("MainSeq : Nothing") .AddOperation(checkUiOp) .RemovePermanentOperation(dataEntryCmpnt as IOperation) .EnterState(); e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.UiCmdStop)) goto stop; /// Open the modeless form for the end of the cycle State.Create("MainSeq : Enter end data") .AddOperation((dataEntryCmpnt as GenericDevices.IDataEntry).ShowFormAtCycleEndOp(WaterMeters)) .AddOperation(checkUiOp) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.UiCmdStop)) goto stop; } while (!e.Contains(Event.ModelessFormClosed)); if (dataEntryCmpnt is IHasProtocolTitle) { protocolTitle = (dataEntryCmpnt as IHasProtocolTitle).ProtocolTitle; } dataEntryCmpnt.UpdateTestResults(WaterMeters, results); } //-------------------------------- IResultsWriter writer = TbfComponents.FindComponent(StateMachine.Procedure.ResultsWriter) as IResultsWriter; if (writer != null) { State.Create("MainSeq : Saving results") .AddOperation(writer.WriteResultsOp(results)) .AddOperation(checkUiOp) .EnterState(); { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) goto stop; } } //-------------------------------- IResultsPrinter printer = TbfComponents.FindComponent(StateMachine.Procedure.ResultsPrinter) as IResultsPrinter; if (printer != null) { State.Create("MainSeq : Printing results") .AddOperation(printer.PrintResultsOp(BenchId, WaterMeters, results, protocolTitle)) .AddOperation(checkUiOp) .EnterState(); { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) goto stop; } } /// Purge - End switch (Transition(purgeEnd, Strings.Emptying_i_n)) { case Event.Error: goto error; case Event.UiCmdStop: goto stop; } benchFilled = false; Bridge.Bench2UI(ButtonsEtc.ShowBenchEmpty); goto idle; camera_test: Bridge.OnActivity(this, "Camera test"); //--------------------------------------------------------- Bridge.Bench2UI(ButtonsEtc.StartTestBtnsEn | ButtonsEtc.StopBtnEn); selection = Selection.None; State.Create("MainSeq : 1 = Grab, 2 = Live, 3 = Focus, Stop = Quit camera test") .AddOperation(checkUiOp) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) { goto idle; } if (e.Contains(Event.UiCmdStartQ1)) goto grab; if (e.Contains(Event.UiCmdStartQ2)) goto live; if (e.Contains(Event.UiCmdStartQ3)) goto focus; } while (true); grab: Bridge.Bench2UI(ButtonsEtc.StopBtnEn); selection = Selection.None; State.Create("MainSeq : Press 'Stop' to continue") .AddOperation(checkUiOp) .AddOperation((Cameras.Count > 0 && Cameras[0] != null && (Cameras[0].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[0].GrabOp() : null) .AddOperation((Cameras.Count > 1 && Cameras[1] != null && (Cameras[1].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[1].GrabOp() : null) .AddOperation((Cameras.Count > 2 && Cameras[2] != null && (Cameras[2].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[2].GrabOp() : null) .AddOperation((Cameras.Count > 3 && Cameras[3] != null && (Cameras[3].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[3].GrabOp() : null) .AddOperation((Cameras.Count > 4 && Cameras[4] != null && (Cameras[4].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[4].GrabOp() : null) .AddOperation((Cameras.Count > 5 && Cameras[5] != null && (Cameras[5].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[5].GrabOp() : null) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) goto camera_test; } while (true); live: Bridge.Bench2UI(ButtonsEtc.StopBtnEn); selection = Selection.None; State.Create("MainSeq : Press 'Stop' to stop.") .AddOperation(checkUiOp) .AddOperation((Cameras.Count > 0 && Cameras[0] != null && (Cameras[0].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[0].LiveOp() : null) .AddOperation((Cameras.Count > 1 && Cameras[1] != null && (Cameras[1].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[1].LiveOp() : null) .AddOperation((Cameras.Count > 2 && Cameras[2] != null && (Cameras[2].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[2].LiveOp() : null) .AddOperation((Cameras.Count > 3 && Cameras[3] != null && (Cameras[3].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[3].LiveOp() : null) .AddOperation((Cameras.Count > 4 && Cameras[4] != null && (Cameras[4].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[4].LiveOp() : null) .AddOperation((Cameras.Count > 5 && Cameras[5] != null && (Cameras[5].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[5].LiveOp() : null) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) goto camera_test; } while (true); focus: Bridge.Bench2UI(ButtonsEtc.StopBtnEn); selection = Selection.None; State.Create("MainSeq : Press 'Stop' to stop.") .AddOperation(checkUiOp) .AddOperation((Cameras.Count > 0 && Cameras[0] != null && (Cameras[0].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[0].FocusOp() : null) .AddOperation((Cameras.Count > 1 && Cameras[1] != null && (Cameras[1].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[1].FocusOp() : null) .AddOperation((Cameras.Count > 2 && Cameras[2] != null && (Cameras[2].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[2].FocusOp() : null) .AddOperation((Cameras.Count > 3 && Cameras[3] != null && (Cameras[3].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[3].FocusOp() : null) .AddOperation((Cameras.Count > 4 && Cameras[4] != null && (Cameras[4].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[4].FocusOp() : null) .AddOperation((Cameras.Count > 5 && Cameras[5] != null && (Cameras[5].Cfg.DebugLevel != Entities.DebugMode.DetectedOff)) ? Cameras[5].FocusOp() : null) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.UiCmdStop)) goto camera_test; } while (true); stop: //-------------------------------- State.Create("MainSeq : Turning IDLE -> 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)); goto idle; config_error: //-------------------------------- State.Create("MainSeq : Procedure configuration error") .EnterState(); while (true) StateMachine.WaitRunDevsRunOps(); error: //-------------------------------- State.Create("MainSeq : ERROR -> Closing the valves") .AddOperation(checkUiOp) .AddOperation(cBrd.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose)) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); } while (!e.Contains(Event.ValvesSet) && !e.Contains(Event.Error)); //-------------------------------- State.Create("MainSeq : ERROR state") .EnterState(); while (true) StateMachine.WaitRunDevsRunOps(); } } }