StartInfo is read from DB when previous results were reloaded.
This commit is contained in:
@@ -225,34 +225,19 @@ namespace TBF.BenchControl.Sequences
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Main sequence
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="dummyArg"></param>
|
||||
/// <returns></returns>
|
||||
public void Execute()
|
||||
/// <returns>true = OK, false = error</returns>
|
||||
bool DrainTanks()
|
||||
{
|
||||
IList<Event> e;
|
||||
Selection selection;
|
||||
string selectedTestName;
|
||||
|
||||
Bridge.OnActivity(this, Strings.Starting_system);
|
||||
WaitForOkButton();
|
||||
SetValvesToDefaultState();
|
||||
|
||||
string scaleName;
|
||||
string message;
|
||||
if (TestCommunicationWithScales(out scaleName, out message) == false)
|
||||
{
|
||||
Bridge.OnError(this, string.Format("{0} : {1}", scaleName, message));
|
||||
goto error;
|
||||
}
|
||||
|
||||
///
|
||||
/// Enable stop draining buttons
|
||||
///
|
||||
Bridge.Bench2UI(((StateMachine.DrainValve1 != null) ? ButtonsEtc.DrainTankBtn1Hi : 0) |
|
||||
((StateMachine.DrainValve2 != null) ? ButtonsEtc.DrainTankBtn2Hi : 0) |
|
||||
((StateMachine.DrainValve3 != null) ? ButtonsEtc.DrainTankBtn3Hi : 0));
|
||||
/// Enable stop draining buttons
|
||||
///
|
||||
Bridge.Bench2UI(((StateMachine.DrainValve1 != null) ? ButtonsEtc.DrainTankBtn1Hi : 0) |
|
||||
((StateMachine.DrainValve2 != null) ? ButtonsEtc.DrainTankBtn2Hi : 0) |
|
||||
((StateMachine.DrainValve3 != null) ? ButtonsEtc.DrainTankBtn3Hi : 0));
|
||||
|
||||
///
|
||||
/// Determine lists of drain valves and drain times (max. of all tank drain times)
|
||||
@@ -299,17 +284,16 @@ namespace TBF.BenchControl.Sequences
|
||||
.AddOperation(new TimerOp(areTwoDrainPhases ? firstPhaseTime : totalDrainTime, timerTime))
|
||||
.AddOperation(StateMachine.ControlBoard.SetValvesOp(fullDrainValves, null))
|
||||
.EnterState();
|
||||
do
|
||||
{
|
||||
do {
|
||||
int remTime = areTwoDrainPhases ? (timerTime.Val + totalDrainTime - firstPhaseTime) : timerTime.Val;
|
||||
Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remTime / 60, "min", remTime % 60, Strings.sec));
|
||||
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
if (e.Contains(Event.Error)) goto error;
|
||||
bool stopDrainingCmd = e.Contains(Event.UiCmdStopDrainingTank1) || e.Contains(Event.UiCmdStopDrainingTank2) || e.Contains(Event.UiCmdStopDrainingTank3);
|
||||
if (stopDrainingCmd && !e.Contains(Event.ValvesBusy) && !e.Contains(Event.CameraBusy)) break;
|
||||
if (e.Contains(Event.Error)) return false;
|
||||
bool stopDrainingCmd = e.Contains(Event.UiCmdStopDrainingTank1) || e.Contains(Event.UiCmdStopDrainingTank2) || e.Contains(Event.UiCmdStopDrainingTank3);
|
||||
if (stopDrainingCmd && !e.Contains(Event.ValvesBusy) && !e.Contains(Event.CameraBusy)) break;
|
||||
}
|
||||
while (e.Contains(Event.TimerBusy) || e.Contains(Event.CameraBusy) || e.Contains(Event.ValvesBusy));
|
||||
while (e.Contains(Event.TimerBusy) || e.Contains(Event.CameraBusy) || e.Contains(Event.ValvesBusy));
|
||||
|
||||
if (areTwoDrainPhases)
|
||||
{
|
||||
@@ -318,13 +302,12 @@ namespace TBF.BenchControl.Sequences
|
||||
.AddOperation(new TimerOp(totalDrainTime - firstPhaseTime, timerTime))
|
||||
.AddOperation(StateMachine.ControlBoard.SetValvesOp(secondHalfDrainValves, null))
|
||||
.EnterState();
|
||||
do
|
||||
{
|
||||
do {
|
||||
int remTime = timerTime.Val;
|
||||
Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remTime / 60, "min", remTime % 60, Strings.sec));
|
||||
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
if (e.Contains(Event.Error)) goto error;
|
||||
if (e.Contains(Event.Error)) return false;
|
||||
bool stopDrainingCmd = e.Contains(Event.UiCmdStopDrainingTank1) || e.Contains(Event.UiCmdStopDrainingTank2) || e.Contains(Event.UiCmdStopDrainingTank3);
|
||||
if (stopDrainingCmd && !e.Contains(Event.ValvesBusy) && !e.Contains(Event.CameraBusy)) break;
|
||||
}
|
||||
@@ -333,22 +316,56 @@ namespace TBF.BenchControl.Sequences
|
||||
|
||||
Bridge.OnActivity(this, Strings.Emptying_tank);
|
||||
|
||||
State stopDraining = State.Create("MainSeq : Stop draining water tanks")
|
||||
State stopDraining = State.Create("MainSeq : Stop draining water tanks")
|
||||
.AddOperation(checkUiOp)
|
||||
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, allDrainValves))
|
||||
.EnterState();
|
||||
do
|
||||
{
|
||||
do {
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
if (e.Contains(Event.Error)) goto error;
|
||||
if (e.Contains(Event.Error)) return false;
|
||||
}
|
||||
while (e.Contains(Event.ValvesBusy));
|
||||
}
|
||||
|
||||
return true; /// OK
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Main sequence
|
||||
/// </summary>
|
||||
/// <param name="dummyArg"></param>
|
||||
/// <returns></returns>
|
||||
public void Execute()
|
||||
{
|
||||
IList<Event> e;
|
||||
Selection selection;
|
||||
string selectedTestName;
|
||||
|
||||
Bridge.OnActivity(this, Strings.Starting_system);
|
||||
WaitForOkButton();
|
||||
SetValvesToDefaultState();
|
||||
|
||||
|
||||
string scaleName;
|
||||
string message;
|
||||
if (TestCommunicationWithScales(out scaleName, out message) == false)
|
||||
{
|
||||
Bridge.OnError(this, string.Format("{0} : {1}", scaleName, message));
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
if (!DrainTanks())
|
||||
{
|
||||
Bridge.OnError(this, "Error when draining tanks");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
Bridge.OnActivity(this, Strings.Resetting_scales);
|
||||
//--------------------------------------------------------------------------------------------
|
||||
Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Resetting scales : Enable STOP button
|
||||
Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Resetting scales -> Enable STOP button
|
||||
|
||||
DoubleBox tara1 = new DoubleBox(0);
|
||||
DoubleBox tara2 = new DoubleBox(0);
|
||||
@@ -485,19 +502,43 @@ namespace TBF.BenchControl.Sequences
|
||||
|
||||
|
||||
StateMachine.CycleStartTimeStamp = BatchRslts.Batch.StartTime;
|
||||
|
||||
|
||||
Bridge.OnProcedureSelected(this, new ProcedureSelectedEventArgs(StateMachine.Procedure));
|
||||
|
||||
|
||||
///
|
||||
/// Display 'Cycle Begin Form' in case of a normal batch (not a restored batch)
|
||||
///
|
||||
if (selection != Selection.RestoreBatch)
|
||||
{
|
||||
if (OpenCycleBeginForm()) goto stop;
|
||||
if ((selection != Selection.RestoreBatch) && !OpenCycleBeginForm())
|
||||
{
|
||||
goto stop;
|
||||
}
|
||||
|
||||
///
|
||||
/// Prepare operations for reading start info @ cycle start
|
||||
///
|
||||
IList<IOperation> startInfoReadOps = new List<IOperation>();
|
||||
string[] resultWriters = StateMachine.Procedure.ResultsWriter.Split(new char[] { '~' });
|
||||
foreach (var writerName in resultWriters)
|
||||
{
|
||||
IStartInfoReader infoReader = TbfComponents.FindComponent(writerName) as IStartInfoReader;
|
||||
if (infoReader != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
IOperation op = infoReader.ReadStartInfoOp(ProcessData.BatchRslts.WaterMeters);
|
||||
if (op != null) startInfoReadOps.Add(op);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Bridge.OnError(this, string.Format(Strings.Component_0_crashed_Results_not_saved, writerName));
|
||||
log.FatalFormat("StartInfoReader {0} crashed: {1}", writerName, exc.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Find purge suquences
|
||||
///
|
||||
TransitionSequence purgeBegin = null;
|
||||
TransitionSequence purgeEnd = null;
|
||||
foreach (var transition in StateMachine.TransitionSequences)
|
||||
@@ -518,9 +559,9 @@ namespace TBF.BenchControl.Sequences
|
||||
/// Always ask a question in case of a restored batch
|
||||
///
|
||||
State.Create("MainSeq : Answer a question")
|
||||
.AddOperation(new Operations.AskYesNoOp(Strings.Fill_with_water))
|
||||
.AddOperation(checkUiOp)
|
||||
.EnterState();
|
||||
.AddOperation(new Operations.AskYesNoOp(Strings.Fill_with_water))
|
||||
.AddOperation(checkUiOp)
|
||||
.EnterState();
|
||||
do
|
||||
{
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
@@ -544,7 +585,6 @@ namespace TBF.BenchControl.Sequences
|
||||
Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingTests, simultWithPurgingParams });
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Purging @ cycle start
|
||||
///
|
||||
@@ -561,34 +601,10 @@ namespace TBF.BenchControl.Sequences
|
||||
break;
|
||||
}
|
||||
|
||||
///
|
||||
/// Prepare reading start info from the DB @ cycle start
|
||||
///
|
||||
State readingStartInfo = State.Create("MainSeq : Reading start info from DB");
|
||||
///
|
||||
string[] resultWriters = StateMachine.Procedure.ResultsWriter.Split(new char[] { '~' });
|
||||
foreach (var writerName in resultWriters)
|
||||
{
|
||||
IStartInfoReader infoReader = TbfComponents.FindComponent(writerName) as IStartInfoReader;
|
||||
if (infoReader != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
IOperation op = infoReader.ReadStartInfoOp(ProcessData.BatchRslts.WaterMeters);
|
||||
if (op != null) readingStartInfo.AddOperation(op);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Bridge.OnError(this, string.Format(Strings.Component_0_crashed_Results_not_saved, writerName));
|
||||
log.FatalFormat("StartInfoReader {0} crashed: {1}", writerName, exc.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Wait until iPerl communications or S/N data entry are completed
|
||||
///
|
||||
if ((simultWithPurgingCount > 0) || (readingStartInfo.Operations.Count > 0))
|
||||
if ((simultWithPurgingCount > 0) || (startInfoReadOps.Count > 0))
|
||||
{
|
||||
/// Get 'bool completed'
|
||||
bool completed = !(modelessDlg is GenericDevices.IHasCompleted) || (modelessDlg as GenericDevices.IHasCompleted).Completed;
|
||||
@@ -618,38 +634,41 @@ namespace TBF.BenchControl.Sequences
|
||||
modelessDlg = null;
|
||||
}
|
||||
|
||||
///
|
||||
/// Read start info from the DB @ cycle start
|
||||
///
|
||||
|
||||
if (readingStartInfo.Operations.Count > 0)
|
||||
assume_bench_filled:
|
||||
|
||||
benchFilled = true;
|
||||
Bridge.Bench2UI(ButtonsEtc.ShowBenchFilled);
|
||||
|
||||
if ((selection == Selection.Cycle) || (selection == Selection.RestoreBatch))
|
||||
{
|
||||
readingStartInfo.AddOperation(checkUiOp).EnterState();
|
||||
do
|
||||
///
|
||||
/// Read start info from the DB @ cycle start
|
||||
///
|
||||
if (startInfoReadOps.Count > 0)
|
||||
{
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
if (e.Contains(Event.Error)) goto error;
|
||||
if (e.Contains(Event.UiCmdStop)) goto stop;
|
||||
}
|
||||
while (e.Contains(Event.Busy));
|
||||
State.Create("MainSeq : Reading start info from DB")
|
||||
.AddOperations(startInfoReadOps)
|
||||
.AddOperation(checkUiOp).EnterState();
|
||||
do
|
||||
{
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
if (e.Contains(Event.Error)) goto error;
|
||||
if (e.Contains(Event.UiCmdStop)) goto stop;
|
||||
}
|
||||
while (e.Contains(Event.Busy));
|
||||
|
||||
if (e.Contains(Event.InfoNotRead))
|
||||
{
|
||||
log.ErrorFormat("StartInfoReader failed to read data from the database");
|
||||
/// TODO: Message for an operator? Error?
|
||||
}
|
||||
if (e.Contains(Event.InfoNotRead))
|
||||
{
|
||||
log.ErrorFormat("StartInfoReader failed to read data from the database");
|
||||
/// TODO: Message for an operator? Error?
|
||||
}
|
||||
|
||||
/// Redraw on-screen results
|
||||
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(string.Empty, null));
|
||||
/// Redraw on-screen results
|
||||
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(string.Empty, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
assume_bench_filled:
|
||||
|
||||
benchFilled = true;
|
||||
Bridge.Bench2UI(ButtonsEtc.ShowBenchFilled);
|
||||
|
||||
if (selection != Selection.PurgeBegin && selection != Selection.RestoreBatch)
|
||||
if ((selection != Selection.PurgeBegin) && (selection != Selection.RestoreBatch))
|
||||
{
|
||||
goto cycle_or_test_selected;
|
||||
}
|
||||
|
||||
@@ -760,22 +760,23 @@ namespace TBF.BenchControl.Sequences
|
||||
/// <summary>
|
||||
/// Opens a modeless dialog for entering data at the beginning of a procedure (serial numbers)
|
||||
/// </summary>
|
||||
/// <returns>false = OK, true = stop pressed</returns>
|
||||
/// <returns>true = OK, false = stop pressed</returns>
|
||||
protected bool OpenCycleBeginForm()
|
||||
{
|
||||
IList<Event> e;
|
||||
lastDataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry;
|
||||
|
||||
if (lastDataEntryCmpnt is IHasCycleBeginForm)
|
||||
{
|
||||
Bridge.OnActivity(this, Strings.Enter_water_meter_data);
|
||||
State.Create("MainSeq : Enter begin data")
|
||||
.AddPermanentOperation((lastDataEntryCmpnt as IHasCycleBeginForm).ShowCycleBeginFormOp())
|
||||
.AddOperation(checkUiOp)
|
||||
.EnterState();
|
||||
e = StateMachine.WaitRunDevsRunOps();
|
||||
if (TestAndLogUiCmdStop(e)) return true;
|
||||
.AddPermanentOperation((lastDataEntryCmpnt as IHasCycleBeginForm).ShowCycleBeginFormOp())
|
||||
.AddOperation(checkUiOp)
|
||||
.EnterState();
|
||||
|
||||
if (TestAndLogUiCmdStop(StateMachine.WaitRunDevsRunOps())) return false; /// Return false when STOP pressed
|
||||
}
|
||||
return false;
|
||||
|
||||
return true; /// OK (=either a cycle beginning form is open or DataEntry component is not IHasCycleBeginForm)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user