Major upgrade

This commit is contained in:
Duc
2025-10-24 15:18:11 -07:00
parent fd85735c93
commit ce583d1664
478 changed files with 237518 additions and 47610 deletions

View File

@@ -23,367 +23,334 @@
//>>***************************************************************************
using System;
using VTI.VTEXSwitch.Interop;
using NLog;
using Raytheon.Common;
using VTI.VTEXSwitch.Interop;
namespace Raytheon.Instruments
{
/// <summary>
/// This is a class for controlling a VTI EX1200-3001, 5002, 4264 switch card.
/// It only supports individual relay mode at this time.
/// </summary>
public class SwitchVTI : ISwitch
{
#region PrivateMemberVariables
private VTEXSwitch _switch;
private string _name;
private readonly string _address;
private readonly string _options;
private State _state;
private SelfTestResult _selfTestResult;
/// <summary>
/// This is a class for controlling a VTI EX1200-3001, 5002, 4264 switch card.
/// It only supports individual relay mode at this time.
/// </summary>
public class SwitchVTI : ISwitch
{
#region PrivateMemberVariables
private VTEXSwitch _switch;
private string _name;
private readonly string _address;
private readonly string _options;
private State _state;
private SelfTestResult _selfTestResult;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
private readonly ILogger _logger;
#endregion
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#region PrivateFunctions
/// <summary>
/// Finalizer.
/// </summary>
~SwitchVTI()
{
Dispose(false);
}
#endregion
/// <summary>
/// Dispose of this object's resources.
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
Reset();
#region PrivateFunctions
/// <summary>
/// Finalizer.
/// </summary>
~SwitchVTI()
{
Dispose(false);
}
_switch.Close();
/// <summary>
/// Dispose of this object's resources.
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_state == State.Ready)
{
Reset();
_state = State.Uninitialized;
}
}
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected
}
}
}
_switch.Close();
/// <summary>
/// Perform self-test.
/// </summary>
private string SelfTest()
{
int testResult = 0;
_state = State.Uninitialized;
}
}
}
string selfTestMessage = "";
/// <summary>
/// Perform self-test.
/// </summary>
private string SelfTest()
{
int testResult = 0;
_switch.Utility.SelfTest(ref testResult, ref selfTestMessage);
string selfTestMessage = "";
if (testResult != 0)
{
throw new Exception("Self test returned an error code of: " + testResult.ToString() + ", and an error string of: " + selfTestMessage);
}
_switch.Utility.SelfTest(ref testResult, ref selfTestMessage);
return selfTestMessage;
}
#endregion
if (testResult != 0)
{
throw new Exception("Self test returned an error code of: " + testResult.ToString() + ", and an error string of: " + selfTestMessage);
}
#region PublicFunctions
return selfTestMessage;
}
#endregion
/// <summary>
/// SwitchVTI factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchVTI(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
#region PublicFunctions
_logger = logger;
/// <summary>
/// SwitchVTI factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchVTI(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_address = _configuration.GetConfigurationValue("SwitchVTI", "Address", "");
_options = _configuration.GetConfigurationValue("SwitchVTI", "Options", "");
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
_address = _configuration.GetConfigurationValue("SwitchVTI", "Address", "");
_options = _configuration.GetConfigurationValue("SwitchVTI", "Options", "");
/// <summary>
/// Constructor for RelaySwitch card.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="address">The address of the RelaySwitch.</param>
/// <param name="options">The options used for setting up the instrument.</param>
public SwitchVTI(string name, string address, string options)
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_address = address;
_options = options;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
// created in initialized
_switch = null;
/// <summary>
/// Constructor for RelaySwitch card.
/// </summary>
/// <param name="deviceName">The name.</param>
/// <param name="address">The address of the RelaySwitch.</param>
/// <param name="options">The options used for setting up the instrument.</param>
public SwitchVTI(string deviceName, string address, string options)
{
_name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_address = address;
_options = options;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
// created in initialized
_switch = null;
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
/// Close a single relay.
/// The COTS library works on string inputs:
/// - Ex Relay: "2!K1" Means card 2 relay 1.
/// </summary>
/// <param name="relay">The relay to close.</param>
public void Connect(string path)
{
_switch.InstrumentSpecific.CloseRelays(path);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
/// Open a single relay.
/// The COTS library works on string inputs:
/// - Ex Relay: "2!K1" Means card 2 relay 1.
/// </summary>
/// <param name="relay">The relay to open.</param>
public void Disconnect(string path)
{
_switch.InstrumentSpecific.OpenRelays(path);
}
/// <summary>
/// Close a single relay.
/// The COTS library works on string inputs:
/// - Ex Relay: "2!K1" Means card 2 relay 1.
/// </summary>
/// <param name="relay">The relay to close.</param>
public void Connect(string path)
{
_switch.InstrumentSpecific.CloseRelays(path);
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
string relayList = _switch.InstrumentSpecific.ListOfRelays;
/// <summary>
/// Open a single relay.
/// The COTS library works on string inputs:
/// - Ex Relay: "2!K1" Means card 2 relay 1.
/// </summary>
/// <param name="relay">The relay to open.</param>
public void Disconnect(string path)
{
_switch.InstrumentSpecific.OpenRelays(path);
}
_switch.InstrumentSpecific.OpenRelays(relayList);
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
string relayList = _switch.InstrumentSpecific.ListOfRelays;
/// <summary>
/// Dispose of resources.
/// </summary>
public void Dispose()
{
try
{
Dispose(true);
_switch.InstrumentSpecific.OpenRelays(relayList);
}
GC.SuppressFinalize(this);
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected
}
}
}
/// <summary>
/// Dispose of resources.
/// </summary>
public void Dispose()
{
Dispose(true);
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a VTI Switch";
}
}
GC.SuppressFinalize(this);
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotSupportedException();
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a VTI Switch";
}
}
set
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotSupportedException();
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotSupportedException();
}
set
{
throw new NotSupportedException();
}
}
set
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotSupportedException();
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotSupportedException();
}
}
set
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_switch = new VTEXSwitch();
_switch.Initialize(_address, false, true, _options);
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_switch = new VTEXSwitch();
_switch.Initialize(_address, false, true, _options);
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
int testResult = 0;
string result = "";
_switch.Utility.SelfTest(ref testResult, ref result);
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
// Set measurement input to backplane after performing self test. Default is front panel.
// _dmm.Measurement.In = VTEXDmmInputSelectEnum.VTEXDmmInputSelectInternal;
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
int testResult = 0;
string result = "";
_switch.Utility.SelfTest(ref testResult, ref result);
if (testResult > 0)
{
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
throw new Exception("self test failed with an Error Code: " + testResult + " and Error Message: " + result);
}
// Set measurement input to backplane after performing self test. Default is front panel.
// _dmm.Measurement.In = VTEXDmmInputSelectEnum.VTEXDmmInputSelectInternal;
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
if (testResult > 0)
{
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
throw new Exception("self test failed with an Error Code: " + testResult + " and Error Message: " + result);
}
return _selfTestResult;
}
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
/// <summary>
///
/// </summary>
public void Reset()
{
_switch.Utility.Reset();
}
return _selfTestResult;
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
_switch.Utility.Reset();
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
Reset();
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
_switch.Close();
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
Reset();
_state = State.Uninitialized;
}
}
#endregion
}
_switch.Close();
_state = State.Uninitialized;
}
}
#endregion
}
}

