iPerlCommunication simultaneously with purging fixed II., Invoke( ) in MainSeq.

This commit is contained in:
Milan Hanajik
2015-09-06 00:09:52 +02:00
parent 558f000198
commit 264830a36b
2 changed files with 46 additions and 36 deletions
@@ -255,6 +255,7 @@ namespace TBF.BenchControl.Sequences
simultWithPurgingCount = 0; simultWithPurgingCount = 0;
simultWithPurgingCfg = null; simultWithPurgingCfg = null;
simultWithPurgingParams = new List<Generic.ITestParams>(); simultWithPurgingParams = new List<Generic.ITestParams>();
///
foreach (var test in StateMachine.Tests) foreach (var test in StateMachine.Tests)
{ {
Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method); Generic.IComponent testMethodComp = TbfComponents.FindComponent(test.Method);
@@ -276,19 +277,17 @@ namespace TBF.BenchControl.Sequences
break; break;
} }
Generic.ITestParams tp = testMethodComp.Cfg.GetTestParams().Clone() as Generic.ITestParams; simultWithPurgingParams.Add(testMethodComp.Cfg.GetTestParams().Clone() as Generic.ITestParams);
simultWithPurgingParams.Add(tp);
simultWithPurgingCount++; simultWithPurgingCount++;
} }
///
if (simultWithPurgingCount > 0) if (simultWithPurgingCount > 0)
{ {
/// Make sure the entry form is closed /// Make sure the entry form is closed
if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stop; if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stop;
OpenIPerlCommForm(this, simultWithPurgingCfg, simultWithPurgingParams); Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingParams });
} }
/// ///
/// Purging @ cycle start /// Purging @ cycle start
@@ -318,6 +318,8 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
} }
else DoOnAllCompleted(sender, args); else DoOnAllCompleted(sender, args);
}; };
StartForceCloseHandler();
} }
@@ -385,10 +387,6 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
iPerlCommunicationForm.multiTestParams.Add(testParams); iPerlCommunicationForm.multiTestParams.Add(testParams);
activityLabel.Text = testParams.Activity; activityLabel.Text = testParams.Activity;
/// Start worker threads
int wtId = 0;
foreach (var wt in workerThreads) wt.Start(new Boxes.IntBox(wtId++));
} }
@@ -404,10 +402,6 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
iPerlCommunicationForm.multiTestParams = multiTestParams; iPerlCommunicationForm.multiTestParams = multiTestParams;
if (multiTestParams.Count > 0) activityLabel.Text = multiTestParams[0].Activity; if (multiTestParams.Count > 0) activityLabel.Text = multiTestParams[0].Activity;
/// Start worker threads
int wtId = 0;
foreach (var wt in workerThreads) wt.Start(new Boxes.IntBox(wtId++));
} }
@@ -468,20 +462,29 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
} }
} }
/// TBF.LocalSettings ls = Program.LocalSettings;
/// Set QuidoRS outputs and start the whole communication process Left = (ls.iPerlCommunicationsFormLeft != 0) ? ls.iPerlCommunicationsFormLeft : 150;
/// by incrementing 'currentGroup'. Top = (ls.iPerlCommunicationsFormTop != 0) ? ls.iPerlCommunicationsFormTop : 150;
///
if (quido != null)
{
quido.SetOutputs((ushort)(16 - currentGroup - 1));
Thread.Sleep(200);
}
currentGroup++;
TBF.LocalSettings ls = Program.LocalSettings; ///
Left = (ls.iPerlCommunicationsFormLeft != 0) ? ls.iPerlCommunicationsFormLeft : 150; /// Start worker threads, etc.
Top = (ls.iPerlCommunicationsFormTop != 0) ? ls.iPerlCommunicationsFormTop : 150; ///
if (workerThreads != null)
{
int wtId = 0;
foreach (var wt in workerThreads) wt.Start(new Boxes.IntBox(wtId++));
///
/// Set QuidoRS outputs and start the whole communication process
/// by incrementing 'currentGroup'.
///
if (quido != null)
{
quido.SetOutputs((ushort)(16 - currentGroup - 1));
Thread.Sleep(200);
}
currentGroup++;
}
} }
@@ -550,7 +553,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
for (int group = 1; group <= lastGroup; group++) for (int group = 1; group <= lastGroup; group++)
{ {
/// Synchronize with QuidoRS and other threads /// Synchronize with QuidoRS and other threads
while (((currentGroup != group) || (activityStep != currentActivityStep)) && !stopWorkerThreads) while (((group != currentGroup) || (activityStep != currentActivityStep)) && !stopWorkerThreads)
{ {
Thread.Sleep(50); Thread.Sleep(50);
} }
@@ -585,8 +588,15 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
resultStr = "Invalid activity"; resultStr = "Invalid activity";
} }
if (error == CommErr.None) OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, resultStr));
else if (wm.Disabled || error == CommErr.Disabled) OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Watermeter is disabled")); if (error == CommErr.None)
{
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, resultStr));
}
else if (wm.Disabled || error == CommErr.Disabled)
{
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Watermeter is disabled"));
}
else else
{ {
OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, string.Format("{0} failed ({1}) !!!", activity, error))); OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, string.Format("{0} failed ({1}) !!!", activity, error)));
@@ -1023,7 +1033,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
void DoOnCommCompleted(object sender, CommCompletedEventArgs data) void DoOnCommCompleted(object sender, CommCompletedEventArgs data)
{ {
if (data.WMNr >= 0) messages[data.WMNr].Text = data.CommMessage; if (data.WMNr >= 0) messages[data.WMNr].Text = data.CommMessage;
lock (this) lock (this)
{ {
@@ -1034,23 +1044,24 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
if (currentGroup < lastGroup) if (currentGroup < lastGroup)
{ {
/// Go to the next step / next group /// Go to the next step / next group
currentGroup++;
if (quido != null) if (quido != null)
{ {
quido.SetOutputs((ushort)(16 - currentGroup)); quido.SetOutputs((ushort)(16 - currentGroup - 1));
Thread.Sleep(100); Thread.Sleep(100);
} }
} currentGroup++;
}
else if (currentActivityStep + 1 < multiTestParams.Count) else if (currentActivityStep + 1 < multiTestParams.Count)
{ {
currentGroup = 0;
currentActivityStep++; currentActivityStep++;
activityLabel.Text = multiTestParams[currentActivityStep].Activity; activityLabel.Text = multiTestParams[currentActivityStep].Activity;
currentGroup = 1;
if (quido != null) if (quido != null)
{ {
quido.SetOutputs((ushort)(16 - currentGroup)); quido.SetOutputs((ushort)(16 - currentGroup - 1));
Thread.Sleep(100); Thread.Sleep(100);
} }
currentGroup++;
} }
else else
{ {