tbf/TBF/Rig/TestMethods/GrabImage/Component.cs
2021-03-05 16:12:24 +01:00

76 lines
2.0 KiB
C#

///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using log4net;
using Config.Entities;
using TBF.Rig;
namespace TBF.Rig.TestMethods.GrabImage
{
public class Component : ComponentBase, GenericDevices.ITestMethod
{
private static readonly ILog log = LogManager.GetLogger(typeof(Component));
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(1)); }
public bool CanTest(MetersKind meters) { return true; }
public bool DoTransitions() { return false; }
readonly GrabImageCfg cfg;
#region Configuration Change Handling
public static void OnCfgChange(object sender, CfgChangeArgs args)
{
if (CfgChangeHandler == null) return;
try { CfgChangeHandler(sender, args); }
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
}
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
public override void StartChangeHandler()
{
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
{
GrabImageCfg tmpcfg = args.Cfg as GrabImageCfg;
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
{
if (args.Command == CfgChangeCmd.CfgChange)
{
cfg.ImageFileName = tmpcfg.ImageFileName;
cfg.BlackAndWhite = tmpcfg.BlackAndWhite;
cfg.LowResolution = tmpcfg.LowResolution;
cfg.ImageRotation = tmpcfg.ImageRotation;
}
}
};
}
#endregion Configuration Change Handling
public bool CheckDeviceCaps(Test test, OutputPath devices, out string message)
{
message = string.Format("{0}: CheckDeviceCaps() is not implemented yet", Name);
return false;
}
public Component() { }
///
public Component(Generic.IComponentCfg cfg)
: base(cfg)
{
this.cfg = cfg as GrabImageCfg;
log.Warn(this.ToString());
}
public IList<Event> Execute(Test test, int idummy, bool bdummy)
{
return (new GrabImageSeq()).Execute(test, cfg);
}
}
}