2014-07-28 07:54:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.UiBridge;
|
|
|
|
|
|
using TBF.BenchControl.Operations;
|
|
|
|
|
|
using TBF.BenchControl.GenericDevices;
|
2014-07-31 15:04:09 +00:00
|
|
|
|
using TBF.Boxes;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
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"; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Specifies the selection done in the main sequence
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public enum Selection
|
|
|
|
|
|
{
|
|
|
|
|
|
None,
|
|
|
|
|
|
Cycle,
|
|
|
|
|
|
Test,
|
|
|
|
|
|
Q1,
|
|
|
|
|
|
Q2,
|
|
|
|
|
|
Q3,
|
2014-07-30 22:03:19 +00:00
|
|
|
|
Stop,
|
2014-07-28 07:54:35 +00:00
|
|
|
|
PurgeBegin,
|
|
|
|
|
|
PurgeEnd,
|
|
|
|
|
|
EmptyTank1,
|
|
|
|
|
|
EmptyTank2,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MainSeq()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IList<Event> Execute(Entities.Test dummyArg)
|
|
|
|
|
|
{
|
|
|
|
|
|
Elde.ControlBoardDev cBrd = StateMachine.ControlBoard;
|
|
|
|
|
|
|
|
|
|
|
|
/// Operations running in more then one state
|
|
|
|
|
|
IOperation checkUiOp = new CheckUIOp(true);
|
|
|
|
|
|
|
|
|
|
|
|
IList<Event> e;
|
|
|
|
|
|
Selection selection;
|
|
|
|
|
|
bool benchFilled = false;
|
|
|
|
|
|
|
|
|
|
|
|
Entities.TransitionSequence purgeBegin;
|
|
|
|
|
|
Entities.TransitionSequence purgeEnd;
|
|
|
|
|
|
|
|
|
|
|
|
StateMachine.LoadProcedure(true);
|
|
|
|
|
|
|
|
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.StopBtnEn);
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Measuring_the_weight);
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
State.Create(Strings.Set_route)
|
|
|
|
|
|
.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:
|
|
|
|
|
|
|
2014-07-30 22:03:19 +00:00
|
|
|
|
bool emptying1 = false;
|
|
|
|
|
|
bool emptying2 = false;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
do
|
|
|
|
|
|
{
|
2014-07-30 22:03:19 +00:00
|
|
|
|
/// 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.CalibrationBtnEn)) |
|
|
|
|
|
|
(emptying1 ? 0 : ButtonsEtc.EmptyTankBtn1En) |
|
|
|
|
|
|
(emptying2 ? 0 : ButtonsEtc.EmptyTankBtn2En));
|
|
|
|
|
|
|
|
|
|
|
|
selection = Selection.None;
|
|
|
|
|
|
State.Create("MainSeq : Select a procedure")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(StateMachine.Balance1.ReadMassOp(ref mass1))
|
|
|
|
|
|
.AddOperation(StateMachine.Balance2.ReadMassOp(ref mass2))
|
|
|
|
|
|
.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;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (selection == Selection.None);
|
|
|
|
|
|
|
|
|
|
|
|
if (selection == Selection.Stop)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (emptying1 || emptying2)
|
|
|
|
|
|
{
|
|
|
|
|
|
IList<IValve> valvesClose = new List<IValve>();
|
|
|
|
|
|
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.Bench2UI(ButtonsEtc.ProcedureCmbBoxEn | ButtonsEtc.TestCmbBoxEn | ButtonsEtc.StopBtnEn |
|
|
|
|
|
|
(emptying1 ? 0 : ButtonsEtc.EmptyTankBtn1En));
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Emptying_tank);
|
|
|
|
|
|
State.Create("MainSeq : Open emptying valve 2")
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.EmptyTankValve2, null))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do { e = StateMachine.WaitRunDevsRunOps(); }
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
}
|
2014-07-31 15:04:09 +00:00
|
|
|
|
else if ((emptying1 == true) && (mass1.Val < (StateMachine.Balance1.Capacity / 100.0f + 20.0f)))
|
2014-07-30 22:03:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
State.Create("MainSeq : Close emptying valve 1")
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, StateMachine.EmptyTankValve1))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do { e = StateMachine.WaitRunDevsRunOps(); }
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
emptying1 = false;
|
|
|
|
|
|
}
|
2014-07-31 15:04:09 +00:00
|
|
|
|
else if ((emptying2 == true) && (mass1.Val < (StateMachine.Balance1.Capacity / 100.0f + 20.0f)))
|
2014-07-30 22:03:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
State.Create("MainSeq : Close emptying valve 2")
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, StateMachine.EmptyTankValve2))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do { e = StateMachine.WaitRunDevsRunOps(); }
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
emptying2 = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
while (emptying1 || emptying2 || (selection == Selection.None));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
2014-07-28 21:12:43 +00:00
|
|
|
|
GenericDevices.IDataEntry dataEntryCmpnt =
|
|
|
|
|
|
TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry;
|
|
|
|
|
|
if (dataEntryCmpnt != null)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnActivity(this, "Enter the water meter data");
|
|
|
|
|
|
State.Create("MainSeq : Enter begin data")
|
2014-07-29 17:25:13 +00:00
|
|
|
|
.AddOperation(dataEntryCmpnt.ShowFormAtCycleBeginningOp(WaterMeters))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.Done));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assume_bench_filled:
|
|
|
|
|
|
|
|
|
|
|
|
benchFilled = true;
|
|
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.ShowBenchFilled);
|
|
|
|
|
|
|
|
|
|
|
|
if (selection != Selection.PurgeBegin) goto cycle_or_test;
|
|
|
|
|
|
|
|
|
|
|
|
ready:
|
2014-07-30 22:03:19 +00:00
|
|
|
|
emptying1 = false;
|
|
|
|
|
|
emptying2 = false;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
do
|
|
|
|
|
|
{
|
2014-07-30 22:03:19 +00:00
|
|
|
|
/// 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.PurgeEndBtnEn |
|
|
|
|
|
|
((Cameras.Count > 0) ? ButtonsEtc.CalibrationBtnEn : 0)) |
|
|
|
|
|
|
ButtonsEtc.SensitivityTestBtnEn | ButtonsEtc.TryOpticalHeadsBtnEn) |
|
|
|
|
|
|
(emptying1 ? 0 : ButtonsEtc.EmptyTankBtn1En) |
|
|
|
|
|
|
(emptying2 ? 0 : ButtonsEtc.EmptyTankBtn2En));
|
|
|
|
|
|
|
|
|
|
|
|
selection = Selection.None;
|
|
|
|
|
|
State.Create("MainSeq : Select an activity for the selected procedure")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(StateMachine.Balance1.ReadMassOp(ref mass1))
|
|
|
|
|
|
.AddOperation(StateMachine.Balance2.ReadMassOp(ref mass2))
|
|
|
|
|
|
.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 (e.Contains(Event.UiCmdAcceptResults)) goto save_results;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (selection == Selection.None);
|
|
|
|
|
|
|
|
|
|
|
|
if (selection == Selection.Stop)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (emptying1 || emptying2)
|
|
|
|
|
|
{
|
|
|
|
|
|
IList<IValve> valvesClose = new List<IValve>();
|
|
|
|
|
|
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));
|
|
|
|
|
|
}
|
2014-07-31 15:04:09 +00:00
|
|
|
|
else if ((emptying1 == true) && (mass1.Val < (StateMachine.Balance1.Capacity / 100.0f + 20.0f)))
|
2014-07-30 22:03:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
State.Create("MainSeq : Close emptying valve 1")
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, StateMachine.EmptyTankValve1))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do { e = StateMachine.WaitRunDevsRunOps(); }
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
emptying1 = false;
|
|
|
|
|
|
}
|
2014-07-31 15:04:09 +00:00
|
|
|
|
else if ((emptying2 == true) && (mass1.Val < (StateMachine.Balance1.Capacity / 100.0f + 20.0f)))
|
2014-07-30 22:03:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
State.Create("MainSeq : Close emptying valve 2")
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, StateMachine.EmptyTankValve2))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do { e = StateMachine.WaitRunDevsRunOps(); }
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
emptying2 = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
while (emptying1 || emptying2 || (selection == Selection.None));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
var events = testMethodSequence.Execute(test);
|
|
|
|
|
|
|
|
|
|
|
|
if (events.Contains(Event.Error)) goto error;
|
|
|
|
|
|
if (events.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;
|
2014-07-28 21:12:43 +00:00
|
|
|
|
dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry;
|
|
|
|
|
|
if (dataEntryCmpnt != null)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnActivity(this, "Enter the protokoll data");
|
|
|
|
|
|
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.Done));
|
|
|
|
|
|
|
|
|
|
|
|
if (dataEntryCmpnt is IHasProtocolTitle)
|
|
|
|
|
|
{
|
|
|
|
|
|
protocolTitle = (dataEntryCmpnt as IHasProtocolTitle).ProtocolTitle;
|
|
|
|
|
|
}
|
2014-07-28 21:12:43 +00:00
|
|
|
|
|
|
|
|
|
|
dataEntryCmpnt.UpdateTestResults(WaterMeters, results);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|