tbf/TBF/Rig/TestMethods/S640Communication/S640CommSeq.cs
2021-10-26 19:38:09 +02:00

96 lines
3.2 KiB
C#

///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Drawing; /// Point definition
using log4net;
using Common;
using Config.Entities;
using TBF.Rig.Sequences;
using TBF.Resources;
using TBF.UiBridge;
namespace TBF.Rig.TestMethods.S640Communication
{
public class S640CommSeq : Sequences.SequenceBase
{
private static readonly ILog log = LogManager.GetLogger(typeof(S640CommSeq));
System.Windows.Forms.Form modelessDlg;
///
delegate void S640CommFormDlgt(S640CommSeq myRef, S640Activity activity, I640Cfg config, ProcParams procParams, Test test);
///
void OpenS640CommForm(S640CommSeq myRef, S640Activity activity, I640Cfg config, ProcParams procParams, Test test)
{
myRef.modelessDlg = new S640CommForm(activity, config, procParams, test);
myRef.modelessDlg.Show();
}
///
void CloseS640CommForm()
{
UiBridge.Bridge.OnCloseModelessForm(this, null);
modelessDlg = null;
}
/// <summary>
/// Flying start mass collection method sequence
/// </summary>
/// <param name="test">Test entity</param>
/// <returns>
/// Event.Done . . . . . . . OK
/// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP
/// Event.OpArgumentError . Target flow is out of range
/// Event.Error . . . . . . Unspecified error
/// </returns>
public IList<Event> Execute(Test test, int repetitionNr, S640Activity activity, I640Cfg config, ProcParams procParams)
{
IList<Event> e; /// Events from currently running operations
checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state
processDataLoggingOp = new TBF.Rig.Operations.ProcessDataLoggingOp(processDataLogger, this, false);
modelessDlg = null;
///
/// Show the modeless dialog with error indication
///
Program.MainWnd.Invoke(new S640CommFormDlgt(OpenS640CommForm), new object[] { this, activity, config, procParams, test });
//------------------------------------------------
Bridge.OnActivity(this, Strings.iPerl_Communication_in_progress);
//------------------------------------------------
bool stopPressed = false; /// true when STOP button pressed
bool completed = false;
State.Create("iPerlCommunicationSeq : Wait until the entry form is closed")
.AddOperation(checkUiOp)
.EnterState();
do {
e = StateMachine.WaitRunDevsRunOps();
stopPressed = TestAndLogUiCmdStop(test,e);
completed = (modelessDlg is GenericDevices.IHasCompleted)
&& (modelessDlg as GenericDevices.IHasCompleted).Completed;
}
while (!stopPressed && !completed);
if (stopPressed)
{
CloseS640CommForm();
return new List<Event> { Event.UiCmdStop };
}
else
{
TBF.UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(test.Name, Progress.Completed));
}
/// Test 'Quit'
modelessDlg = null; /// Modeless dialog is closed now
return new List<Event> { Event.Done };
}
}
}