2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2019-02-06 09:34:43 +00:00
|
|
|
|
/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-06-15 07:38:18 +00:00
|
|
|
|
using System.Diagnostics;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using log4net;
|
2018-06-08 10:41:47 +00:00
|
|
|
|
using NHibernate;
|
2018-04-10 14:10:44 +00:00
|
|
|
|
using Config;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2017-04-12 19:45:58 +00:00
|
|
|
|
using Results.Entities;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
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;
|
2019-03-04 12:14:13 +00:00
|
|
|
|
using System.Threading;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Sequences
|
|
|
|
|
|
{
|
2015-02-01 15:20:27 +00:00
|
|
|
|
public class MainSeq : SequenceBase
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(MainSeq));
|
|
|
|
|
|
|
|
|
|
|
|
public override string ToString() { return "Sequences.MainSeq"; }
|
|
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
2017-06-30 10:04:55 +00:00
|
|
|
|
bool benchFilled;
|
|
|
|
|
|
|
2016-04-07 11:52:57 +00:00
|
|
|
|
int simultWithPurgingCount;
|
|
|
|
|
|
Generic.IComponentCfg simultWithPurgingCfg;
|
|
|
|
|
|
IList<Config.Entities.Test> simultWithPurgingTests;
|
|
|
|
|
|
IList<Generic.ITestParams> simultWithPurgingParams;
|
|
|
|
|
|
|
|
|
|
|
|
int simultWithEvacuationCount;
|
|
|
|
|
|
Generic.IComponentCfg simultWithEvacuationCfg;
|
|
|
|
|
|
IList<Config.Entities.Test> simultWithEvacuationTests;
|
|
|
|
|
|
IList<Generic.ITestParams> simultWithEvacuationParams;
|
|
|
|
|
|
|
2015-09-04 11:49:04 +00:00
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
|
|
|
|
///
|
2016-01-19 16:38:09 +00:00
|
|
|
|
delegate void iPerlCommFormDlgt(MainSeq myRef, Generic.IComponentCfg cfg, IList<Test> tests, IList<Generic.ITestParams> multiTestParams);
|
2015-09-04 11:49:04 +00:00
|
|
|
|
///
|
2016-01-19 16:38:09 +00:00
|
|
|
|
void OpenIPerlCommForm(MainSeq myRef, Generic.IComponentCfg cfg, IList<Test> tests, IList<Generic.ITestParams> multiTestParams)
|
2015-09-04 11:49:04 +00:00
|
|
|
|
{
|
2015-11-23 19:31:01 +00:00
|
|
|
|
try
|
2015-09-04 11:49:04 +00:00
|
|
|
|
{
|
2016-01-19 16:38:09 +00:00
|
|
|
|
/// 1nd argument
|
2015-11-23 19:31:01 +00:00
|
|
|
|
TestMethods.iPerlCommunication.TestMethodCfg iPerlCfg = cfg as TestMethods.iPerlCommunication.TestMethodCfg;
|
2015-09-04 11:49:04 +00:00
|
|
|
|
|
2016-01-19 16:38:09 +00:00
|
|
|
|
/// 2rd argument: as is
|
2016-01-03 01:05:35 +00:00
|
|
|
|
|
2016-01-19 16:38:09 +00:00
|
|
|
|
/// 3th argument
|
2015-11-23 19:31:01 +00:00
|
|
|
|
IList<TestMethods.iPerlCommunication.iPerlCommunicationParams> iPerlCommParams = new List<TestMethods.iPerlCommunication.iPerlCommunicationParams>();
|
|
|
|
|
|
foreach (var tp in multiTestParams) iPerlCommParams.Add(tp as TestMethods.iPerlCommunication.iPerlCommunicationParams);
|
2015-09-04 11:49:04 +00:00
|
|
|
|
|
2016-01-19 16:38:09 +00:00
|
|
|
|
myRef.modelessDlg = new TestMethods.iPerlCommunication.iPerlCommunicationForm(iPerlCfg, tests, iPerlCommParams);
|
2015-11-23 19:31:01 +00:00
|
|
|
|
myRef.modelessDlg.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
log.FatalFormat("---------------( MainSeq : OpenIperlCommForm crashed !!! )---------------");
|
|
|
|
|
|
log.FatalFormat("Message : {0}", e.Message);
|
|
|
|
|
|
if (e.InnerException != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
log.FatalFormat("InnerMessage : {0}", e.InnerException.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
log.FatalFormat("StackTrace : {0}{1}", Environment.NewLine, e.StackTrace);
|
|
|
|
|
|
log.Fatal("--------------------------------------");
|
|
|
|
|
|
}
|
2015-09-04 11:49:04 +00:00
|
|
|
|
}
|
2017-04-10 13:23:37 +00:00
|
|
|
|
///
|
2015-09-04 11:49:04 +00:00
|
|
|
|
void CloseIPerlCommForm()
|
|
|
|
|
|
{
|
|
|
|
|
|
UiBridge.Bridge.OnCloseModelessForm(this, null);
|
|
|
|
|
|
modelessDlg = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
/// <summary> Constructor </summary>
|
|
|
|
|
|
public MainSeq()
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-06-30 10:04:55 +00:00
|
|
|
|
benchFilled = false;
|
|
|
|
|
|
|
|
|
|
|
|
simultWithPurgingCount = 0;
|
|
|
|
|
|
simultWithPurgingCfg = null;
|
2016-04-07 11:52:57 +00:00
|
|
|
|
simultWithPurgingTests = new List<Config.Entities.Test>();
|
|
|
|
|
|
simultWithPurgingParams = new List<Generic.ITestParams>();
|
2017-06-30 10:04:55 +00:00
|
|
|
|
|
|
|
|
|
|
simultWithEvacuationCount = 0;
|
|
|
|
|
|
simultWithEvacuationCfg = null;
|
2016-04-07 11:52:57 +00:00
|
|
|
|
simultWithEvacuationTests = new List<Config.Entities.Test>();
|
|
|
|
|
|
simultWithEvacuationParams = new List<Generic.ITestParams>();
|
2019-01-23 07:34:31 +00:00
|
|
|
|
|
|
|
|
|
|
checkUiOp = new CheckUIOp(true); /// Running in almost all states
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
/// <summary>
|
2019-01-23 07:34:31 +00:00
|
|
|
|
/// Unconditionally wait for OK button
|
2014-08-12 16:22:32 +00:00
|
|
|
|
/// </summary>
|
2019-01-23 07:34:31 +00:00
|
|
|
|
void WaitForOkButton()
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2018-02-06 14:26:50 +00:00
|
|
|
|
State.Create("MainSeq : Press OK to start the system")
|
|
|
|
|
|
.AddOperation(new BenchControl.Operations.MessageBoxOp(Strings.Start_the_test_bench, System.Drawing.Color.OliveDrab))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
|
2019-01-23 07:34:31 +00:00
|
|
|
|
while (!StateMachine.WaitRunDevsRunOps().Contains(Event.OK)) { }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Unconditionally set valves to default position
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
void SetValvesToDefaultState()
|
|
|
|
|
|
{
|
2014-12-10 11:36:57 +00:00
|
|
|
|
State.Create("MainSeq : Setting valves to default positions")
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose))
|
2019-01-23 07:34:31 +00:00
|
|
|
|
.EnterState();
|
|
|
|
|
|
|
|
|
|
|
|
while (StateMachine.WaitRunDevsRunOps().Contains(Event.ValvesBusy)) { }
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-07-19 06:02:45 +00:00
|
|
|
|
|
2019-01-23 07:34:31 +00:00
|
|
|
|
/// <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)
|
|
|
|
|
|
{
|
2017-07-19 06:02:45 +00:00
|
|
|
|
///
|
2019-01-23 07:34:31 +00:00
|
|
|
|
/// 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 };
|
2017-06-26 11:22:36 +00:00
|
|
|
|
|
2019-01-23 07:34:31 +00:00
|
|
|
|
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>
|
|
|
|
|
|
/// Main sequence
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dummyArg"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2019-03-04 12:14:13 +00:00
|
|
|
|
public void Execute()
|
2019-01-23 07:34:31 +00:00
|
|
|
|
{
|
|
|
|
|
|
IList<Event> e;
|
|
|
|
|
|
Selection selection;
|
|
|
|
|
|
string selectedTestName;
|
2017-06-26 11:22:36 +00:00
|
|
|
|
|
2019-01-23 07:34:31 +00:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2018-10-26 08:19:33 +00:00
|
|
|
|
|
2017-07-19 06:02:45 +00:00
|
|
|
|
///
|
2018-10-26 08:19:33 +00:00
|
|
|
|
/// Enable stop draining buttons
|
2017-07-19 06:02:45 +00:00
|
|
|
|
///
|
2017-07-19 08:32:20 +00:00
|
|
|
|
Bridge.Bench2UI(((StateMachine.DrainValve1 != null) ? ButtonsEtc.DrainTankBtn1Hi : 0) |
|
|
|
|
|
|
((StateMachine.DrainValve2 != null) ? ButtonsEtc.DrainTankBtn2Hi : 0) |
|
|
|
|
|
|
((StateMachine.DrainValve3 != null) ? ButtonsEtc.DrainTankBtn3Hi : 0));
|
2014-12-10 11:36:57 +00:00
|
|
|
|
|
2018-10-26 08:19:33 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Determine lists of drain valves and drain times (max. of all tank drain times)
|
|
|
|
|
|
///
|
|
|
|
|
|
IList<IValve> fullDrainValves = new List<IValve>();
|
|
|
|
|
|
IList<IValve> secondHalfDrainValves = new List<IValve>();
|
|
|
|
|
|
IList<IValve> allDrainValves = new List<IValve>();
|
|
|
|
|
|
int totalDrainTime = 0;
|
|
|
|
|
|
int maxDrainTimeFor2VlvTanks = 0;
|
|
|
|
|
|
bool areTwoDrainPhases = false;
|
|
|
|
|
|
foreach (IScaleOrTank tank in new IScaleOrTank[] { StateMachine.Tank1, StateMachine.Tank2, StateMachine.Tank3 })
|
2014-12-10 11:36:57 +00:00
|
|
|
|
{
|
2018-10-26 08:19:33 +00:00
|
|
|
|
if (tank != null && tank.DrainValve != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tank.EmptyTimeSec > totalDrainTime) totalDrainTime = tank.EmptyTimeSec;
|
|
|
|
|
|
if (tank.DrainValve2 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
areTwoDrainPhases = true;
|
|
|
|
|
|
if (tank.EmptyTimeSec > maxDrainTimeFor2VlvTanks) maxDrainTimeFor2VlvTanks = tank.EmptyTimeSec;
|
|
|
|
|
|
|
|
|
|
|
|
if (!secondHalfDrainValves.Contains(tank.DrainValve)) secondHalfDrainValves.Add(tank.DrainValve);
|
|
|
|
|
|
if (!fullDrainValves.Contains(tank.DrainValve2)) fullDrainValves.Add(tank.DrainValve2);
|
|
|
|
|
|
if (!allDrainValves.Contains(tank.DrainValve)) allDrainValves.Add(tank.DrainValve);
|
|
|
|
|
|
if (!allDrainValves.Contains(tank.DrainValve2)) allDrainValves.Add(tank.DrainValve2);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!fullDrainValves.Contains(tank.DrainValve)) fullDrainValves.Add(tank.DrainValve);
|
|
|
|
|
|
if (!allDrainValves.Contains(tank.DrainValve)) allDrainValves.Add(tank.DrainValve);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-12-10 11:36:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-26 08:19:33 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Drain the tanks, two phases if necessary
|
|
|
|
|
|
///
|
|
|
|
|
|
if (totalDrainTime > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
IntBox timerTime = new IntBox(); /// Contains remaining time in each phase
|
|
|
|
|
|
int firstPhaseTime = maxDrainTimeFor2VlvTanks / 2;
|
|
|
|
|
|
|
|
|
|
|
|
State.Create(areTwoDrainPhases ? "MainSeq : Drain tanks - phase 1" : "MainSeq : Drain tanks")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(new TimerOp(areTwoDrainPhases ? firstPhaseTime : totalDrainTime, timerTime))
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(fullDrainValves, null))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (e.Contains(Event.TimerBusy) || e.Contains(Event.CameraBusy) || e.Contains(Event.ValvesBusy));
|
2014-12-10 21:39:53 +00:00
|
|
|
|
|
2018-10-26 08:19:33 +00:00
|
|
|
|
if (areTwoDrainPhases)
|
2014-12-10 11:36:57 +00:00
|
|
|
|
{
|
2018-10-26 08:19:33 +00:00
|
|
|
|
State.Create("MainSeq : Drain tanks - phase 2")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(new TimerOp(totalDrainTime - firstPhaseTime, timerTime))
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(secondHalfDrainValves, null))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
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;
|
|
|
|
|
|
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));
|
2014-12-10 11:36:57 +00:00
|
|
|
|
}
|
2014-12-10 21:39:53 +00:00
|
|
|
|
|
2018-10-26 08:19:33 +00:00
|
|
|
|
Bridge.OnActivity(this, Strings.Emptying_tank);
|
2017-07-19 06:02:45 +00:00
|
|
|
|
|
2018-10-26 08:19:33 +00:00
|
|
|
|
State stopDraining = State.Create("MainSeq : Stop draining water tanks")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, allDrainValves))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.Error)) goto error;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (e.Contains(Event.ValvesBusy));
|
2014-12-10 11:36:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
2017-06-26 11:22:36 +00:00
|
|
|
|
Bridge.OnActivity(this, Strings.Resetting_scales);
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
2019-03-04 12:14:13 +00:00
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Resetting scales : Enable STOP button
|
2017-07-19 08:32:20 +00:00
|
|
|
|
|
|
|
|
|
|
DoubleBox tara1 = new DoubleBox(0);
|
2017-06-26 11:22:36 +00:00
|
|
|
|
DoubleBox tara2 = new DoubleBox(0);
|
|
|
|
|
|
DoubleBox tara3 = new DoubleBox(0);
|
2017-06-26 13:27:26 +00:00
|
|
|
|
State.Create("MainSeq : Reset scales").AddOperation(checkUiOp)
|
2018-10-22 16:14:47 +00:00
|
|
|
|
.AddOperation((StateMachine.Tank1 is IScale) ? (StateMachine.Tank1 as IScale).TaringOp(ref tara1) : null)
|
|
|
|
|
|
.AddOperation((StateMachine.Tank2 is IScale) ? (StateMachine.Tank2 as IScale).TaringOp(ref tara2) : null)
|
|
|
|
|
|
.AddOperation((StateMachine.Tank3 is IScale) ? (StateMachine.Tank3 as IScale).TaringOp(ref tara3) : null)
|
2017-06-26 13:27:26 +00:00
|
|
|
|
.EnterState();
|
2014-12-10 11:36:57 +00:00
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.Error)) goto error;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (e.Contains(Event.Busy));
|
|
|
|
|
|
|
2019-01-23 07:34:31 +00:00
|
|
|
|
|
2014-12-10 11:36:57 +00:00
|
|
|
|
//--------------------------------------------------------------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Measuring_the_weight);
|
|
|
|
|
|
State.Create("MainSeq : Mesuring the weight for the 1st time")
|
2015-05-07 16:31:46 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(new MettlerToledo.ReadMassesOp())
|
2014-12-10 11:36:57 +00:00
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.Error)) goto error;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.BalanceDone));
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
2014-08-12 16:22:32 +00:00
|
|
|
|
select_procedure:
|
2015-01-15 05:34:36 +00:00
|
|
|
|
|
2017-04-10 13:23:37 +00:00
|
|
|
|
CloseBeginForm(); /// Make sure the CycleBeginForm is closed (after an abnormal end, etc.)
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
2019-03-04 12:14:13 +00:00
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
selection = MakeSelection(MKSelContext.ProcedureNotSelected);
|
|
|
|
|
|
if (selection == Selection.Shutdown)
|
|
|
|
|
|
{
|
|
|
|
|
|
Shutdown();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
while (selection == Selection.Shutdown);
|
|
|
|
|
|
|
2018-02-06 14:26:50 +00:00
|
|
|
|
switch (selection)
|
2017-12-08 09:34:02 +00:00
|
|
|
|
{
|
2018-02-06 14:26:50 +00:00
|
|
|
|
case Selection.Q1: selectedTestName = "Q1"; break;
|
|
|
|
|
|
case Selection.Q2: selectedTestName = "Q2"; break;
|
|
|
|
|
|
case Selection.Q3: selectedTestName = "Q3"; break;
|
|
|
|
|
|
default: selectedTestName = Bridge.SelectedTestName; break;
|
2017-12-08 09:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-15 07:38:18 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
using (ISession localSession = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config))
|
|
|
|
|
|
{
|
|
|
|
|
|
StateMachine.LoadPathsAndTransitions(localSession);
|
|
|
|
|
|
}
|
2018-06-19 07:25:24 +00:00
|
|
|
|
|
2018-06-20 12:38:32 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Try to load all parameters for the selected procedure from databases as specifie in BenchInfo
|
|
|
|
|
|
///
|
|
|
|
|
|
if ((Bridge.SelectedProcedure != null) && !string.IsNullOrEmpty(Bridge.SelectedProcedure.Name))
|
2018-06-15 07:38:18 +00:00
|
|
|
|
{
|
2018-06-19 07:25:24 +00:00
|
|
|
|
/// TODO: Repeate twice for Users.Entities.DBKind.Config and Users.Entities.DBKind.RemoteConfig
|
2018-06-20 12:38:32 +00:00
|
|
|
|
using (ISession remoteOrLocalSession = Config.FluentCommon.CreateSession(Bridge.SelectedProcedure.DBKind))
|
2018-06-19 07:25:24 +00:00
|
|
|
|
{
|
2018-06-20 12:38:32 +00:00
|
|
|
|
StateMachine.LoadProcedure(remoteOrLocalSession, Bridge.SelectedProcedure.Name);
|
2018-06-19 07:25:24 +00:00
|
|
|
|
StateMachine.LoadProcedureParams(StateMachine.Procedure);
|
2018-06-08 10:41:47 +00:00
|
|
|
|
|
2018-06-19 07:25:24 +00:00
|
|
|
|
/// This is to load Procedure.Tests and tets.MoreParams for each test
|
|
|
|
|
|
int a = 0;
|
|
|
|
|
|
foreach (var test in StateMachine.Procedure.Tests) a += test.MoreParams.Count;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-20 12:38:32 +00:00
|
|
|
|
else
|
2018-06-19 07:25:24 +00:00
|
|
|
|
{
|
|
|
|
|
|
StateMachine.Procedure = null;
|
2018-06-08 10:41:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-20 12:38:32 +00:00
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
StateMachine.Procedure = null;
|
|
|
|
|
|
}
|
2018-06-08 10:41:47 +00:00
|
|
|
|
}
|
2017-04-10 13:23:37 +00:00
|
|
|
|
while (StateMachine.Procedure == null); /// Make sure a valid procedure is selected
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
2018-06-15 07:38:18 +00:00
|
|
|
|
Debug.WriteLine(string.Empty);
|
|
|
|
|
|
Debug.WriteLine(string.Format("TransitionSequences {0}", NHibernateUtil.IsInitialized(StateMachine.TransitionSequences) ? "initialized" : "NOT initialized"));
|
|
|
|
|
|
Debug.WriteLine(string.Format("TransitionSteps {0}", NHibernateUtil.IsInitialized(StateMachine.TransitionSteps) ? "initialized" : "NOT initialized"));
|
|
|
|
|
|
Debug.WriteLine(string.Format("Procedure {0}", NHibernateUtil.IsInitialized(StateMachine.Procedure) ? "initialized" : "NOT initialized"));
|
|
|
|
|
|
Debug.WriteLine(string.Format("Procedure.MoreParams {0}", NHibernateUtil.IsInitialized(StateMachine.Procedure.MoreParams) ? "initialized" : "NOT initialized"));
|
|
|
|
|
|
Debug.WriteLine(string.Format("Procedure.Tests {0}", NHibernateUtil.IsInitialized(StateMachine.Procedure.Tests) ? "initialized" : "NOT initialized"));
|
|
|
|
|
|
Debug.WriteLine(string.Format("Procedure.Tests[0].MoreParams {0}", NHibernateUtil.IsInitialized(StateMachine.Procedure.Tests[0].MoreParams) ? "initialized" : "NOT initialized"));
|
|
|
|
|
|
|
2018-06-08 10:41:47 +00:00
|
|
|
|
UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any)
|
|
|
|
|
|
|
2015-12-04 11:24:55 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Procedure selected at this point, a new batch was started
|
|
|
|
|
|
///
|
2017-05-03 20:19:26 +00:00
|
|
|
|
StateMachine.ControlBoard.ManualUIAllowed = !StateMachine.Procedure.ManualCtrlDisabled;
|
2017-07-19 08:32:20 +00:00
|
|
|
|
|
2019-03-04 12:14:13 +00:00
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// A new cycle started : Enable STOP button
|
2017-12-01 10:45:26 +00:00
|
|
|
|
|
2017-07-19 08:32:20 +00:00
|
|
|
|
int newBatchNr = Program.LocalSettings.BatchNr;
|
2017-04-20 09:00:41 +00:00
|
|
|
|
log.FatalFormat("New measurement session started: batch = {0}, procedure = {1}", newBatchNr, StateMachine.Procedure.Name);
|
2016-01-10 12:15:14 +00:00
|
|
|
|
|
2017-12-01 10:45:26 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Clear iperlhead data (including PCB Number, avoid double use)
|
|
|
|
|
|
///
|
|
|
|
|
|
foreach (var cmpnt in StateMachine.Components)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (cmpnt is TestMethods.iPerlCommunication.iPerlHead.IperlHead)
|
|
|
|
|
|
{
|
|
|
|
|
|
(cmpnt as TestMethods.iPerlCommunication.iPerlHead.IperlHead).ClearData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-10 13:23:37 +00:00
|
|
|
|
if (selection == Selection.RestoreBatch)
|
2016-01-02 16:53:57 +00:00
|
|
|
|
{
|
2017-04-20 11:45:38 +00:00
|
|
|
|
BatchRslts = CreateNewBatchResults(newBatchNr, StateMachine.Procedure);
|
|
|
|
|
|
RestoreBatchResults(TBF.UiBridge.Bridge.BatchNr, ref BatchRslts); /// pass the original batch number of the batch to be restored
|
2017-04-10 13:23:37 +00:00
|
|
|
|
}
|
2017-04-12 15:33:47 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-04-20 09:00:41 +00:00
|
|
|
|
BatchRslts = CreateNewBatchResults(newBatchNr, StateMachine.Procedure);
|
2017-04-12 15:33:47 +00:00
|
|
|
|
}
|
2017-04-10 13:23:37 +00:00
|
|
|
|
|
2016-01-02 16:53:57 +00:00
|
|
|
|
|
2016-01-10 12:15:14 +00:00
|
|
|
|
StateMachine.CycleStartTimeStamp = BatchRslts.Batch.StartTime;
|
2015-12-04 11:24:55 +00:00
|
|
|
|
|
2016-04-07 11:52:57 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Bridge.OnProcedureSelected(this, new ProcedureSelectedEventArgs(StateMachine.Procedure));
|
|
|
|
|
|
|
2017-04-10 13:23:37 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Display 'Cycle Begin Form' in case of a normal batch (not a restored batch)
|
|
|
|
|
|
///
|
2019-01-09 12:48:51 +00:00
|
|
|
|
if (selection != Selection.RestoreBatch)
|
2017-04-10 13:23:37 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (OpenCycleBeginForm()) goto stop;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-08-13 14:20:00 +00:00
|
|
|
|
/// Find purge suquences
|
2015-12-04 16:17:20 +00:00
|
|
|
|
TransitionSequence purgeBegin = null;
|
|
|
|
|
|
TransitionSequence purgeEnd = null;
|
2014-08-12 12:52:42 +00:00
|
|
|
|
foreach (var transition in StateMachine.TransitionSequences)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2017-04-12 15:33:47 +00:00
|
|
|
|
else if ((selection == Selection.Cycle && benchFilled) || (selection == Selection.RestoreBatch))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-04-10 13:23:37 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Always ask a question in case of a restored batch
|
|
|
|
|
|
///
|
2014-07-28 07:54:35 +00:00
|
|
|
|
State.Create("MainSeq : Answer a question")
|
2014-08-12 20:21:26 +00:00
|
|
|
|
.AddOperation(new Operations.AskYesNoOp(Strings.Fill_with_water))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.No)) goto assume_bench_filled;
|
2014-08-12 16:22:32 +00:00
|
|
|
|
if (e.Contains(Event.UiCmdStop)) goto select_procedure;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.Yes));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fill_the_bench:
|
|
|
|
|
|
|
2016-04-07 11:52:57 +00:00
|
|
|
|
CollectSimultSteps();
|
2015-09-10 18:07:06 +00:00
|
|
|
|
///
|
|
|
|
|
|
if (simultWithPurgingCount > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Make sure the entry form is closed
|
|
|
|
|
|
if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stop;
|
|
|
|
|
|
|
|
|
|
|
|
/// Open iPerlCommunicationForm
|
2016-02-16 14:57:30 +00:00
|
|
|
|
ProcessData.RegisterReaders = StateMachine.GetMetersPath(simultWithPurgingTests[0]).RegisterReaders;
|
2016-01-19 16:38:09 +00:00
|
|
|
|
Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingTests, simultWithPurgingParams });
|
2015-09-05 22:09:52 +00:00
|
|
|
|
}
|
2015-09-04 11:49:04 +00:00
|
|
|
|
|
2019-02-06 09:34:43 +00:00
|
|
|
|
|
2015-09-04 11:49:04 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Purging @ cycle start
|
|
|
|
|
|
///
|
|
|
|
|
|
Event evt = Transition(purgeBegin, TransitionContext.PurgeBegin);
|
|
|
|
|
|
switch (evt)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2015-09-04 11:49:04 +00:00
|
|
|
|
case Event.Error:
|
|
|
|
|
|
if (simultWithPurgingCount > 0) CloseIPerlCommForm();
|
|
|
|
|
|
goto error;
|
|
|
|
|
|
case Event.UiCmdStop:
|
|
|
|
|
|
if (simultWithPurgingCount > 0) CloseIPerlCommForm();
|
|
|
|
|
|
goto stop;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2015-09-05 10:19:11 +00:00
|
|
|
|
|
2019-02-06 09:34:43 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// 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))
|
2015-09-05 10:19:11 +00:00
|
|
|
|
{
|
|
|
|
|
|
bool completed = !(modelessDlg is GenericDevices.IHasCompleted)
|
|
|
|
|
|
|| (modelessDlg as GenericDevices.IHasCompleted).Completed;
|
|
|
|
|
|
if (!completed)
|
|
|
|
|
|
{
|
|
|
|
|
|
State.Create("MainSeq : Wait until the entry form is closed")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop))
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseIPerlCommForm();
|
|
|
|
|
|
goto stop;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
completed = (modelessDlg as GenericDevices.IHasCompleted).Completed;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!completed);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
modelessDlg = null;
|
2019-01-09 12:48:51 +00:00
|
|
|
|
}
|
2017-04-12 15:33:47 +00:00
|
|
|
|
|
2019-01-09 12:48:51 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Read start info from the DB @ cycle start
|
|
|
|
|
|
///
|
|
|
|
|
|
if (readingStartInfo.Operations.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
readingStartInfo.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?
|
|
|
|
|
|
}
|
2019-02-06 09:34:43 +00:00
|
|
|
|
|
|
|
|
|
|
/// Redraw on-screen results
|
|
|
|
|
|
Bridge.OnTestCompleted(this, new TestCompletedEventArgs(string.Empty, null));
|
2019-01-09 12:48:51 +00:00
|
|
|
|
}
|
2015-09-04 11:49:04 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
assume_bench_filled:
|
|
|
|
|
|
|
|
|
|
|
|
benchFilled = true;
|
|
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.ShowBenchFilled);
|
|
|
|
|
|
|
2019-01-09 12:48:51 +00:00
|
|
|
|
if (selection != Selection.PurgeBegin && selection != Selection.RestoreBatch)
|
2014-08-12 12:52:42 +00:00
|
|
|
|
{
|
2014-08-12 16:22:32 +00:00
|
|
|
|
goto cycle_or_test_selected;
|
2014-08-12 12:52:42 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
select_cycle_or_test:
|
2015-04-28 13:27:47 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
selection = MakeSelection(MKSelContext.InsideProcedure);
|
2017-12-08 09:34:02 +00:00
|
|
|
|
switch (selection)
|
|
|
|
|
|
{
|
2018-02-06 14:26:50 +00:00
|
|
|
|
case Selection.Q1: selectedTestName = "Q1"; break;
|
|
|
|
|
|
case Selection.Q2: selectedTestName = "Q2"; break;
|
|
|
|
|
|
case Selection.Q3: selectedTestName = "Q3"; break;
|
|
|
|
|
|
default: selectedTestName = Bridge.SelectedTestName; break;
|
2017-12-08 09:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
///
|
2017-07-25 08:41:06 +00:00
|
|
|
|
UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any)
|
|
|
|
|
|
///
|
|
|
|
|
|
if (selection == Selection.PurgeBegin) goto fill_the_bench;
|
2017-06-30 10:04:55 +00:00
|
|
|
|
if (selection == Selection.PurgeEnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (DoEvacuation(purgeEnd))
|
|
|
|
|
|
{
|
|
|
|
|
|
case Event.Error: goto error;
|
|
|
|
|
|
case Event.UiCmdStop: goto stop;
|
|
|
|
|
|
default: goto select_cycle_or_test;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-05-22 14:43:17 +00:00
|
|
|
|
if (selection == Selection.Break)
|
|
|
|
|
|
{
|
2017-05-03 20:19:26 +00:00
|
|
|
|
StateMachine.ControlBoard.ManualUIAllowed = true;
|
2015-05-22 14:43:17 +00:00
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.ShowBenchEmpty);
|
2017-05-04 20:11:18 +00:00
|
|
|
|
Bridge.OnProcedureCompleted(this, new ProcedureCompletedEventArgs(StateMachine.Procedure));
|
|
|
|
|
|
goto select_procedure;
|
2015-05-22 14:43:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (selection == Selection.SaveResults) goto save_results;
|
2014-07-30 22:03:19 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
cycle_or_test_selected:
|
2014-07-30 22:03:19 +00:00
|
|
|
|
|
2017-05-03 20:19:26 +00:00
|
|
|
|
UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any)
|
2015-06-25 02:45:04 +00:00
|
|
|
|
|
2017-05-03 20:19:26 +00:00
|
|
|
|
if (UIFlowControl.Stop == WaitBeginFormClosed())
|
|
|
|
|
|
{
|
|
|
|
|
|
goto stop_within_cycle; /// Make sure the entry form is closed
|
|
|
|
|
|
}
|
2015-04-28 13:27:47 +00:00
|
|
|
|
|
2017-05-03 20:19:26 +00:00
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Hide buttons
|
2014-07-30 22:03:19 +00:00
|
|
|
|
|
2016-04-07 11:52:57 +00:00
|
|
|
|
if (selection != Selection.Cycle)
|
|
|
|
|
|
{
|
2016-04-07 12:53:34 +00:00
|
|
|
|
//--------------------------------
|
|
|
|
|
|
State.Create("MainSeq : Continue in the cycle?")
|
|
|
|
|
|
.AddOperation(new Operations.AskYesNoOp(Strings.Continue_in_the_cycle))
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.Yes))
|
|
|
|
|
|
{
|
|
|
|
|
|
selection = Selection.RestOfCycle;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (e.Contains(Event.No)) break;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop)) goto select_procedure;
|
|
|
|
|
|
}
|
2016-04-07 11:52:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-22 13:56:22 +00:00
|
|
|
|
///------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
if (selection == Selection.Cycle || selection == Selection.RestOfCycle)
|
|
|
|
|
|
{
|
|
|
|
|
|
IList<DeferredTestEvaluationData> deferredData = new List<DeferredTestEvaluationData>();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-11-22 13:56:22 +00:00
|
|
|
|
int selsctedTestIx = simultWithPurgingCount; /// Applies when selection == Selection.Cycle
|
|
|
|
|
|
int repetNr = 1;
|
|
|
|
|
|
///
|
|
|
|
|
|
if (selection == Selection.RestOfCycle) /// ... otherwise
|
2015-09-04 11:49:04 +00:00
|
|
|
|
{
|
2017-12-08 09:34:02 +00:00
|
|
|
|
Test slctdTest = TBF.BenchControl.StateMachine.GetTest(selectedTestName, out repetNr);
|
2017-11-22 13:56:22 +00:00
|
|
|
|
if (slctdTest == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiBridge.Bridge.OnError(this, string.Format("No test specified"));
|
2015-02-02 22:18:28 +00:00
|
|
|
|
goto select_cycle_or_test;
|
2015-09-04 11:49:04 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-11-22 13:56:22 +00:00
|
|
|
|
selsctedTestIx = -1;
|
|
|
|
|
|
for (int i = simultWithPurgingCount; i < StateMachine.Tests.Count - simultWithEvacuationCount; i++)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-11-22 13:56:22 +00:00
|
|
|
|
if (slctdTest == StateMachine.Tests[i])
|
2016-12-10 10:30:57 +00:00
|
|
|
|
{
|
2017-11-22 13:56:22 +00:00
|
|
|
|
selsctedTestIx = i;
|
|
|
|
|
|
break;
|
2016-12-10 10:30:57 +00:00
|
|
|
|
}
|
2015-02-02 22:18:28 +00:00
|
|
|
|
}
|
2017-11-22 13:56:22 +00:00
|
|
|
|
if (selsctedTestIx == -1) goto select_cycle_or_test; /// goto ... when selection is not valid
|
2016-04-07 12:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-24 12:59:20 +00:00
|
|
|
|
float TimeEstimateTotal = 0; /// Time estimate of the selected cycle or test
|
2016-04-07 12:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
for (int i = selsctedTestIx; i < StateMachine.Tests.Count - simultWithEvacuationCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Test test = StateMachine.Tests[i];
|
|
|
|
|
|
|
|
|
|
|
|
TimeEstimateTotal += (test.Repeats * (test.TstTime + 10.0f));
|
|
|
|
|
|
|
|
|
|
|
|
/// Try to fetch all test paths and transitions
|
|
|
|
|
|
/// to detect configuration errors as early as possible.
|
|
|
|
|
|
string errorMsg;
|
2017-11-22 13:56:22 +00:00
|
|
|
|
TBF.BenchControl.Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method);
|
|
|
|
|
|
if (!(testMethodComp is TBF.BenchControl.TestMethods.OuterLoop.Start.Component) &&
|
|
|
|
|
|
!(testMethodComp is TBF.BenchControl.TestMethods.OuterLoop.End.Component) &&
|
2016-12-10 15:27:51 +00:00
|
|
|
|
!StateMachine.GetPaths(test, (StateMachine.Procedure.MetersKind == MetersKind.HeatMeter),
|
2016-07-07 07:52:54 +00:00
|
|
|
|
out inPath, out benchPath, out outPath, out sensPath,
|
|
|
|
|
|
out heatMetersPath,
|
2018-11-14 07:23:01 +00:00
|
|
|
|
out transitionBefore, out transitionBetween, out transitionAfter,
|
2016-07-07 07:52:54 +00:00
|
|
|
|
out errorMsg))
|
|
|
|
|
|
{
|
2016-04-07 12:53:34 +00:00
|
|
|
|
UiBridge.Bridge.OnError(this, errorMsg);
|
|
|
|
|
|
goto select_cycle_or_test;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-10 10:30:57 +00:00
|
|
|
|
int currentTestIx = selsctedTestIx;
|
2017-12-02 16:54:38 +00:00
|
|
|
|
bool isOuterLoopMode = false;
|
2017-12-08 09:34:02 +00:00
|
|
|
|
int outerLoopStartIx = -1; /// This is to identify program errors
|
|
|
|
|
|
int outerLoopRepeats = 0;
|
2016-12-20 14:43:28 +00:00
|
|
|
|
while (currentTestIx < StateMachine.Tests.Count - simultWithEvacuationCount)
|
2016-04-07 12:53:34 +00:00
|
|
|
|
{
|
2016-12-10 10:30:57 +00:00
|
|
|
|
Test test = StateMachine.Tests[currentTestIx];
|
2018-01-24 12:59:20 +00:00
|
|
|
|
Test nextTest = (currentTestIx + 1 < StateMachine.Tests.Count - simultWithEvacuationCount)
|
|
|
|
|
|
? StateMachine.Tests[currentTestIx + 1]
|
|
|
|
|
|
: null;
|
2016-04-07 12:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// Fetch the test paths and transitions
|
|
|
|
|
|
string errorMsg;
|
2017-11-22 13:56:22 +00:00
|
|
|
|
TBF.BenchControl.Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method);
|
|
|
|
|
|
if (!(testMethodComp is TBF.BenchControl.TestMethods.OuterLoop.Start.Component) &&
|
|
|
|
|
|
!(testMethodComp is TBF.BenchControl.TestMethods.OuterLoop.End.Component) &&
|
2016-12-10 15:27:51 +00:00
|
|
|
|
!StateMachine.GetPaths(test, (StateMachine.Procedure.MetersKind == MetersKind.HeatMeter),
|
2016-07-07 07:52:54 +00:00
|
|
|
|
out inPath, out benchPath, out outPath, out sensPath,
|
|
|
|
|
|
out heatMetersPath,
|
2018-11-14 07:23:01 +00:00
|
|
|
|
out transitionBefore, out transitionBetween, out transitionAfter,
|
2016-07-07 07:52:54 +00:00
|
|
|
|
out errorMsg))
|
|
|
|
|
|
{
|
2016-04-07 12:53:34 +00:00
|
|
|
|
UiBridge.Bridge.OnError(this, errorMsg);
|
|
|
|
|
|
goto select_cycle_or_test;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Update format for the water mass
|
2017-03-28 21:47:32 +00:00
|
|
|
|
Mass.Format = outPath.Scale.Format;
|
|
|
|
|
|
StartMass.Format = outPath.Scale.Format;
|
|
|
|
|
|
EndMass.Format = outPath.Scale.Format;
|
2016-04-07 12:53:34 +00:00
|
|
|
|
|
2017-11-22 13:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
ITestMethod testMethod = testMethodComp as ITestMethod;
|
|
|
|
|
|
if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind))
|
2016-04-07 12:53:34 +00:00
|
|
|
|
{
|
2018-06-19 07:25:24 +00:00
|
|
|
|
StateMachine.LoadTestParams(test);
|
2016-04-07 12:53:34 +00:00
|
|
|
|
ProcessData.RegisterReaders = sensPath.RegisterReaders;
|
2018-01-24 12:59:20 +00:00
|
|
|
|
if (isOuterLoopMode && outerLoopRepeats != test.Repeats && !(testMethod is TestMethods.OuterLoop.End.Component))
|
2017-12-08 09:34:02 +00:00
|
|
|
|
{
|
|
|
|
|
|
goto config_error;
|
|
|
|
|
|
}
|
2016-04-07 12:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
|
|
|
|
{
|
2017-05-31 12:51:26 +00:00
|
|
|
|
if ((rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) && (BenchInfo != null))
|
2016-04-07 12:53:34 +00:00
|
|
|
|
{
|
2017-05-31 12:51:26 +00:00
|
|
|
|
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).BenchName = BenchInfo.TestBenchName;
|
2016-04-07 12:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-02 16:54:38 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Execute one test (single repetition of a repeated test)
|
|
|
|
|
|
/// Previously:
|
|
|
|
|
|
/// e = testMethod.Execute(test, outerLoopMode, (outerLoopMode ? outerLoopCounter: repetNr));
|
|
|
|
|
|
///
|
|
|
|
|
|
Event rsltTransBefore = Event.Done;
|
2018-11-14 07:23:01 +00:00
|
|
|
|
Event rsltTransBetween = Event.Done;
|
2017-12-02 16:54:38 +00:00
|
|
|
|
Event rsltTransAfter = Event.Done;
|
|
|
|
|
|
{
|
|
|
|
|
|
int timeEstTransBefore = testMethod.DoTransitions() ? GetTransitionTimeEst(transitionBefore) : 1;
|
2018-11-14 07:23:01 +00:00
|
|
|
|
int timeEstTransBetween = testMethod.DoTransitions() ? GetTransitionTimeEst(transitionBetween) : 1;
|
2017-12-02 16:54:38 +00:00
|
|
|
|
int timeEstTransAfter = testMethod.DoTransitions() ? GetTransitionTimeEst(transitionAfter) : 1;
|
2016-04-07 12:53:34 +00:00
|
|
|
|
|
2017-12-02 16:54:38 +00:00
|
|
|
|
TestProgressEventArgs.SetEstimatedTimes(new int[] { 1, timeEstTransBefore, 1, 30, 0, Convert.ToInt32(test.TstTime) + 15, timeEstTransAfter, 0 });
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetNr, Config.Entities.Progress.JustStarted));
|
|
|
|
|
|
|
2018-06-01 11:58:59 +00:00
|
|
|
|
bool currentTestFinished = true;
|
2018-11-14 15:41:58 +00:00
|
|
|
|
bool doOneMoreRepetition = false;
|
|
|
|
|
|
do
|
2017-12-02 16:54:38 +00:00
|
|
|
|
{
|
2018-11-14 15:41:58 +00:00
|
|
|
|
if (testMethod.DoTransitions())
|
2017-12-02 16:54:38 +00:00
|
|
|
|
{
|
2018-11-14 15:41:58 +00:00
|
|
|
|
/// Make a transition before a test and before each test repetition
|
|
|
|
|
|
rsltTransBefore = Transition(transitionBefore, TransitionContext.BeforeTest); /// Transition or SetRoute - start of test
|
|
|
|
|
|
log.InfoFormat("Test {0}: Transition({1}, BeforeTest) returned {2}", test.Name, (transitionBefore == null ? "null" : transitionBefore.Name), rsltTransBefore);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (rsltTransBefore != Event.Done) break;
|
2017-12-02 16:54:38 +00:00
|
|
|
|
|
2018-11-14 15:41:58 +00:00
|
|
|
|
log.InfoFormat("Test {0}: Execute(., {1}, {2})", test.Name, repetNr, isOuterLoopMode || repetNr == test.Repeats);
|
|
|
|
|
|
e = testMethod.Execute(test, repetNr, isOuterLoopMode || repetNr == test.Repeats);
|
2017-12-02 16:54:38 +00:00
|
|
|
|
|
2018-11-14 15:41:58 +00:00
|
|
|
|
if (e.Contains(Event.MakeSecondPass) && testMethod is ITestMethodWith2ndPass)
|
|
|
|
|
|
{
|
|
|
|
|
|
deferredData.Add(new DeferredTestEvaluationData(test, repetNr, (testMethod as ITestMethodWith2ndPass).IntermediateData));
|
|
|
|
|
|
}
|
2017-12-02 16:54:38 +00:00
|
|
|
|
|
2018-11-14 15:41:58 +00:00
|
|
|
|
currentTestFinished = (rsltTransBefore == Event.Done && !e.Contains(Event.Error)
|
|
|
|
|
|
&& !e.Contains(Event.ConfigurationError)
|
|
|
|
|
|
&& !e.Contains(Event.OpArgumentError)
|
|
|
|
|
|
&& !e.Contains(Event.UiCmdStop));
|
2018-06-01 11:58:59 +00:00
|
|
|
|
|
2018-11-14 15:41:58 +00:00
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetNr, currentTestFinished ? Config.Entities.Progress.Completed
|
|
|
|
|
|
: Config.Entities.Progress.Aborted));
|
2018-11-14 07:23:01 +00:00
|
|
|
|
|
2018-11-14 15:41:58 +00:00
|
|
|
|
if (e.Contains(Event.OuterLoopStart)) break; /// Do not repeat OuterLoopStart test in this loop
|
|
|
|
|
|
if (currentTestFinished && !isOuterLoopMode) repetNr++;
|
2018-11-14 07:23:01 +00:00
|
|
|
|
|
2018-11-14 15:41:58 +00:00
|
|
|
|
doOneMoreRepetition = currentTestFinished && !isOuterLoopMode && (repetNr <= test.Repeats);
|
2017-12-02 16:54:38 +00:00
|
|
|
|
|
2018-11-14 15:41:58 +00:00
|
|
|
|
if (testMethod.DoTransitions() && doOneMoreRepetition)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Make a transition between two test repetitions
|
|
|
|
|
|
rsltTransBetween = Transition(transitionBetween, TransitionContext.BetweenTests); /// Transition or SetRoute - start of test
|
|
|
|
|
|
log.InfoFormat("Test {0}: Transition({1}, BetweenTests) returned {2}", test.Name, (transitionBetween == null ? "null" : transitionBetween.Name), rsltTransBetween);
|
|
|
|
|
|
}
|
2017-12-02 16:54:38 +00:00
|
|
|
|
}
|
2018-11-14 15:41:58 +00:00
|
|
|
|
while ((rsltTransBetween == Event.Done) && doOneMoreRepetition);
|
|
|
|
|
|
|
|
|
|
|
|
if (currentTestFinished && !isOuterLoopMode && repetNr > test.Repeats) repetNr = 1; /// Reset repetNr
|
2017-12-02 16:54:38 +00:00
|
|
|
|
|
2018-06-06 07:50:52 +00:00
|
|
|
|
if (testMethod.DoTransitions())
|
2017-12-02 16:54:38 +00:00
|
|
|
|
{
|
2018-11-14 15:41:58 +00:00
|
|
|
|
/// Make a transition after the last test repetition
|
2018-06-01 11:58:59 +00:00
|
|
|
|
TransitionContext endContext = currentTestFinished ? TransitionContext.AfterTest : TransitionContext.Stop;
|
2017-12-02 16:54:38 +00:00
|
|
|
|
rsltTransAfter = Transition(transitionAfter, endContext); /// Transition or SetRoute - end of test
|
|
|
|
|
|
log.InfoFormat("Test {0}: Transition({1}, {2}) returned {3}", test.Name, (transitionAfter == null ? "null" : transitionAfter.Name), endContext, rsltTransAfter);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-14 07:23:01 +00:00
|
|
|
|
if (rsltTransBefore == Event.Error || rsltTransBetween == Event.Error|| e.Contains(Event.Error))
|
2017-12-02 16:54:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
isOuterLoopMode = false;
|
|
|
|
|
|
goto error;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (e.Contains(Event.ConfigurationError))
|
2016-12-10 10:30:57 +00:00
|
|
|
|
{
|
2017-12-02 16:54:38 +00:00
|
|
|
|
isOuterLoopMode = false;
|
|
|
|
|
|
goto select_cycle_or_test; /// OR goto config_error; ???
|
2016-12-10 10:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (e.Contains(Event.OpArgumentError))
|
|
|
|
|
|
{
|
2017-12-02 16:54:38 +00:00
|
|
|
|
isOuterLoopMode = false;
|
2016-12-10 10:30:57 +00:00
|
|
|
|
goto config_error;
|
|
|
|
|
|
}
|
2017-12-02 16:54:38 +00:00
|
|
|
|
else if (rsltTransBefore == Event.UiCmdStop || e.Contains(Event.UiCmdStop))
|
2016-12-10 10:30:57 +00:00
|
|
|
|
{
|
2017-12-02 16:54:38 +00:00
|
|
|
|
isOuterLoopMode = false;
|
2016-12-10 10:30:57 +00:00
|
|
|
|
goto stop_within_cycle;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (e.Contains(Event.OuterLoopStart))
|
|
|
|
|
|
{
|
2017-12-08 09:34:02 +00:00
|
|
|
|
if (isOuterLoopMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
goto config_error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-02 16:54:38 +00:00
|
|
|
|
isOuterLoopMode = true;
|
2018-01-24 12:59:20 +00:00
|
|
|
|
outerLoopRepeats = (nextTest != null) ? nextTest.Repeats : 1;
|
2017-12-02 16:54:38 +00:00
|
|
|
|
repetNr = 1;
|
2016-12-10 10:30:57 +00:00
|
|
|
|
outerLoopStartIx = currentTestIx;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (e.Contains(Event.OuterLoopEnd))
|
|
|
|
|
|
{
|
2018-01-24 12:59:20 +00:00
|
|
|
|
if (!isOuterLoopMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
goto config_error;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (++repetNr <= outerLoopRepeats)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentTestIx = outerLoopStartIx;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
isOuterLoopMode = false;
|
|
|
|
|
|
repetNr = 1; /// Reset repetNr
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-07 12:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-11-22 13:56:22 +00:00
|
|
|
|
UiBridge.Bridge.OnError(this, string.Format(Strings.Method_0_cannot_be_used, test.Method));
|
2016-04-07 12:53:34 +00:00
|
|
|
|
goto select_cycle_or_test;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-10 10:30:57 +00:00
|
|
|
|
currentTestIx++;
|
2016-04-07 12:53:34 +00:00
|
|
|
|
}
|
2017-11-22 13:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Execute deferred evaluations of tests that returned 'Event.MakeSecondPass' here
|
|
|
|
|
|
///
|
|
|
|
|
|
foreach (var dfrrdData in deferredData)
|
|
|
|
|
|
{
|
|
|
|
|
|
string errorMsg;
|
|
|
|
|
|
StateMachine.GetPaths(dfrrdData.Test, (StateMachine.Procedure.MetersKind == MetersKind.HeatMeter),
|
|
|
|
|
|
out inPath, out benchPath, out outPath, out sensPath,
|
|
|
|
|
|
out heatMetersPath,
|
2018-11-14 07:23:01 +00:00
|
|
|
|
out transitionBefore, out transitionBetween, out transitionAfter,
|
|
|
|
|
|
out errorMsg);
|
2017-11-22 13:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
ITestMethodWith2ndPass testMethod = TbfComponents.FindComponent(dfrrdData.Test.Method) as ITestMethodWith2ndPass;
|
|
|
|
|
|
|
|
|
|
|
|
if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind))
|
|
|
|
|
|
{
|
2018-06-19 07:25:24 +00:00
|
|
|
|
StateMachine.LoadTestParams(dfrrdData.Test);
|
2017-11-22 13:56:22 +00:00
|
|
|
|
ProcessData.RegisterReaders = sensPath.RegisterReaders;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) && (BenchInfo != null))
|
|
|
|
|
|
{
|
|
|
|
|
|
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).BenchName = BenchInfo.TestBenchName;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e = testMethod.Execute2ndPass(dfrrdData.Test, dfrrdData.RepetNr, dfrrdData.IntermediateData);
|
|
|
|
|
|
|
|
|
|
|
|
if (e.Contains(Event.Error)) goto error;
|
|
|
|
|
|
else if (e.Contains(Event.OpArgumentError)) goto config_error;
|
|
|
|
|
|
else if (e.Contains(Event.UiCmdStop)) goto stop_within_cycle;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
deferredData.Clear();
|
2016-04-07 12:53:34 +00:00
|
|
|
|
}
|
2017-11-22 13:56:22 +00:00
|
|
|
|
///------------------------------------------------------------------------------------------------------------
|
2017-12-08 09:34:02 +00:00
|
|
|
|
else /// if (selection == Selection.Test or Q1 or Q2 or Q3)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-10-19 07:19:31 +00:00
|
|
|
|
int repetNr;
|
2017-12-08 09:34:02 +00:00
|
|
|
|
Test test = TBF.BenchControl.StateMachine.GetTest(selectedTestName, out repetNr);
|
2015-05-20 14:18:54 +00:00
|
|
|
|
if (test == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiBridge.Bridge.OnError(this, string.Format("No test specified"));
|
|
|
|
|
|
goto select_cycle_or_test;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
/// Fetch the test paths and transitions
|
2015-05-20 14:18:54 +00:00
|
|
|
|
string errorMsg;
|
2017-11-22 13:56:22 +00:00
|
|
|
|
TBF.BenchControl.Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method);
|
|
|
|
|
|
if (!(testMethodComp is TBF.BenchControl.TestMethods.OuterLoop.Start.Component) &&
|
|
|
|
|
|
!(testMethodComp is TBF.BenchControl.TestMethods.OuterLoop.End.Component) &&
|
2016-12-10 15:27:51 +00:00
|
|
|
|
!StateMachine.GetPaths(test, (StateMachine.Procedure.MetersKind == MetersKind.HeatMeter),
|
2016-07-07 07:52:54 +00:00
|
|
|
|
out inPath, out benchPath, out outPath, out sensPath,
|
|
|
|
|
|
out heatMetersPath,
|
2018-11-14 07:23:01 +00:00
|
|
|
|
out transitionBefore, out transitionBetween, out transitionAfter,
|
2016-07-07 07:52:54 +00:00
|
|
|
|
out errorMsg))
|
2014-08-12 16:22:32 +00:00
|
|
|
|
{
|
2015-05-20 14:18:54 +00:00
|
|
|
|
UiBridge.Bridge.OnError(this, errorMsg);
|
2015-02-02 22:18:28 +00:00
|
|
|
|
goto select_cycle_or_test;
|
|
|
|
|
|
}
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
2015-03-25 09:01:37 +00:00
|
|
|
|
/// Update format for the water mass
|
2018-08-22 15:51:31 +00:00
|
|
|
|
Mass.Format = (outPath != null && outPath.Scale != null) ? outPath.Scale.Format : "F3";
|
|
|
|
|
|
StartMass.Format = (outPath != null && outPath.Scale != null) ? outPath.Scale.Format : "F3";
|
|
|
|
|
|
EndMass.Format = (outPath != null && outPath.Scale != null) ? outPath.Scale.Format : "F3";
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
2017-11-23 08:15:25 +00:00
|
|
|
|
ITestMethod testMethod = TbfComponents.FindComponent(test.Method) as ITestMethod;
|
|
|
|
|
|
if (testMethod != null && testMethod.CanTest(StateMachine.Procedure.MetersKind))
|
2015-02-02 22:18:28 +00:00
|
|
|
|
{
|
2018-06-19 07:25:24 +00:00
|
|
|
|
StateMachine.LoadTestParams(test);
|
2016-02-13 07:18:49 +00:00
|
|
|
|
ProcessData.RegisterReaders = sensPath.RegisterReaders;
|
2015-08-22 11:34:10 +00:00
|
|
|
|
|
2016-02-13 07:18:49 +00:00
|
|
|
|
foreach (var rr in sensPath.RegisterReaders)
|
|
|
|
|
|
{
|
2017-05-31 12:51:26 +00:00
|
|
|
|
if ((rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) && (BenchInfo != null))
|
2016-02-13 07:18:49 +00:00
|
|
|
|
{
|
2017-05-31 12:51:26 +00:00
|
|
|
|
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).BenchName = BenchInfo.TestBenchName;
|
2016-02-13 07:18:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-08-22 11:34:10 +00:00
|
|
|
|
|
2017-12-02 16:54:38 +00:00
|
|
|
|
Event rsltTransBefore = Event.Done;
|
|
|
|
|
|
Event rsltTransAfter = Event.Done;
|
|
|
|
|
|
{
|
|
|
|
|
|
int timeEstTransBefore = testMethod.DoTransitions() ? GetTransitionTimeEst(transitionBefore) : 1;
|
2018-11-14 07:23:01 +00:00
|
|
|
|
int timeEstTransBetween = testMethod.DoTransitions() ? GetTransitionTimeEst(transitionBetween) : 1;
|
2017-12-02 16:54:38 +00:00
|
|
|
|
int timeEstTransAfter = testMethod.DoTransitions() ? GetTransitionTimeEst(transitionAfter) : 1;
|
2017-11-23 08:15:25 +00:00
|
|
|
|
|
2017-12-02 16:54:38 +00:00
|
|
|
|
TestProgressEventArgs.SetEstimatedTimes(new int[] { 1, timeEstTransBefore, 1, 30, 0, Convert.ToInt32(test.TstTime) + 15, timeEstTransAfter, 0 });
|
|
|
|
|
|
/// start, transition, flow detection, flow setting, aborted, test, transition, end
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetNr, Config.Entities.Progress.JustStarted));
|
|
|
|
|
|
|
|
|
|
|
|
if (testMethod.DoTransitions())
|
|
|
|
|
|
{
|
|
|
|
|
|
rsltTransBefore = Transition(transitionBefore, TransitionContext.BeforeTest); /// Transition or SetRoute - start of test
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (rsltTransBefore == Event.Done)
|
|
|
|
|
|
{
|
|
|
|
|
|
e = testMethod.Execute(test, repetNr, true);
|
|
|
|
|
|
|
|
|
|
|
|
if (e.Contains(Event.MakeSecondPass) && testMethod is ITestMethodWith2ndPass)
|
|
|
|
|
|
{
|
|
|
|
|
|
ITestMethodWith2ndPass tm2 = testMethod as ITestMethodWith2ndPass;
|
|
|
|
|
|
e = tm2.Execute2ndPass(test, repetNr, tm2.IntermediateData);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-05 09:16:13 +00:00
|
|
|
|
bool testFinished = (rsltTransBefore == Event.Done && !e.Contains(Event.Error)
|
|
|
|
|
|
&& !e.Contains(Event.ConfigurationError)
|
|
|
|
|
|
&& !e.Contains(Event.OpArgumentError)
|
|
|
|
|
|
&& !e.Contains(Event.UiCmdStop));
|
2017-12-02 16:54:38 +00:00
|
|
|
|
|
2018-06-01 11:58:59 +00:00
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetNr, testFinished ? Config.Entities.Progress.Completed
|
|
|
|
|
|
: Config.Entities.Progress.Aborted));
|
|
|
|
|
|
|
2018-06-06 07:50:52 +00:00
|
|
|
|
if (testMethod.DoTransitions())
|
2017-12-02 16:54:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
TransitionContext endContext = testFinished ? TransitionContext.AfterTest : TransitionContext.Stop;
|
|
|
|
|
|
rsltTransAfter = Transition(transitionAfter, endContext); /// Transition or SetRoute - end of test
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetNr, testFinished ? Config.Entities.Progress.Completed
|
|
|
|
|
|
: Config.Entities.Progress.Aborted));
|
|
|
|
|
|
}
|
2015-01-15 02:51:33 +00:00
|
|
|
|
|
2017-12-02 16:54:38 +00:00
|
|
|
|
if (rsltTransBefore == Event.Error || e.Contains(Event.Error)) goto error;
|
|
|
|
|
|
if (e.Contains(Event.ConfigurationError)) goto config_error;
|
|
|
|
|
|
if (e.Contains(Event.OpArgumentError)) goto config_error;
|
|
|
|
|
|
if (rsltTransBefore == Event.UiCmdStop || e.Contains(Event.UiCmdStop)) goto stop_within_cycle;
|
2015-02-02 22:18:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UiBridge.Bridge.OnError(this, string.Format("{0} cannot be used", test.Method));
|
|
|
|
|
|
goto select_cycle_or_test;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-11-22 13:56:22 +00:00
|
|
|
|
///------------------------------------------------------------------------------------------------------------
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
goto select_cycle_or_test;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-11-22 13:56:22 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
save_results:
|
|
|
|
|
|
|
2015-06-25 02:45:04 +00:00
|
|
|
|
UiBridge.Bridge.OnError(this, string.Empty); /// Clear an error message (if any)
|
2017-11-07 10:05:22 +00:00
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.StopBtnEn); /// Hide most of buttons
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2015-03-08 14:13:50 +00:00
|
|
|
|
if (State.LastEvents.Contains(Event.ModelessFormIsOpen))
|
2015-02-21 19:00:35 +00:00
|
|
|
|
{
|
2015-06-25 02:45:04 +00:00
|
|
|
|
if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stop;
|
2015-02-21 19:00:35 +00:00
|
|
|
|
}
|
2015-03-08 14:13:50 +00:00
|
|
|
|
else if (State.LastEvents.Contains(Event.ModelessFormClosed))
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseBeginForm();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-28 11:40:58 +00:00
|
|
|
|
Bridge.OnActivity(this, Strings.Enter_protocol_data);
|
2015-02-21 19:00:35 +00:00
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
2015-01-15 02:51:33 +00:00
|
|
|
|
GenericDevices.IDataEntry dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry;
|
2014-07-28 21:12:43 +00:00
|
|
|
|
if (dataEntryCmpnt != null)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2014-09-23 11:16:59 +00:00
|
|
|
|
if (dataEntryCmpnt is IHasCycleEndForm)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Open the modeless form for the end of the cycle
|
|
|
|
|
|
State.Create("MainSeq : Enter end data")
|
2016-01-06 21:37:19 +00:00
|
|
|
|
.AddOperation((dataEntryCmpnt as GenericDevices.IHasCycleEndForm).ShowCycleEndFormOp())
|
2014-09-23 11:16:59 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.ModelessFormClosed));
|
|
|
|
|
|
}
|
2016-01-08 09:23:36 +00:00
|
|
|
|
|
2016-01-04 16:55:39 +00:00
|
|
|
|
dataEntryCmpnt.UpdateTestResults(BatchRslts);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2016-01-06 20:39:52 +00:00
|
|
|
|
|
2016-01-06 21:37:19 +00:00
|
|
|
|
ProcessData.BatchRslts.Batch.EndTime = DateTime.Now;
|
2016-01-06 20:39:52 +00:00
|
|
|
|
ProcessData.BatchRslts.AddWaterMetersToBatch();
|
|
|
|
|
|
|
2015-01-25 07:11:40 +00:00
|
|
|
|
//------------------------------------------------------
|
2016-05-28 11:40:58 +00:00
|
|
|
|
Bridge.OnActivity(this, Strings.Saving_and_printing_results);
|
2015-01-25 07:11:40 +00:00
|
|
|
|
State savingAndPrintingRslts = State.Create("MainSeq : Saving and printing results");
|
2016-01-08 18:18:45 +00:00
|
|
|
|
|
2016-04-29 14:58:23 +00:00
|
|
|
|
string[] writers = StateMachine.Procedure.ResultsWriter.Split(new char[] { '~' });
|
|
|
|
|
|
foreach (var writerName in writers)
|
|
|
|
|
|
{
|
|
|
|
|
|
IResultsWriter writer = TbfComponents.FindComponent(writerName) as IResultsWriter;
|
|
|
|
|
|
if (writer != null)
|
|
|
|
|
|
{
|
2016-08-24 13:42:24 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
savingAndPrintingRslts.AddOperation(writer.WriteResultsOp(ProcessData.BatchRslts.Batch));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exc)
|
|
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnError(this, string.Format(Strings.Component_0_crashed_Results_not_saved, writerName));
|
|
|
|
|
|
log.FatalFormat("FileWriter {0} crashed: {1}", writerName, exc.Message);
|
|
|
|
|
|
}
|
2016-04-29 14:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-01-08 18:18:45 +00:00
|
|
|
|
|
2016-04-29 14:58:23 +00:00
|
|
|
|
string[] printers = StateMachine.Procedure.ResultsPrinter.Split(new char[] { '~' });
|
|
|
|
|
|
foreach (var printerName in printers)
|
|
|
|
|
|
{
|
|
|
|
|
|
IResultsPrinter printer = TbfComponents.FindComponent(printerName) as IResultsPrinter;
|
|
|
|
|
|
if (printer != null && !printer.SupressPrinting)
|
|
|
|
|
|
{
|
2016-08-24 13:42:24 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
savingAndPrintingRslts.AddOperation(printer.PrintResultsOp(ProcessData.BatchRslts.Batch));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exc)
|
|
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnError(this, string.Format(Strings.Component_0_crashed_Results_not_printed, printerName));
|
|
|
|
|
|
log.FatalFormat("Printer {0} crashed: {1}", printerName, exc.Message);
|
|
|
|
|
|
}
|
2016-04-29 14:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-01-08 18:18:45 +00:00
|
|
|
|
|
2015-01-25 07:11:40 +00:00
|
|
|
|
savingAndPrintingRslts.AddOperation(checkUiOp).EnterState();
|
|
|
|
|
|
do
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2015-01-25 07:11:40 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.Error)) goto error;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop)) goto stop;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2015-01-25 07:11:40 +00:00
|
|
|
|
while (e.Contains(Event.Busy));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2016-01-08 18:18:45 +00:00
|
|
|
|
bool resultsSent = !e.Contains(Event.ResultsNotWritten);
|
2016-01-08 12:51:54 +00:00
|
|
|
|
ProcessData.BatchRslts.Batch.RsltsSent = resultsSent;
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Save results to the built in 'Results' database
|
|
|
|
|
|
///
|
|
|
|
|
|
Results.DB.SaveNewBatch(ProcessData.BatchRslts.Batch);
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Save results to 'summary results' logger
|
|
|
|
|
|
///
|
|
|
|
|
|
foreach (var tr in ProcessData.BatchRslts.Batch.TestRslts)
|
|
|
|
|
|
{
|
|
|
|
|
|
summaryResults.Info(TestResult2CsvLine(tr));
|
|
|
|
|
|
}
|
2015-02-01 23:07:39 +00:00
|
|
|
|
|
2015-02-02 17:09:05 +00:00
|
|
|
|
Program.LocalSettings.BatchNr++;
|
2015-01-25 07:11:40 +00:00
|
|
|
|
Program.LocalSettings.Save();
|
|
|
|
|
|
|
2017-04-20 09:00:41 +00:00
|
|
|
|
log.FatalFormat("Measurement session saved: batch = {0}, procedure = {1}, next batch nr. = {2}",
|
|
|
|
|
|
ProcessData.BatchRslts.Batch.BatchNr,
|
|
|
|
|
|
ProcessData.BatchRslts.Batch.ProcedureName,
|
|
|
|
|
|
Program.LocalSettings.BatchNr);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-05-03 20:19:26 +00:00
|
|
|
|
evacuation:
|
|
|
|
|
|
|
|
|
|
|
|
/// Evacuation is similar to 'Abort session' (no results are saved), but the evacuation is done as well.
|
2017-05-03 20:17:20 +00:00
|
|
|
|
|
2017-05-03 20:19:26 +00:00
|
|
|
|
StateMachine.ControlBoard.ManualUIAllowed = true;
|
2017-05-03 20:17:20 +00:00
|
|
|
|
|
2017-06-30 10:04:55 +00:00
|
|
|
|
switch (DoEvacuation(purgeEnd))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-06-30 10:04:55 +00:00
|
|
|
|
case Event.Error: goto error;
|
|
|
|
|
|
case Event.UiCmdStop: goto stop;
|
|
|
|
|
|
default: break;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2017-06-30 10:04:55 +00:00
|
|
|
|
|
|
|
|
|
|
Bridge.OnProcedureCompleted(this, new ProcedureCompletedEventArgs(StateMachine.Procedure));
|
2015-09-10 18:07:06 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
goto select_procedure;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-06-30 10:04:55 +00:00
|
|
|
|
|
2015-04-29 11:51:24 +00:00
|
|
|
|
stop_within_cycle:
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
State.Create("MainSeq : Turning IDLE -> Closing the valves")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen,
|
|
|
|
|
|
StateMachine.DefaultValvesClose))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.Error)) goto error;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
|
|
|
|
|
|
goto select_cycle_or_test;
|
|
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
stop:
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
State.Create("MainSeq : Turning IDLE -> Closing the valves")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen,
|
|
|
|
|
|
StateMachine.DefaultValvesClose))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.Error)) goto error;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet));
|
|
|
|
|
|
|
|
|
|
|
|
goto select_procedure;
|
|
|
|
|
|
|
|
|
|
|
|
config_error:
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
State.Create("MainSeq : Procedure configuration error")
|
2014-08-12 20:21:26 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
2019-02-12 08:00:02 +00:00
|
|
|
|
.AddOperation(StateMachine.BenchErrorOp)
|
2014-08-12 20:21:26 +00:00
|
|
|
|
.AddOperation(new Operations.MessageBoxOp("Test configration error"))
|
2014-08-12 16:22:32 +00:00
|
|
|
|
.EnterState();
|
2014-08-12 20:21:26 +00:00
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.OK));
|
|
|
|
|
|
|
|
|
|
|
|
goto select_cycle_or_test;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
error:
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
State.Create("MainSeq : ERROR -> Closing the valves")
|
2014-07-28 07:54:35 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
2019-02-12 08:00:02 +00:00
|
|
|
|
.AddOperation(StateMachine.BenchErrorOp)
|
2014-08-12 16:22:32 +00:00
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen,
|
|
|
|
|
|
StateMachine.DefaultValvesClose))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2014-08-12 16:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.ValvesSet) && !e.Contains(Event.Error));
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
State.Create("MainSeq : ERROR state")
|
2019-03-04 12:14:13 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
2019-02-12 08:00:02 +00:00
|
|
|
|
.AddOperation(StateMachine.BenchErrorOp)
|
2014-08-12 16:22:32 +00:00
|
|
|
|
.EnterState();
|
2019-03-04 12:14:13 +00:00
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.UiCmdShutdown));
|
|
|
|
|
|
|
|
|
|
|
|
Shutdown(true);
|
|
|
|
|
|
return;
|
2014-08-12 16:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// MakeSelection() call context
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
enum MKSelContext
|
|
|
|
|
|
{
|
|
|
|
|
|
ProcedureNotSelected,
|
|
|
|
|
|
InsideProcedure,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-04-10 13:23:37 +00:00
|
|
|
|
/// Return values of MakeSelection()
|
2014-08-12 16:22:32 +00:00
|
|
|
|
/// </summary>
|
2017-04-10 13:23:37 +00:00
|
|
|
|
public enum Selection
|
|
|
|
|
|
{
|
|
|
|
|
|
PurgeBegin,
|
|
|
|
|
|
PurgeEnd,
|
2015-05-22 14:43:17 +00:00
|
|
|
|
Break,
|
2017-04-10 13:23:37 +00:00
|
|
|
|
Cycle,
|
|
|
|
|
|
RestOfCycle,
|
|
|
|
|
|
Test,
|
|
|
|
|
|
Q1,
|
|
|
|
|
|
Q2,
|
|
|
|
|
|
Q3,
|
|
|
|
|
|
SaveResults,
|
|
|
|
|
|
RestoreBatch,
|
2018-02-06 14:26:50 +00:00
|
|
|
|
Shutdown,
|
2017-04-10 13:23:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Idle loop to make a procedure or test selection.
|
|
|
|
|
|
/// Handles tank emptying, camera test.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context">Context where MakeSelection() is called</param>
|
|
|
|
|
|
/// <returns>
|
2017-07-19 06:02:45 +00:00
|
|
|
|
/// Selection.PurgeBegin, PurgeEnd, Break, Cycle, Test, Q1, Q2, Q3 or SaveResults
|
2014-08-12 16:22:32 +00:00
|
|
|
|
/// </returns>
|
2019-03-04 12:14:13 +00:00
|
|
|
|
Selection MakeSelection(MKSelContext context)
|
2014-08-12 16:22:32 +00:00
|
|
|
|
{
|
2018-02-06 14:26:50 +00:00
|
|
|
|
log.WarnFormat("MakeSelection({0})", context);
|
2018-02-16 05:54:14 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
/// Tank emptying valves states
|
2017-03-28 21:47:32 +00:00
|
|
|
|
bool draining1 = false;
|
|
|
|
|
|
bool draining2 = false;
|
|
|
|
|
|
bool draining3 = false;
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
|
|
|
|
|
/// Measured masses to control emptying
|
2016-10-07 12:06:54 +00:00
|
|
|
|
DoubleBox mass1 = new DoubleBox();
|
|
|
|
|
|
DoubleBox mass2 = new DoubleBox();
|
|
|
|
|
|
DoubleBox mass3 = new DoubleBox();
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
|
|
|
|
|
IList<Event> e;
|
|
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
2017-07-19 06:02:45 +00:00
|
|
|
|
bool draining = draining1 || draining2 || draining3;
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Activity message
|
|
|
|
|
|
///
|
|
|
|
|
|
Bridge.OnActivity(this, draining ? Strings.Emptying_tank
|
|
|
|
|
|
: ((context == MKSelContext.ProcedureNotSelected) ? Strings.Please_select_a_procedure
|
|
|
|
|
|
: Strings.Please_select_a_cycle_a_test_or_empty));
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-05-04 20:11:18 +00:00
|
|
|
|
bool saveResultsActive = (context == MKSelContext.InsideProcedure)
|
|
|
|
|
|
&& (StateMachine.Procedure != null)
|
2017-07-19 06:02:45 +00:00
|
|
|
|
&& (!StateMachine.Procedure.MustBeComplete || BatchRslts.AllTestsDone());
|
2017-05-04 20:11:18 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
/// Enable appropriate UI controls and buttons
|
|
|
|
|
|
Bridge.Bench2UI(((context == MKSelContext.ProcedureNotSelected) ? ButtonsEtc.ProcedureCmbBoxEn : 0) |
|
|
|
|
|
|
ButtonsEtc.TestCmbBoxEn |
|
2017-05-03 20:17:20 +00:00
|
|
|
|
((context == MKSelContext.InsideProcedure) ? ButtonsEtc.Break : 0) |
|
2017-05-04 20:11:18 +00:00
|
|
|
|
(saveResultsActive ? ButtonsEtc.AcceptResultsBtnEn : 0) |
|
2017-07-19 06:02:45 +00:00
|
|
|
|
(draining ? 0 : ButtonsEtc.StartCycleBtnEn) |
|
|
|
|
|
|
(draining ? 0 : ButtonsEtc.StartTestBtnsEn) |
|
|
|
|
|
|
(draining ? 0 : ButtonsEtc.PurgeBeginBtnEn) |
|
|
|
|
|
|
(draining ? 0 : ((context == MKSelContext.InsideProcedure) ? ButtonsEtc.PurgeEndBtnEn : 0)) |
|
|
|
|
|
|
((StateMachine.DrainValve1 == null) ? 0 : (draining1 ? ButtonsEtc.DrainTankBtn1Hi : ButtonsEtc.DrainTankBtn1En)) |
|
|
|
|
|
|
((StateMachine.DrainValve2 == null) ? 0 : (draining2 ? ButtonsEtc.DrainTankBtn2Hi : ButtonsEtc.DrainTankBtn2En)) |
|
|
|
|
|
|
((StateMachine.DrainValve3 == null) ? 0 : (draining3 ? ButtonsEtc.DrainTankBtn3Hi : ButtonsEtc.DrainTankBtn3En)));
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
2017-04-10 13:23:37 +00:00
|
|
|
|
|
2014-08-12 16:22:32 +00:00
|
|
|
|
State.Create("MainSeq : Select an activity")
|
2018-02-16 05:54:14 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
2019-02-12 08:00:02 +00:00
|
|
|
|
.AddOperation(StateMachine.BenchWaitingOp)
|
2018-10-22 16:14:47 +00:00
|
|
|
|
.AddOperation((StateMachine.Tank1 is IScale) ? (StateMachine.Tank1 as IScale).ReadMassOp(ref mass1) : null)
|
|
|
|
|
|
.AddOperation((StateMachine.Tank2 is IScale) ? (StateMachine.Tank2 as IScale).ReadMassOp(ref mass2) : null)
|
|
|
|
|
|
.AddOperation((StateMachine.Tank3 is IScale) ? (StateMachine.Tank3 as IScale).ReadMassOp(ref mass3) : null)
|
2014-08-12 16:22:32 +00:00
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2017-04-10 13:23:37 +00:00
|
|
|
|
|
|
|
|
|
|
/// Handled inside MakeSelection() inside the selection loop
|
2018-02-16 05:54:14 +00:00
|
|
|
|
if (e.Contains(Event.Error)) break;
|
|
|
|
|
|
if (!draining1 && e.Contains(Event.UiCmdDrainTank1)) break;
|
2017-07-19 06:02:45 +00:00
|
|
|
|
if (!draining2 && e.Contains(Event.UiCmdDrainTank2)) break;
|
|
|
|
|
|
if (!draining3 && e.Contains(Event.UiCmdDrainTank3)) break;
|
|
|
|
|
|
if (draining1 && e.Contains(Event.UiCmdStopDrainingTank1)) break;
|
|
|
|
|
|
if (draining2 && e.Contains(Event.UiCmdStopDrainingTank2)) break;
|
|
|
|
|
|
if (draining3 && e.Contains(Event.UiCmdStopDrainingTank3)) break;
|
2018-10-22 16:14:47 +00:00
|
|
|
|
if (draining1 && StateMachine.Tank1.IsEmpty()) break;
|
|
|
|
|
|
if (draining2 && StateMachine.Tank2.IsEmpty()) break;
|
|
|
|
|
|
if (draining3 && StateMachine.Tank3.IsEmpty()) break;
|
2017-04-10 13:23:37 +00:00
|
|
|
|
|
|
|
|
|
|
/// Quit the selection loop and leave MakeSelection()
|
2019-03-04 12:14:13 +00:00
|
|
|
|
if (e.Contains(Event.UiCmdShutdown) && (context == MKSelContext.ProcedureNotSelected)) return Selection.Shutdown;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdBreak) && (context == MKSelContext.InsideProcedure)) return Selection.Break;
|
2017-04-10 13:23:37 +00:00
|
|
|
|
if (e.Contains(Event.UiCmdPurgeBegin)) return Selection.PurgeBegin;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdPurgeEnd)) return Selection.PurgeEnd;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStartCycle)) return Selection.Cycle;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStartTest)) return Selection.Test;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStartQ1)) return Selection.Q1;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStartQ2)) return Selection.Q2;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStartQ3)) return Selection.Q3;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdAcceptResults)) return Selection.SaveResults;
|
|
|
|
|
|
if (e.Contains(Event.UiCmdReloadBatch)) return Selection.RestoreBatch;
|
2017-04-12 15:33:47 +00:00
|
|
|
|
}
|
2017-04-10 13:23:37 +00:00
|
|
|
|
while (true);
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
2017-04-10 13:23:37 +00:00
|
|
|
|
|
|
|
|
|
|
if (e.Contains(Event.Error))
|
|
|
|
|
|
{
|
|
|
|
|
|
///------------------------------------
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Error);
|
|
|
|
|
|
///------------------------------------
|
|
|
|
|
|
State.Create("MainSeq : ERROR state")
|
2019-03-04 12:14:13 +00:00
|
|
|
|
.AddOperation(checkUiOp)
|
2019-02-12 08:00:02 +00:00
|
|
|
|
.AddOperation(StateMachine.BenchErrorOp)
|
2017-04-10 13:23:37 +00:00
|
|
|
|
.EnterState();
|
2019-03-04 12:14:13 +00:00
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!e.Contains(Event.UiCmdShutdown));
|
|
|
|
|
|
|
|
|
|
|
|
return Selection.Shutdown;
|
2017-04-10 13:23:37 +00:00
|
|
|
|
}
|
2018-02-16 05:54:14 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
string stateText = "MainSeq : ";
|
|
|
|
|
|
IList<IValve> openValves = new List<IValve>();
|
|
|
|
|
|
IList<IValve> closeValves = new List<IValve>();
|
2017-07-19 06:02:45 +00:00
|
|
|
|
|
2018-10-22 16:14:47 +00:00
|
|
|
|
if (draining1 && (StateMachine.Tank1.IsEmpty() || e.Contains(Event.UiCmdStopDrainingTank1)))
|
2018-02-16 05:54:14 +00:00
|
|
|
|
{
|
|
|
|
|
|
draining1 = false;
|
|
|
|
|
|
closeValves.Add(StateMachine.DrainValve1);
|
|
|
|
|
|
stateText = stateText + "close tank 1, ";
|
|
|
|
|
|
}
|
2018-10-22 16:14:47 +00:00
|
|
|
|
else if (draining2 && (StateMachine.Tank2.IsEmpty() || e.Contains(Event.UiCmdStopDrainingTank2)))
|
2018-02-16 05:54:14 +00:00
|
|
|
|
{
|
|
|
|
|
|
draining2 = false;
|
|
|
|
|
|
closeValves.Add(StateMachine.DrainValve2);
|
|
|
|
|
|
stateText = stateText + "close tank 2, ";
|
|
|
|
|
|
}
|
2018-10-22 16:14:47 +00:00
|
|
|
|
else if (draining3 && (StateMachine.Tank3.IsEmpty() || e.Contains(Event.UiCmdStopDrainingTank3)))
|
2018-02-16 05:54:14 +00:00
|
|
|
|
{
|
|
|
|
|
|
draining3 = false;
|
|
|
|
|
|
closeValves.Add(StateMachine.DrainValve3);
|
|
|
|
|
|
stateText = stateText + "close tank 3, ";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!draining1 && e.Contains(Event.UiCmdDrainTank1))
|
|
|
|
|
|
{
|
|
|
|
|
|
draining1 = true;
|
|
|
|
|
|
openValves.Add(StateMachine.DrainValve1);
|
|
|
|
|
|
stateText = stateText + "open tank 1, ";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!draining2 && e.Contains(Event.UiCmdDrainTank2))
|
|
|
|
|
|
{
|
|
|
|
|
|
draining2 = true;
|
|
|
|
|
|
openValves.Add(StateMachine.DrainValve2);
|
|
|
|
|
|
stateText = stateText + "open tank 2, ";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!draining3 && e.Contains(Event.UiCmdDrainTank3))
|
|
|
|
|
|
{
|
|
|
|
|
|
draining3 = true;
|
|
|
|
|
|
openValves.Add(StateMachine.DrainValve3);
|
|
|
|
|
|
stateText = stateText + "open tank 3, ";
|
|
|
|
|
|
}
|
2017-07-19 06:02:45 +00:00
|
|
|
|
|
2018-02-16 05:54:14 +00:00
|
|
|
|
draining = draining1 || draining2 || draining3;
|
|
|
|
|
|
if (draining) Bridge.OnActivity(this, Strings.Emptying_tank);
|
2017-07-19 06:02:45 +00:00
|
|
|
|
|
2018-02-16 05:54:14 +00:00
|
|
|
|
Bridge.Bench2UI(((context == MKSelContext.ProcedureNotSelected) ? ButtonsEtc.ProcedureCmbBoxEn : 0) |
|
|
|
|
|
|
((StateMachine.DrainValve1 == null) ? 0 : (draining1 ? ButtonsEtc.DrainTankBtn1Hi : ButtonsEtc.DrainTankBtn1En)) |
|
|
|
|
|
|
((StateMachine.DrainValve2 == null) ? 0 : (draining2 ? ButtonsEtc.DrainTankBtn2Hi : ButtonsEtc.DrainTankBtn2En)) |
|
|
|
|
|
|
((StateMachine.DrainValve3 == null) ? 0 : (draining3 ? ButtonsEtc.DrainTankBtn3Hi : ButtonsEtc.DrainTankBtn3En)));
|
2017-07-19 06:02:45 +00:00
|
|
|
|
|
2018-02-16 05:54:14 +00:00
|
|
|
|
State.Create(stateText)
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(openValves, closeValves))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
2018-02-06 14:26:50 +00:00
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
2018-02-16 05:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
while (e.Contains(Event.ValvesBusy));
|
|
|
|
|
|
}
|
2014-08-12 16:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-04 12:14:13 +00:00
|
|
|
|
void Shutdown(bool skipTankDraining = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
log.WarnFormat(string.Format("Shutdown(skipTankDraining={0})", skipTankDraining));
|
|
|
|
|
|
|
|
|
|
|
|
StateMachine.MachineState = MachineState.ShuttingDown; /// TBF shut down cannot be aborted from now on
|
|
|
|
|
|
Bridge.Bench2UI(0); /// All buttons off
|
|
|
|
|
|
|
|
|
|
|
|
if (!skipTankDraining)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Drain time
|
|
|
|
|
|
int maxDrainTime = 0;
|
|
|
|
|
|
if ((StateMachine.Tank1 != null) && (StateMachine.Tank1.EmptyTimeSec > maxDrainTime)) maxDrainTime = StateMachine.Tank1.EmptyTimeSec;
|
|
|
|
|
|
if ((StateMachine.Tank2 != null) && (StateMachine.Tank2.EmptyTimeSec > maxDrainTime)) maxDrainTime = StateMachine.Tank2.EmptyTimeSec;
|
|
|
|
|
|
if ((StateMachine.Tank3 != null) && (StateMachine.Tank3.EmptyTimeSec > maxDrainTime)) maxDrainTime = StateMachine.Tank3.EmptyTimeSec;
|
|
|
|
|
|
|
|
|
|
|
|
/// Drain valves
|
|
|
|
|
|
IList<IValve> drainValves = new List<IValve>();
|
|
|
|
|
|
if (StateMachine.DrainValve1 != null) drainValves.Add(StateMachine.DrainValve1);
|
|
|
|
|
|
if (StateMachine.DrainValve2 != null) drainValves.Add(StateMachine.DrainValve2);
|
|
|
|
|
|
if (StateMachine.DrainValve3 != null) drainValves.Add(StateMachine.DrainValve3);
|
|
|
|
|
|
|
|
|
|
|
|
/// Open all drain valves
|
|
|
|
|
|
if (drainValves.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Emptying_tank); /// Activity message
|
|
|
|
|
|
|
|
|
|
|
|
State.Create("Open all drain valves")
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(drainValves, null))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
while (StateMachine.WaitRunDevsRunOps().Contains(Event.ValvesBusy)) { }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Tank emptying valves states
|
|
|
|
|
|
bool draining1 = (StateMachine.DrainValve1 != null);
|
|
|
|
|
|
bool draining2 = (StateMachine.DrainValve2 != null);
|
|
|
|
|
|
bool draining3 = (StateMachine.DrainValve3 != null);
|
|
|
|
|
|
|
|
|
|
|
|
int drainingStartTime = StateMachine.Time;
|
|
|
|
|
|
|
|
|
|
|
|
/// Quit the following loop when time expires or all tanks are empty
|
|
|
|
|
|
while ((StateMachine.Time < drainingStartTime + maxDrainTime) && (draining1 || draining2 || draining3))
|
|
|
|
|
|
{
|
|
|
|
|
|
int remTime = drainingStartTime + maxDrainTime - StateMachine.Time;
|
|
|
|
|
|
Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remTime / 60, "min", remTime % 60, Strings.sec));
|
|
|
|
|
|
|
|
|
|
|
|
DoubleBox mass1 = new DoubleBox();
|
|
|
|
|
|
DoubleBox mass2 = new DoubleBox();
|
|
|
|
|
|
DoubleBox mass3 = new DoubleBox();
|
|
|
|
|
|
///
|
|
|
|
|
|
State.Create("MainSeq : Reading mass")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.AddOperation((StateMachine.Tank1 is IScale) ? (StateMachine.Tank1 as IScale).ReadMassOp(ref mass1) : null)
|
|
|
|
|
|
.AddOperation((StateMachine.Tank2 is IScale) ? (StateMachine.Tank2 as IScale).ReadMassOp(ref mass2) : null)
|
|
|
|
|
|
.AddOperation((StateMachine.Tank3 is IScale) ? (StateMachine.Tank3 as IScale).ReadMassOp(ref mass3) : null)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
while (StateMachine.WaitRunDevsRunOps().Contains(Event.Busy)) { }
|
|
|
|
|
|
|
|
|
|
|
|
if (draining1 && StateMachine.Tank1.IsEmpty()) draining1 = false;
|
|
|
|
|
|
if (draining2 && StateMachine.Tank2.IsEmpty()) draining2 = false;
|
|
|
|
|
|
if (draining3 && StateMachine.Tank3.IsEmpty()) draining3 = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Close all drain valves
|
|
|
|
|
|
if (drainValves.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
State.Create("Close all drain valves")
|
|
|
|
|
|
.AddOperation(StateMachine.ControlBoard.SetValvesOp(null, drainValves))
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
while (StateMachine.WaitRunDevsRunOps().Contains(Event.ValvesBusy)) { }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Shut down the state machine
|
|
|
|
|
|
///
|
|
|
|
|
|
Bridge.OnActivity(this, Strings.Shutting_down_devices); /// Activity message
|
|
|
|
|
|
|
|
|
|
|
|
State.Create("No operations").EnterState(); /// Stop all operations
|
|
|
|
|
|
StateMachine.WaitRunDevsRunOps(true);
|
|
|
|
|
|
|
|
|
|
|
|
BenchControl.StateMachine.StopDevices(); /// Stop all devices - phase 1
|
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
|
BenchControl.StateMachine.StopDevices2(); /// Stop all devices - phase 2
|
|
|
|
|
|
}
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
2017-04-10 13:23:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a new empty batch results from the procedure
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="newBatchNr">New batch number</param>
|
|
|
|
|
|
/// <param name="procedure">Selected procedure</param>
|
|
|
|
|
|
/// <returns>Created BatchResults</returns>
|
|
|
|
|
|
Results.BatchResults CreateNewBatchResults(int newBatchNr, Procedure procedure)
|
|
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Prepare new water meters
|
|
|
|
|
|
///
|
|
|
|
|
|
foreach (var wm in WaterMeters) wm.ClearData(); /// Clean water meter data
|
2014-08-12 16:22:32 +00:00
|
|
|
|
|
2017-04-10 13:23:37 +00:00
|
|
|
|
bool compound = (StateMachine.Procedure.MetersKind == MetersKind.Combined);
|
|
|
|
|
|
bool heatMeters = (StateMachine.Procedure.MetersKind == MetersKind.HeatMeter);
|
|
|
|
|
|
int waterMetersCount = Math.Min(WaterMeters.Count, heatMeters ? Config.Data.HeatMetersCount : (compound ? Config.Data.CompoundWMsCount : Config.Data.WMsCount));
|
|
|
|
|
|
///
|
|
|
|
|
|
Results.Entities.WaterMeterData[] waterMeterData = new Results.Entities.WaterMeterData[waterMetersCount];
|
|
|
|
|
|
///
|
|
|
|
|
|
int[] waterMeterParts = new int[waterMetersCount];
|
|
|
|
|
|
for (int wmNr = 0; wmNr < waterMetersCount; wmNr++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int ix = compound ? (2 * wmNr) : wmNr;
|
2017-06-29 07:20:43 +00:00
|
|
|
|
if (WaterMeters.Count > ix)
|
2017-04-10 13:23:37 +00:00
|
|
|
|
{
|
2017-06-29 07:20:43 +00:00
|
|
|
|
waterMeterParts[wmNr] = Utils.PartNr(wmNr + 1, compound);
|
|
|
|
|
|
waterMeterData[wmNr] = new Results.Entities.WaterMeterData()
|
|
|
|
|
|
{
|
|
|
|
|
|
ProductName = WaterMeters[ix].ProductName,
|
|
|
|
|
|
Producer = WaterMeters[ix].Producer,
|
|
|
|
|
|
|
|
|
|
|
|
L = WaterMeters[ix].L,
|
|
|
|
|
|
DN = WaterMeters[ix].DN,
|
|
|
|
|
|
Mounting = WaterMeters[ix].Mounting,
|
|
|
|
|
|
|
2017-11-21 08:31:24 +00:00
|
|
|
|
NewQnames = WaterMeters[ix].NewQnames,
|
2017-06-29 07:20:43 +00:00
|
|
|
|
Q4_Qmax = WaterMeters[ix].Q4_Qmax,
|
|
|
|
|
|
Q3_Qn = WaterMeters[ix].Q3_Qn,
|
|
|
|
|
|
Q2_Qt = WaterMeters[ix].Q2_Qt,
|
|
|
|
|
|
Q1_Qmin = WaterMeters[ix].Q1_Qmin,
|
|
|
|
|
|
|
|
|
|
|
|
MetrologicalClass = WaterMeters[ix].MetrologicalClass,
|
|
|
|
|
|
TemperatureClass = WaterMeters[ix].TemperatureClass,
|
|
|
|
|
|
PressureLossClass = WaterMeters[ix].PressureLossClass,
|
|
|
|
|
|
MaxAdmissiblePressure = WaterMeters[ix].MaxAdmissiblePressure,
|
|
|
|
|
|
FlowProfileSensitivityClass = WaterMeters[ix].FlowProfileSensitivityClass,
|
|
|
|
|
|
|
|
|
|
|
|
ApprovalInfo = WaterMeters[ix].ApprovalInfo,
|
|
|
|
|
|
Certificate = WaterMeters[ix].Certificate,
|
|
|
|
|
|
|
|
|
|
|
|
PulsesPerLtr = WaterMeters[ix].PulsesPerLtr,
|
2018-04-13 09:40:51 +00:00
|
|
|
|
Medium = WaterMeters[ix].Medium,
|
2017-06-29 07:20:43 +00:00
|
|
|
|
Text1 = WaterMeters[ix].Text1,
|
|
|
|
|
|
Text2 = WaterMeters[ix].Text2,
|
|
|
|
|
|
Text3 = WaterMeters[ix].Text3,
|
|
|
|
|
|
Text4 = WaterMeters[ix].Text4,
|
|
|
|
|
|
Text5 = WaterMeters[ix].Text5,
|
|
|
|
|
|
|
|
|
|
|
|
Compound = compound,
|
|
|
|
|
|
HeatMeter = heatMeters,
|
2018-09-11 09:31:00 +00:00
|
|
|
|
#if ORACLE_DB
|
|
|
|
|
|
WMTypeId = 0, /// <--------------------------- TODO
|
|
|
|
|
|
#endif
|
2017-06-29 07:20:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2017-04-10 13:23:37 +00:00
|
|
|
|
|
2017-06-29 07:20:43 +00:00
|
|
|
|
int auxIx = 2 * wmNr + 1;
|
|
|
|
|
|
if (compound && WaterMeters.Count > auxIx)
|
2017-04-10 13:23:37 +00:00
|
|
|
|
{
|
|
|
|
|
|
waterMeterData[wmNr].ProducerAux = WaterMeters[auxIx].Producer;
|
|
|
|
|
|
waterMeterData[wmNr].Q3_Qn_Aux = WaterMeters[auxIx].Q3_Qn;
|
|
|
|
|
|
waterMeterData[wmNr].MetrologicalClassAux = WaterMeters[auxIx].MetrologicalClass;
|
|
|
|
|
|
waterMeterData[wmNr].ApprovalInfoAux = WaterMeters[auxIx].ApprovalInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Prepare empty results
|
|
|
|
|
|
return Results.BatchResults.NewFromProcedure(newBatchNr,
|
|
|
|
|
|
(BenchInfo != null) ? BenchInfo.TestBenchId : 1,
|
2018-09-13 14:33:22 +00:00
|
|
|
|
(BenchInfo != null) ? BenchInfo.TestBenchName : "testbench",
|
|
|
|
|
|
(BenchInfo != null) ? BenchInfo.Address1 : string.Empty,
|
|
|
|
|
|
(BenchInfo != null) ? BenchInfo.Address2 : string.Empty,
|
|
|
|
|
|
(BenchInfo != null) ? BenchInfo.Address3 : string.Empty,
|
|
|
|
|
|
(BenchInfo != null) ? BenchInfo.Address4 : string.Empty,
|
|
|
|
|
|
(BenchInfo != null) ? BenchInfo.Address5 : string.Empty,
|
|
|
|
|
|
Users.GlobalData.CurrentUser.ToEncodedStr(),
|
2017-04-10 13:23:37 +00:00
|
|
|
|
Users.GlobalData.CurrentUser.Number,
|
|
|
|
|
|
Program.Version,
|
|
|
|
|
|
StateMachine.Procedure,
|
|
|
|
|
|
waterMeterData,
|
2017-06-29 10:48:14 +00:00
|
|
|
|
waterMeterParts,
|
2018-04-10 14:10:44 +00:00
|
|
|
|
Formulas.DensityCorrection(Program.LocalSettings.RealDensity,
|
|
|
|
|
|
Program.LocalSettings.AtTemperature));
|
2017-04-10 13:23:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Reload batch results from Results database given the batch number
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="oriBatchNr">Original batch number</param>
|
|
|
|
|
|
/// <param name="newBatchNr">New unique batch number</param>
|
|
|
|
|
|
/// <param name="procedure">Reloaded procedure</param>
|
|
|
|
|
|
/// <returns></returns>
|
2017-04-20 11:45:38 +00:00
|
|
|
|
void RestoreBatchResults(int oriBatchNr, ref Results.BatchResults batchResults)
|
2017-04-10 13:23:37 +00:00
|
|
|
|
{
|
2017-04-20 11:45:38 +00:00
|
|
|
|
Batch oriBatch = Results.DB.LoadBatch(oriBatchNr);
|
|
|
|
|
|
|
2018-04-12 10:42:11 +00:00
|
|
|
|
if (oriBatch == null) return;
|
|
|
|
|
|
|
2017-04-20 11:45:38 +00:00
|
|
|
|
batchResults.Batch.StartTime = oriBatch.StartTime;
|
2018-09-13 14:33:22 +00:00
|
|
|
|
batchResults.Batch.TestBenchId = (BenchInfo != null) ? BenchInfo.TestBenchId : 1;
|
|
|
|
|
|
batchResults.Batch.TestBenchName = (BenchInfo != null) ? BenchInfo.TestBenchName : "testbench";
|
2017-04-20 11:45:38 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var testRslt in batchResults.Batch.TestRslts)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var oriTstRslt in oriBatch.TestRslts)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (testRslt.Name() == oriTstRslt.Name() &&
|
|
|
|
|
|
testRslt.Part == oriTstRslt.Part &&
|
|
|
|
|
|
testRslt.RepetitionNr == oriTstRslt.RepetitionNr)
|
|
|
|
|
|
{
|
|
|
|
|
|
testRslt.CopyContentFrom(oriTstRslt);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < batchResults.WaterMeters.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
WaterMeter wm = batchResults.WaterMeters[i];
|
2017-09-28 07:39:58 +00:00
|
|
|
|
wm.Disabled = true;
|
2017-04-20 11:45:38 +00:00
|
|
|
|
foreach (var wm2 in oriBatch.WaterMeters)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wm.WMPosition == wm2.WMPosition)
|
|
|
|
|
|
{
|
|
|
|
|
|
wm.CopyContentFrom(wm2);
|
2017-09-28 07:39:58 +00:00
|
|
|
|
wm.Disabled = false;
|
2018-10-08 07:36:13 +00:00
|
|
|
|
#if ORACLE_DB
|
|
|
|
|
|
wm.WaterMeterData.WMTypeId = wm2.WaterMeterData.WMTypeId;
|
|
|
|
|
|
#endif
|
2017-04-20 11:45:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-04-10 13:23:37 +00:00
|
|
|
|
}
|
2016-04-07 11:52:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-04-20 11:45:38 +00:00
|
|
|
|
void CollectSimultSteps()
|
2016-04-07 11:52:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Collect steps (e.g. iPerl communication) to be done simultaneously with purging
|
|
|
|
|
|
///
|
|
|
|
|
|
simultWithPurgingCount = 0;
|
|
|
|
|
|
simultWithPurgingCfg = null;
|
|
|
|
|
|
simultWithPurgingTests.Clear();
|
|
|
|
|
|
simultWithPurgingParams.Clear();
|
|
|
|
|
|
///
|
|
|
|
|
|
foreach (var test in StateMachine.Tests)
|
|
|
|
|
|
{
|
|
|
|
|
|
Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method);
|
|
|
|
|
|
if (testMethodComp == null) break;
|
|
|
|
|
|
|
2018-05-10 11:25:46 +00:00
|
|
|
|
testMethodComp.Cfg.LoadTestParamsFromDB(test);
|
2016-04-07 11:52:57 +00:00
|
|
|
|
|
|
|
|
|
|
ISimultTestMethod simultTest = testMethodComp as ISimultTestMethod;
|
|
|
|
|
|
MetersPath sensPath = StateMachine.GetMetersPath(test);
|
|
|
|
|
|
|
|
|
|
|
|
if (simultTest == null || !simultTest.SimultWithPrevious || sensPath == null) break;
|
|
|
|
|
|
|
|
|
|
|
|
if (simultWithPurgingCount == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
simultWithPurgingCfg = simultTest.Cfg;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (simultTest.Cfg != simultWithPurgingCfg)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
simultWithPurgingTests.Add(test);
|
2018-05-10 11:25:46 +00:00
|
|
|
|
simultWithPurgingParams.Add(testMethodComp.Cfg.GetRuntimeTestParamsProvider().Clone() as Generic.ITestParams);
|
2016-04-07 11:52:57 +00:00
|
|
|
|
simultWithPurgingCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Collect steps (e.g. iPerl communication) to be done simultaneously with evacuation
|
|
|
|
|
|
///
|
|
|
|
|
|
simultWithEvacuationCount = 0;
|
|
|
|
|
|
simultWithEvacuationCfg = null;
|
|
|
|
|
|
simultWithEvacuationTests.Clear();
|
|
|
|
|
|
simultWithEvacuationParams.Clear();
|
|
|
|
|
|
///
|
|
|
|
|
|
for (int i = StateMachine.Tests.Count - 1; i >= simultWithPurgingCount; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
var test = StateMachine.Tests[i];
|
|
|
|
|
|
|
|
|
|
|
|
Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method);
|
|
|
|
|
|
if (testMethodComp == null) break;
|
|
|
|
|
|
|
2018-05-10 11:25:46 +00:00
|
|
|
|
testMethodComp.Cfg.LoadTestParamsFromDB(test);
|
2016-04-07 11:52:57 +00:00
|
|
|
|
|
|
|
|
|
|
ISimultTestMethod simultTest = testMethodComp as ISimultTestMethod;
|
|
|
|
|
|
MetersPath sensPath = StateMachine.GetMetersPath(test);
|
|
|
|
|
|
|
|
|
|
|
|
if (simultTest == null || !simultTest.SimultWithNext || sensPath == null) break;
|
|
|
|
|
|
|
|
|
|
|
|
if (simultWithEvacuationCount == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
simultWithEvacuationCfg = simultTest.Cfg;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (simultTest.Cfg != simultWithEvacuationCfg)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
simultWithEvacuationTests.Insert(0, test);
|
2018-05-10 11:25:46 +00:00
|
|
|
|
simultWithEvacuationParams.Insert(0, testMethodComp.Cfg.GetRuntimeTestParamsProvider().Clone() as Generic.ITestParams);
|
2016-04-07 11:52:57 +00:00
|
|
|
|
simultWithEvacuationCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-30 10:04:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Executes steps of a evacuation sequence
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// Event.Done Transition sequence completed OK
|
|
|
|
|
|
/// Event.UiCmdStop Transition sequence interrupted by the STOP on-screen button
|
|
|
|
|
|
/// Event.Error Error (e.g. RegulValveTimeOut returned by Run() of SetRegulValvePositionOp)
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
Event DoEvacuation(TransitionSequence purgeEnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
IList<Event> e;
|
|
|
|
|
|
|
|
|
|
|
|
if (simultWithEvacuationCount > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Open iPerlCommunicationForm
|
|
|
|
|
|
ProcessData.RegisterReaders = StateMachine.GetMetersPath(simultWithEvacuationTests[0]).RegisterReaders;
|
|
|
|
|
|
Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithEvacuationCfg, simultWithEvacuationTests, simultWithEvacuationParams });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
|
switch (Transition(purgeEnd, TransitionContext.PurgeEnd))
|
|
|
|
|
|
{
|
|
|
|
|
|
case Event.Error:
|
|
|
|
|
|
if (simultWithEvacuationCount > 0) CloseIPerlCommForm();
|
|
|
|
|
|
return Event.Error;
|
|
|
|
|
|
case Event.UiCmdStop:
|
|
|
|
|
|
if (simultWithEvacuationCount > 0) CloseIPerlCommForm();
|
|
|
|
|
|
return Event.UiCmdStop;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (simultWithEvacuationCount > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Wait until iPerl communications are completed
|
|
|
|
|
|
///
|
|
|
|
|
|
bool completed = !(modelessDlg is GenericDevices.IHasCompleted)
|
|
|
|
|
|
|| (modelessDlg as GenericDevices.IHasCompleted).Completed;
|
|
|
|
|
|
if (!completed)
|
|
|
|
|
|
{
|
|
|
|
|
|
State.Create("MainSeq : Wait until the entry form is closed")
|
|
|
|
|
|
.AddOperation(checkUiOp)
|
|
|
|
|
|
.EnterState();
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
e = StateMachine.WaitRunDevsRunOps();
|
|
|
|
|
|
if (e.Contains(Event.UiCmdStop))
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseIPerlCommForm();
|
|
|
|
|
|
return Event.UiCmdStop;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
completed = (modelessDlg as GenericDevices.IHasCompleted).Completed;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!completed);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
modelessDlg = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
benchFilled = false;
|
|
|
|
|
|
Bridge.Bench2UI(ButtonsEtc.ShowBenchEmpty);
|
|
|
|
|
|
|
|
|
|
|
|
return Event.Done;
|
|
|
|
|
|
}
|
2016-04-07 11:52:57 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|