iPerl : (1) results DB change, (2) reading from Oracle on cycle start, (3) reading Q2 corr. factors from iPerl, (4) new result items, (5) MainSeq cleanup, ver. 2.18.1125

This commit is contained in:
Milan Hanajik
2019-01-29 16:05:29 +01:00
parent 88496cf003
commit f8ac27ba3c
13 changed files with 658 additions and 235 deletions
+142 -91
View File
@@ -91,7 +91,136 @@ namespace TBF.BenchControl.Sequences
simultWithEvacuationCfg = null;
simultWithEvacuationTests = new List<Config.Entities.Test>();
simultWithEvacuationParams = new List<Generic.ITestParams>();
}
checkUiOp = new CheckUIOp(true); /// Running in almost all states
}
/// <summary>
/// Unconditionally wait for OK button
/// </summary>
void WaitForOkButton()
{
State.Create("MainSeq : Press OK to start the system")
.AddOperation(new BenchControl.Operations.MessageBoxOp(Strings.Start_the_test_bench, System.Drawing.Color.OliveDrab))
.EnterState();
while (!StateMachine.WaitRunDevsRunOps().Contains(Event.OK)) { }
}
/// <summary>
/// Unconditionally set valves to default position
/// </summary>
void SetValvesToDefaultState()
{
State.Create("MainSeq : Setting valves to default positions")
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
.EnterState();
while (StateMachine.WaitRunDevsRunOps().Contains(Event.ValvesBusy)) { }
}
/// <summary>
/// Test communication with all scales that support S/N read operation
/// </summary>
/// <param name="scaleName">Name of a scale that failed</param>
/// <param name="message">Message in case of a failure</param>
/// <returns>true = Test passed, all scales communicate OK</returns>
bool TestCommunicationWithScales(out string scaleName, out string message)
{
///
/// Read S/N-s from scales (cannot be stopped, but is limitted to Scales count x 3s (=timeout)
///
IScaleOrTank[] tanks = new IScaleOrTank[] { StateMachine.Tank1, StateMachine.Tank2, StateMachine.Tank3 };
foreach (var tank in tanks)
{
if (tank is IScale)
{
IScale scale = tank as IScale;
string sn = string.Empty;
IOperation getSNOp = scale.GetSerNumOp(ref sn);
if (getSNOp != null)
{
const int nrRetries = 3;
for (int i = 1; i <= nrRetries; i++)
{
IList<Event> e;
bool error = false;
bool timeout = false;
State.Create(string.Format("MainSeq : Reading S/N of scale {0} trial {1}", scale.Name, i))
.AddOperation(getSNOp)
.AddOperation(new Operations.TimerOp(2))
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error))
{
if (i == nrRetries)
{
///
/// All retries completed => the scale failed
///
scaleName = scale.Name;
message = Strings.Scale_communication_error;
return false;
}
else
{
/// The scale failed => try one more time
error = true;
break;
}
}
if (e.Contains(Event.Busy) && e.Contains(Event.TimerExpired))
{
if (i == nrRetries)
{
///
/// All retries completed, the scale failed
///
scaleName = scale.Name;
message = Strings.Scale_communication_timeout;
return false;
}
else
{
/// The scale failed => try one more time
timeout = true;
break;
}
}
}
while (e.Contains(Event.Busy));
if (!error && !timeout)
{
/// This scale communicates OK, break "for (int i = ... " loop
if (!string.IsNullOrEmpty(sn)) log.WarnFormat("Scale {0} : s/n = {1}", scale.Name, sn);
break; ///
}
/// Wait one state machine tick (1 second), kreep retrying, stay inside "for (int i = ... " loop
State.Create(string.Format("MainSeq : Reading S/N of scale {0}", scale.Name)).EnterState();
StateMachine.WaitRunDevsRunOps();
}
}
}
}
///
/// All scales communicate OK, test passed
///
scaleName = string.Empty;
message = string.Empty;
return true;
}
/// <summary>
@@ -101,100 +230,21 @@ namespace TBF.BenchControl.Sequences
/// <returns></returns>
public IList<Event> Execute(Test dummyArg)
{
/// Operations running in more then one state
checkUiOp = new CheckUIOp(true);
IList<Event> e;
Selection selection;
string selectedTestName;
ISession sessn = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
StateMachine.LoadPathsAndTransitions(sessn); // TODO: Implement as an operation so that the worker thread is not blocked
string selectedTestName;
Bridge.OnActivity(this, Strings.Starting_system);
State.Create("MainSeq : Press OK to start the system")
.AddOperation(new BenchControl.Operations.MessageBoxOp(Strings.Start_the_test_bench, System.Drawing.Color.OliveDrab))
.EnterState();
while (!StateMachine.WaitRunDevsRunOps().Contains(Event.OK));
State.Create("MainSeq : Setting valves to default positions")
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
.EnterState();
while (StateMachine.WaitRunDevsRunOps().Contains(Event.ValvesBusy));
///
/// Read S/N-s from scales (cannot be stopped, but is limitted to Scales count x 3s (=timeout)
///
IScaleOrTank[] tanks = new IScaleOrTank[] { StateMachine.Tank1, StateMachine.Tank2, StateMachine.Tank3 };
foreach (var tank in tanks)
{
if (tank is IScale)
{
IScale scale = tank as IScale;
string sn = string.Empty;
IOperation getSNOp = scale.GetSerNumOp(ref sn);
if (getSNOp != null)
{
const int nrRetries = 3;
for (int i = 1; i <= nrRetries; i++)
{
bool error = false;
bool timeout = false;
State.Create(string.Format("MainSeq : Reading S/N of scale {0} trial {1}", scale.Name, i))
.AddOperation(getSNOp)
.AddOperation(new Operations.TimerOp(2))
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error))
{
if (i == nrRetries)
{
Bridge.OnError(this, string.Format("{0} : {1}", scale.Name, Strings.Scale_communication_error));
goto error;
}
else
{
error = true;
break;
}
}
if (e.Contains(Event.Busy) && e.Contains(Event.TimerExpired))
{
if (i == nrRetries)
{
Bridge.OnError(this, string.Format("{0} : {1}", scale.Name, Strings.Scale_communication_timeout));
goto error;
}
else
{
timeout = true;
break;
}
}
}
while (e.Contains(Event.Busy));
if (!error && !timeout)
{
/// Successful
if (!string.IsNullOrEmpty(sn)) log.WarnFormat("Scale {0} : s/n = {1}", scale.Name, sn);
break;
}
State.Create(string.Format("MainSeq : Reading S/N of scale {0}", scale.Name)).EnterState();
StateMachine.WaitRunDevsRunOps();
}
}
}
}
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
@@ -315,6 +365,7 @@ namespace TBF.BenchControl.Sequences
}
while (e.Contains(Event.Busy));
//--------------------------------------------------------------------------------------------
Bridge.OnActivity(this, Strings.Measuring_the_weight);
State.Create("MainSeq : Mesuring the weight for the 1st time")
@@ -541,7 +592,7 @@ namespace TBF.BenchControl.Sequences
{
try
{
IOperation op = infoReader.ReadStartInfoOp(ProcessData.BatchRslts.Batch);
IOperation op = infoReader.ReadStartInfoOp(ProcessData.BatchRslts.WaterMeters);
if (op != null) readingStartInfo.AddOperation(op);
}
catch (Exception exc)