StartInfo is read from DB when previous results were reloaded.

This commit is contained in:
Milan Hanajik
2019-03-20 09:57:41 +01:00
parent 8624f30f71
commit a2bb50117e
2 changed files with 126 additions and 106 deletions
+117 -98
View File
@@ -225,34 +225,19 @@ namespace TBF.BenchControl.Sequences
/// <summary> /// <summary>
/// Main sequence ///
/// </summary> /// </summary>
/// <param name="dummyArg"></param> /// <returns>true = OK, false = error</returns>
/// <returns></returns> bool DrainTanks()
public void Execute()
{ {
IList<Event> e; 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 /// Enable stop draining buttons
/// ///
Bridge.Bench2UI(((StateMachine.DrainValve1 != null) ? ButtonsEtc.DrainTankBtn1Hi : 0) | Bridge.Bench2UI(((StateMachine.DrainValve1 != null) ? ButtonsEtc.DrainTankBtn1Hi : 0) |
((StateMachine.DrainValve2 != null) ? ButtonsEtc.DrainTankBtn2Hi : 0) | ((StateMachine.DrainValve2 != null) ? ButtonsEtc.DrainTankBtn2Hi : 0) |
((StateMachine.DrainValve3 != null) ? ButtonsEtc.DrainTankBtn3Hi : 0)); ((StateMachine.DrainValve3 != null) ? ButtonsEtc.DrainTankBtn3Hi : 0));
/// ///
/// Determine lists of drain valves and drain times (max. of all tank drain times) /// 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(new TimerOp(areTwoDrainPhases ? firstPhaseTime : totalDrainTime, timerTime))
.AddOperation(StateMachine.ControlBoard.SetValvesOp(fullDrainValves, null)) .AddOperation(StateMachine.ControlBoard.SetValvesOp(fullDrainValves, null))
.EnterState(); .EnterState();
do do {
{
int remTime = areTwoDrainPhases ? (timerTime.Val + totalDrainTime - firstPhaseTime) : timerTime.Val; 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)); Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remTime / 60, "min", remTime % 60, Strings.sec));
e = StateMachine.WaitRunDevsRunOps(); 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); 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 (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) if (areTwoDrainPhases)
{ {
@@ -318,13 +302,12 @@ namespace TBF.BenchControl.Sequences
.AddOperation(new TimerOp(totalDrainTime - firstPhaseTime, timerTime)) .AddOperation(new TimerOp(totalDrainTime - firstPhaseTime, timerTime))
.AddOperation(StateMachine.ControlBoard.SetValvesOp(secondHalfDrainValves, null)) .AddOperation(StateMachine.ControlBoard.SetValvesOp(secondHalfDrainValves, null))
.EnterState(); .EnterState();
do do {
{
int remTime = timerTime.Val; int remTime = timerTime.Val;
Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remTime / 60, "min", remTime % 60, Strings.sec)); Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remTime / 60, "min", remTime % 60, Strings.sec));
e = StateMachine.WaitRunDevsRunOps(); 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); 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 (stopDrainingCmd && !e.Contains(Event.ValvesBusy) && !e.Contains(Event.CameraBusy)) break;
} }
@@ -333,22 +316,56 @@ namespace TBF.BenchControl.Sequences
Bridge.OnActivity(this, Strings.Emptying_tank); 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(checkUiOp)
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, allDrainValves)) .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, allDrainValves))
.EnterState(); .EnterState();
do do {
{
e = StateMachine.WaitRunDevsRunOps(); e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) goto error; if (e.Contains(Event.Error)) return false;
} }
while (e.Contains(Event.ValvesBusy)); 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.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 tara1 = new DoubleBox(0);
DoubleBox tara2 = new DoubleBox(0); DoubleBox tara2 = new DoubleBox(0);
@@ -485,19 +502,43 @@ namespace TBF.BenchControl.Sequences
StateMachine.CycleStartTimeStamp = BatchRslts.Batch.StartTime; StateMachine.CycleStartTimeStamp = BatchRslts.Batch.StartTime;
Bridge.OnProcedureSelected(this, new ProcedureSelectedEventArgs(StateMachine.Procedure)); Bridge.OnProcedureSelected(this, new ProcedureSelectedEventArgs(StateMachine.Procedure));
/// ///
/// Display 'Cycle Begin Form' in case of a normal batch (not a restored batch) /// Display 'Cycle Begin Form' in case of a normal batch (not a restored batch)
/// ///
if (selection != Selection.RestoreBatch) if ((selection != Selection.RestoreBatch) && !OpenCycleBeginForm())
{ {
if (OpenCycleBeginForm()) goto stop; 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 /// Find purge suquences
///
TransitionSequence purgeBegin = null; TransitionSequence purgeBegin = null;
TransitionSequence purgeEnd = null; TransitionSequence purgeEnd = null;
foreach (var transition in StateMachine.TransitionSequences) foreach (var transition in StateMachine.TransitionSequences)
@@ -518,9 +559,9 @@ namespace TBF.BenchControl.Sequences
/// Always ask a question in case of a restored batch /// Always ask a question in case of a restored batch
/// ///
State.Create("MainSeq : Answer a question") State.Create("MainSeq : Answer a question")
.AddOperation(new Operations.AskYesNoOp(Strings.Fill_with_water)) .AddOperation(new Operations.AskYesNoOp(Strings.Fill_with_water))
.AddOperation(checkUiOp) .AddOperation(checkUiOp)
.EnterState(); .EnterState();
do do
{ {
e = StateMachine.WaitRunDevsRunOps(); e = StateMachine.WaitRunDevsRunOps();
@@ -544,7 +585,6 @@ namespace TBF.BenchControl.Sequences
Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingTests, simultWithPurgingParams }); Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingTests, simultWithPurgingParams });
} }
/// ///
/// Purging @ cycle start /// Purging @ cycle start
/// ///
@@ -561,34 +601,10 @@ namespace TBF.BenchControl.Sequences
break; 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 /// 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' /// Get 'bool completed'
bool completed = !(modelessDlg is GenericDevices.IHasCompleted) || (modelessDlg as GenericDevices.IHasCompleted).Completed; bool completed = !(modelessDlg is GenericDevices.IHasCompleted) || (modelessDlg as GenericDevices.IHasCompleted).Completed;
@@ -618,38 +634,41 @@ namespace TBF.BenchControl.Sequences
modelessDlg = null; modelessDlg = null;
} }
/// assume_bench_filled:
/// Read start info from the DB @ cycle start
/// benchFilled = true;
Bridge.Bench2UI(ButtonsEtc.ShowBenchFilled);
if (readingStartInfo.Operations.Count > 0)
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(); State.Create("MainSeq : Reading start info from DB")
if (e.Contains(Event.Error)) goto error; .AddOperations(startInfoReadOps)
if (e.Contains(Event.UiCmdStop)) goto stop; .AddOperation(checkUiOp).EnterState();
} do
while (e.Contains(Event.Busy)); {
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)) if (e.Contains(Event.InfoNotRead))
{ {
log.ErrorFormat("StartInfoReader failed to read data from the database"); log.ErrorFormat("StartInfoReader failed to read data from the database");
/// TODO: Message for an operator? Error? /// TODO: Message for an operator? Error?
} }
/// Redraw on-screen results /// Redraw on-screen results
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(string.Empty, null)); Bridge.OnTestCompleted(this, new TestCompletedEventArgs(string.Empty, null));
}
} }
if ((selection != Selection.PurgeBegin) && (selection != Selection.RestoreBatch))
assume_bench_filled:
benchFilled = true;
Bridge.Bench2UI(ButtonsEtc.ShowBenchFilled);
if (selection != Selection.PurgeBegin && selection != Selection.RestoreBatch)
{ {
goto cycle_or_test_selected; goto cycle_or_test_selected;
} }
+9 -8
View File
@@ -760,22 +760,23 @@ namespace TBF.BenchControl.Sequences
/// <summary> /// <summary>
/// Opens a modeless dialog for entering data at the beginning of a procedure (serial numbers) /// Opens a modeless dialog for entering data at the beginning of a procedure (serial numbers)
/// </summary> /// </summary>
/// <returns>false = OK, true = stop pressed</returns> /// <returns>true = OK, false = stop pressed</returns>
protected bool OpenCycleBeginForm() protected bool OpenCycleBeginForm()
{ {
IList<Event> e;
lastDataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry; lastDataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry;
if (lastDataEntryCmpnt is IHasCycleBeginForm) if (lastDataEntryCmpnt is IHasCycleBeginForm)
{ {
Bridge.OnActivity(this, Strings.Enter_water_meter_data); Bridge.OnActivity(this, Strings.Enter_water_meter_data);
State.Create("MainSeq : Enter begin data") State.Create("MainSeq : Enter begin data")
.AddPermanentOperation((lastDataEntryCmpnt as IHasCycleBeginForm).ShowCycleBeginFormOp()) .AddPermanentOperation((lastDataEntryCmpnt as IHasCycleBeginForm).ShowCycleBeginFormOp())
.AddOperation(checkUiOp) .AddOperation(checkUiOp)
.EnterState(); .EnterState();
e = StateMachine.WaitRunDevsRunOps();
if (TestAndLogUiCmdStop(e)) return true; 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)
} }