130 lines
4.7 KiB
C#
130 lines
4.7 KiB
C#
///
|
|
/// Copyright (c) 2015-2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.IO.Ports;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.Rig;
|
|
|
|
namespace TBF.Rig.TestMethods.iPerlCommunication
|
|
{
|
|
public class TestMethod : ComponentBase, GenericDevices.ISimultTestMethod, Generic.IDevice
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod));
|
|
protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData");
|
|
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(1)); }
|
|
|
|
public bool CanTest(MetersKind meters) { return meters == MetersKind.Single; }
|
|
public bool DoTransitions() { return false; }
|
|
public bool CheckDeviceCaps(Test test, OutputPath devices, out string message)
|
|
{
|
|
message = string.Format("{0}: CheckDeviceCaps() is not implemented yet", Name);
|
|
return false;
|
|
}
|
|
|
|
|
|
public bool SimultWithPrevious { get { return testMethodCfg.TestParams.SimultWithPrevious; } }
|
|
public bool SimultWithNext { get { return testMethodCfg.TestParams.SimultWithNext; } }
|
|
|
|
#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)
|
|
{
|
|
TestMethodCfg tmpCfg = args.Cfg as TestMethodCfg;
|
|
if (tmpCfg != null && tmpCfg.Name.Equals(Name))
|
|
{
|
|
if (args.Command == CfgChangeCmd.CfgChange)
|
|
{
|
|
testMethodCfg.CommTimeout = tmpCfg.CommTimeout;
|
|
testMethodCfg.DelayBetweenRetries = tmpCfg.DelayBetweenRetries;
|
|
testMethodCfg.MaxCommRetries = tmpCfg.MaxCommRetries;
|
|
testMethodCfg.IperlCheckErrorsToStop = tmpCfg.IperlCheckErrorsToStop;
|
|
testMethodCfg.UseWebService = tmpCfg.UseWebService;
|
|
testMethodCfg.BaseUrl = tmpCfg.BaseUrl;
|
|
testMethodCfg.RelativeUrl = tmpCfg.RelativeUrl;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#endregion Configuration Change Handling
|
|
|
|
|
|
readonly TestMethodCfg testMethodCfg;
|
|
|
|
public TestMethod() { }
|
|
///
|
|
public TestMethod(Generic.IComponentCfg cfg)
|
|
: base(cfg)
|
|
{
|
|
testMethodCfg = cfg as TestMethodCfg;
|
|
log.Warn(this.ToString());
|
|
}
|
|
|
|
/// IDevice interface - only Initialize() is used
|
|
public void Initialize()
|
|
{
|
|
if (DebugLevel == DebugMode.Normal)
|
|
{
|
|
/// Check whether RFID serial ports are free
|
|
SerialPort rfidPort;
|
|
if (testMethodCfg.RfidPortNrBoard1 != 0)
|
|
{
|
|
rfidPort = new SerialPort(string.Format("COM{0}", testMethodCfg.RfidPortNrBoard1), 9600, Parity.None, 8, StopBits.One);
|
|
rfidPort.Open();
|
|
rfidPort.Close();
|
|
}
|
|
|
|
if (testMethodCfg.RfidPortNrBoard2 != 0)
|
|
{
|
|
rfidPort = new SerialPort(string.Format("COM{0}", testMethodCfg.RfidPortNrBoard2), 9600, Parity.None, 8, StopBits.One);
|
|
rfidPort.Open();
|
|
rfidPort.Close();
|
|
}
|
|
|
|
if (testMethodCfg.RfidPortNrBoard3 != 0)
|
|
{
|
|
rfidPort = new SerialPort(string.Format("COM{0}", testMethodCfg.RfidPortNrBoard3), 9600, Parity.None, 8, StopBits.One);
|
|
rfidPort.Open();
|
|
rfidPort.Close();
|
|
}
|
|
|
|
if (testMethodCfg.RfidPortNrBoard4 != 0)
|
|
{
|
|
rfidPort = new SerialPort(string.Format("COM{0}", testMethodCfg.RfidPortNrBoard4), 9600, Parity.None, 8, StopBits.One);
|
|
rfidPort.Open();
|
|
rfidPort.Close();
|
|
}
|
|
}
|
|
|
|
rfidDataLogger.Fatal("------------------------------------------------------------------------");
|
|
rfidDataLogger.FatalFormat("Test Bench Framework ver. {0}", Program.Version);
|
|
}
|
|
|
|
/// IDevice interface - only Initialize() is used
|
|
public void RunDeviceBefore() { }
|
|
public void RunDeviceAfter() { }
|
|
public void StopDevice() { }
|
|
public void StopDevice2() { }
|
|
|
|
public IList<Event> Execute(Test test, int repetNr, bool isLastRepetition)
|
|
{
|
|
return (new iPerlCommunicationSeq()).Execute(test, repetNr, testMethodCfg, testMethodCfg.TestParams);
|
|
}
|
|
}
|
|
}
|