UiBridge.Bridge.CloseModelessFormHandler isn't used, tank draining before a test is optional, fixes in simulations, ver. 2.18.1056

This commit is contained in:
Milan Hanajik
2018-11-12 16:57:28 +01:00
parent d2d571945c
commit f48a71ce12
10 changed files with 164 additions and 63 deletions
@@ -25,7 +25,7 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection
{
if (debugLevel == Config.Entities.DebugMode.Simulate)
{
Simulate(test, repetitionNr, isLastRepetition, testParams);
return Simulate(test, repetitionNr, isLastRepetition, testParams);
}
@@ -96,13 +96,16 @@ namespace TBF.BenchControl.TestMethods.FixedStartTankCollection
///
/// Drain the water tank
/// Optionally drain the water tank
///
if (test.DoDraining)
{
switch (DrainTheTank(tank))
{
case Event.Error: { retVal = Event.Error; goto stopTest; }
case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; }
}
}
//------------------------------------------------
@@ -35,7 +35,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl
{
if (debugLevel == Config.Entities.DebugMode.Simulate)
{
Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams, heatMetersTestParams);
return Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams, heatMetersTestParams);
}
@@ -36,7 +36,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged
{
if (debugLevel == Config.Entities.DebugMode.Simulate)
{
Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams, heatMetersTestParams);
return Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams, heatMetersTestParams);
}
@@ -34,11 +34,11 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection
{
if (debugLevel == Config.Entities.DebugMode.Simulate)
{
Simulate1(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams);
return Simulate1(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams);
}
else if (debugLevel == Config.Entities.DebugMode.Inherit)
{
Simulate2(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams);
return Simulate2(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams);
}
@@ -29,6 +29,11 @@ namespace TBF.BenchControl.TestMethods.FlyingStartTankCollection
Compound.CombinedTestParams compoundTestParams,
Config.Entities.DebugMode debugLevel)
{
if (debugLevel == Config.Entities.DebugMode.Simulate)
{
return Simulate(test, repetitionNr, isLastRepetition, compoundTestParams);
}
IList<Event> e = new List<Event>(); /// Events from currently running operations
ITankWithVolumeMsrmnt tank = outPath.Scale as ITankWithVolumeMsrmnt;
@@ -91,13 +96,16 @@ namespace TBF.BenchControl.TestMethods.FlyingStartTankCollection
///
/// Drain the water tank
/// Optionally drain the water tank
///
if (test.DoDraining)
{
switch (DrainTheTank(tank))
{
case Event.Error: { retVal = Event.Error; goto stopTest; }
case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; }
}
}
//------------------------------------------------
@@ -759,5 +767,81 @@ namespace TBF.BenchControl.TestMethods.FlyingStartTankCollection
retList.Add(retVal);
return retList;
}
public IList<Event> Simulate(Config.Entities.Test test, int repetitionNr, bool isLastRepetition,
Compound.CombinedTestParams compoundTestParams)
{
///
/// Test method simulation
///
ITankWithVolumeMsrmnt tank = outPath.Scale as ITankWithVolumeMsrmnt;
if (tank == null)
{
Bridge.OnError(this, Strings.Missing_a_tank_with_volume_measurement);
/// Create a list with one item 'retVal' (default is Event.Done) and return it
IList<Event> retListSim1 = new List<Event>(1);
retListSim1.Add(Event.ConfigurationError);
return retListSim1;
}
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting));
IList<Event> e = new List<Event>(); /// Events from currently running operations
Event retVal = Event.Done;
DoubleBox volumeBox = new DoubleBox();
///
IOperation msrVolOp = tank.MeasureVolumeOp(ref volumeBox);
State.Create(string.Format("{0}({1}) : Water level measurement", test.Method, test.Name))
.AddOperation(checkUiOp)
.AddOperation(msrVolOp)
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopSimulation; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopSimulation; }
}
while (!e.Contains(Event.VolumeDone));
///
log.WarnFormat("Volumes = {0}l", volumeBox.Val);
if (compoundTestParams != null)
{
if (test.Name.ToLower().Contains("nok")) MakeSimulatedCompound(test, 1, 0, 4.7f, 0.9f);
else MakeSimulatedCompound(test, 1, 0, 0.7f, 1.0f);
}
else
{
float errorPctBase = -1.0f;
if (test.Name.ToLower().Contains("q3")) errorPctBase = -0.5f;
else if (test.Name.ToLower().Contains("q2")) errorPctBase = 0.5f;
else if (test.Name.ToLower().Contains("q1")) errorPctBase = -5.1f;
MakeSimulated(test, repetitionNr, 0, errorPctBase + repetitionNr * 0.1f);
}
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Completed));
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0)));
allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file
//-------------------------------------------------------------------
Bridge.OnActivity(this, string.Format("{0} Simulation", test.Name));
//-------------------------------------------------------------------
State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name))
.AddOperation(checkUiOp)
.EnterState();
e = StateMachine.WaitRunDevsRunOps();
stopSimulation:
/// Create a list with one item 'retVal' (default is Event.Done) and return it
IList<Event> retListSim = new List<Event>(1);
retListSim.Add(retVal);
return retListSim;
}
}
}
@@ -20,7 +20,7 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
public double WaterLevelMm;
System.Windows.Forms.Form modelessDlg;
WaterLevelForm waterLevelForm;
bool resultSaved; /// Set in Run() when results are saved
@@ -61,10 +61,11 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
///
void OpenWaterLevelForm(ManualLevelMsrmnt myRef)
{
myRef.modelessDlg = new WaterLevelForm();
modelessDlg.Show();
myRef.waterLevelForm = new WaterLevelForm();
waterLevelForm.Show();
}
/// <summary>Start this operation</summary>
public void Start()
{
@@ -79,20 +80,17 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
/// <returns>Event.ResultsPrinted</returns>
public Event Run()
{
if ((modelessDlg is IHasCompleted) && !(modelessDlg as IHasCompleted).Completed)
if ((waterLevelForm != null) && !waterLevelForm.Completed)
{
return Event.Busy; /// = Form open
}
if (!resultSaved) /// This is to save the result only once
if (!resultSaved && (currentOp == CurrentOp.EnterLevel) && (waterLevelForm != null))
{
if ((modelessDlg is WaterLevelForm) && (currentOp == CurrentOp.EnterLevel))
{
WaterLevelMm = (modelessDlg as WaterLevelForm).WaterLevelMm;
/// Save the result (only once)
WaterLevelMm = waterLevelForm.WaterLevelMm;
if (levelBox != null) levelBox.Val = WaterLevelMm;
resultSaved = true;
modelessDlg = null;
}
}
return Event.LevelDone; /// = Form closed
@@ -101,10 +99,10 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
/// <summary>Stop this operation</summary>
public void Stop()
{
if (modelessDlg is IHasCompleted)
if (waterLevelForm != null)
{
UiBridge.Bridge.OnCloseModelessForm(this, null);
modelessDlg = null;
waterLevelForm.OnCloseThisForm(this, null);
waterLevelForm = null;
}
currentOp = CurrentOp.None;
}
@@ -8,7 +8,7 @@ using TBF.Resources;
namespace TBF.BenchControl.Various.ManualLevelMsrmnt
{
public partial class WaterLevelForm : Form, GenericDevices.IHasCompleted
public partial class WaterLevelForm : Form
{
private static readonly ILog log = LogManager.GetLogger(typeof(WaterLevelForm));
@@ -71,16 +71,36 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt
#region Forced close handling
/// <summary>
/// Used by CoverTest, AskYesNoOp and MessageBoxOp.
/// </summary>
public void OnCloseThisForm(object sender, EventArgs args)
{
if (CloseThisFormHandler == null) return;
try
{
CloseThisFormHandler(sender, null);
}
catch (Exception e)
{
log.Error("CloseThisFormHandler(...) failed", e);
}
}
public event EventHandler<EventArgs> CloseThisFormHandler;
public void StartForceCloseHandler()
{
UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args)
CloseThisFormHandler += delegate(object sender, EventArgs args)
{
if (InvokeRequired) { Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args); }
else OnForceClose(sender, args);
if (InvokeRequired)
Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args);
else
OnForceClose(sender, args);
};
}
void OnForceClose(object sender, EventArgs args)
private void OnForceClose(object sender, EventArgs args)
{
DialogResult = DialogResult.Cancel;
Close();
@@ -300,12 +300,8 @@ namespace TBF.BenchControl.Various.TankWithLevelMsrmnt
public IOperation MeasureVolumeOp(ref DoubleBox volume)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
if (readLevelOp == null)
{
readLevelOp = levelMeter.ReadLevelOp(ref levelBox);
}
this.volumeBox = volume;
readLevelOp = levelMeter.ReadLevelOp(ref levelBox);
currentOp = CurrentOp.MeasureVolume;
return this;
}
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.18.1055.0")]
[assembly: AssemblyFileVersion("2.18.1055.0")]
[assembly: AssemblyVersion("2.18.1056.0")]
[assembly: AssemblyFileVersion("2.18.1056.0")]