138 lines
3.9 KiB
C#
138 lines
3.9 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Dirichlet.Numerics;
|
|
using log4net;
|
|
using TBF.BenchControl.GenericDevices;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.Elde.CoverTest
|
|
{
|
|
public class CoverTest : ComponentBase, IOperation, ISequenceCondition
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(CoverTest));
|
|
private static readonly ILog bypassLog = LogManager.GetLogger("BypassLog");
|
|
|
|
public override string ToString() { return string.Format("CoverTest({0})", Cfg.ToString(1)); }
|
|
|
|
readonly CoverTestCfg coverTestCfg;
|
|
|
|
readonly ControlBoardDev controlBoard;
|
|
readonly int bitPosition; /// 0 .. 63
|
|
readonly ulong mask; /// derived from bitPosition in the constructor
|
|
readonly ulong target;
|
|
readonly string message;
|
|
readonly Users.Grp.GID bypassLevel;
|
|
|
|
public CoverTest()
|
|
{
|
|
}
|
|
|
|
public CoverTest(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
coverTestCfg = cfg as CoverTestCfg;
|
|
|
|
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
|
|
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
|
|
|
|
bitPosition = coverTestCfg.BitPosition;
|
|
mask = (((ulong)1) << coverTestCfg.BitPosition);
|
|
target = coverTestCfg.Invert ? 0 : mask;
|
|
message = coverTestCfg.Message;
|
|
bypassLevel = coverTestCfg.BypassLevel;
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
|
|
public int ConditionsCount { get { return 1; } }
|
|
|
|
/// Strings are added to the combo-box for transition sequence condition selection
|
|
public string ConditionName(int i)
|
|
{
|
|
if (i < 1 && i >= 0)
|
|
return Name;
|
|
else
|
|
return string.Empty;
|
|
}
|
|
|
|
/// Operation to be executed as a part of a transition sequence
|
|
public IOperation ConditionOp(int i)
|
|
{
|
|
if (i < 1 && i >= 0)
|
|
return this;
|
|
else
|
|
return null;
|
|
}
|
|
|
|
|
|
CoverTestForm modelessDlg;
|
|
bool completed = false;
|
|
|
|
|
|
delegate void CoverTestFormDlgt(CoverTest myRef);
|
|
///
|
|
void OpenFormDlg(CoverTest myRef)
|
|
{
|
|
myRef.modelessDlg = new CoverTestForm(message, bypassLevel, bypassLog);
|
|
modelessDlg.Show();
|
|
}
|
|
|
|
|
|
public IOperation CoverTestOp()
|
|
{
|
|
return this;
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
log.DebugFormat("Start()");
|
|
completed = false;
|
|
Program.MainWnd.Invoke(new CoverTestFormDlgt(OpenFormDlg), this);
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>Event.ResultsPrinted</returns>
|
|
public Event Run()
|
|
{
|
|
bool conditionMet = ((controlBoard.DigitalInputs & mask) == target);
|
|
|
|
if (completed || conditionMet)
|
|
{
|
|
completed = true;
|
|
}
|
|
|
|
if (completed || modelessDlg.Completed)
|
|
{
|
|
completed = true;
|
|
CloseModelessDlg();
|
|
log.DebugFormat("Run() ... conditionMet={0} completed={1} ... Event.ConditionMet", conditionMet, completed);
|
|
return Event.ConditionMet;
|
|
}
|
|
|
|
log.DebugFormat("Run() ... conditionMet={0} completed={1} ... Event.ConditionNotMet", conditionMet, completed);
|
|
return Event.ConditionNotMet;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
log.DebugFormat("Stop()");
|
|
CloseModelessDlg();
|
|
}
|
|
|
|
void CloseModelessDlg()
|
|
{
|
|
if (modelessDlg is GenericDevices.IHasCompleted)
|
|
{
|
|
UiBridge.Bridge.OnCloseQandAForm(this, null);
|
|
modelessDlg = null;
|
|
}
|
|
}
|
|
}
|
|
}
|