View File

@@ -31,71 +31,64 @@
// POC: Alex Kravchenko (1118268)
// **********************************************************************************************************
using NLog;
using Raytheon.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Reflection;
using NLog;
using Raytheon.Common;
namespace Raytheon.Instruments
{
[ExportInstrumentFactory(ModelNumber = "SwitchVTIFactory")]
public class SwitchVTIFactory : IInstrumentFactory
{
/// <summary>
/// The supported interfaces
/// </summary>
private readonly List<Type> _supportedInterfaces = new List<Type>();
private ILogger _logger;
private readonly IConfigurationManager _configurationManager;
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
private static string DefaultPath;
[ExportInstrumentFactory(ModelNumber = "SwitchVTIFactory")]
public class SwitchVTIFactory : IInstrumentFactory
{
private readonly List<Type> _supportedInterfaces = new List<Type>();
public SwitchVTIFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
private readonly IConfigurationManager _configurationManager;
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
private static string DefaultPath;
/// <summary>
/// COECommDeviceInstrumentFactory injection constructor
/// </summary>
/// <param name="configManager"></param>
/// <param name="simEngine"></param>
/// <param name="logger"></param>
[ImportingConstructor]
public SwitchVTIFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
public SwitchVTIFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
if (LogManager.Configuration == null)
{
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
}
/// <summary>
/// SwitchVTIFactory injection constructor
/// </summary>
[ImportingConstructor]
public SwitchVTIFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
_configurationManager = configManager ?? GetConfigurationManager();
_supportedInterfaces.Add(typeof(ISwitch));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new SwitchVTI(name, _configurationManager, _logger);
}
catch (Exception)
{
throw;
}
}
if (LogManager.Configuration == null)
{
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
}
_configurationManager = configManager ?? GetConfigurationManager();
_supportedInterfaces.Add(typeof(ISwitch));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
return new SwitchVTI(name, _configurationManager);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets the instrument
@@ -106,12 +99,10 @@ namespace Raytheon.Instruments
{
try
{
_logger = LogManager.GetLogger(name);
if (simulateHw)
return new SwitchSim(name, _configurationManager, _logger);
return new SwitchSim(name, _configurationManager);
else
return new SwitchVTI(name, _configurationManager, _logger);
return new SwitchVTI(name, _configurationManager);
}
catch (Exception)
{
@@ -124,17 +115,17 @@ namespace Raytheon.Instruments
/// </summary>
/// <returns></returns>
public ICollection<Type> GetSupportedInterfaces()
{
return _supportedInterfaces.ToArray();
}
{
return _supportedInterfaces.ToArray();
}
/// <summary>
/// returns configuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
/// </summary>
/// <returns></returns>
private static IConfigurationManager GetConfigurationManager()
{
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
}
}
/// <summary>
/// returns configuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
/// </summary>
/// <returns></returns>
private static IConfigurationManager GetConfigurationManager()
{
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
}
}
}