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

@@ -22,339 +22,306 @@ using Raytheon.Common;
namespace Raytheon.Instruments
{
/// <summary>
/// A simulated implementation of the ISwitch interface.
/// </summary>
public class SwitchNiPxi : ISwitch, IDisposable
{
#region PrivateMemberVariables
/// <summary>
/// A simulated implementation of the ISwitch interface.
/// </summary>
public class SwitchNiPxi : ISwitch, IDisposable
{
#region PrivateMemberVariables
private NISwitch _niSwitch;
private string _name;
private readonly string _address;
private readonly string _topology;
private State _state;
private SelfTestResult _selfTestResult;
private NISwitch _niSwitch;
private string _name;
private readonly string _address;
private readonly string _topology;
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
#endregion
/// <summary>
/// The Finalizer
/// </summary>
~SwitchNiPxi()
{
Dispose(false);
}
#region PrivateFunctions
/// <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)
{
_niSwitch.Utility.Reset();
/// <summary>
/// The Finalizer
/// </summary>
~SwitchNiPxi()
{
Dispose(false);
}
_niSwitch.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)
{
_niSwitch.Utility.Reset();
_niSwitch.Dispose();
_niSwitch.Close();
_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
}
}
}
_niSwitch.Dispose();
#endregion
_state = State.Uninitialized;
}
}
}
#region PublicFunctions
#endregion
/// <summary>
/// SwitchNiPxi factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchNiPxi(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
#region PublicFunctions
_logger = logger;
/// <summary>
/// SwitchNiPxi factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchNiPxi(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_address = _configuration.GetConfigurationValue("SwitchNiPxi", "Address", "");
_topology = _configuration.GetConfigurationValue("SwitchNiPxi", "Topology", "");
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
_address = _configuration.GetConfigurationValue("SwitchNiPxi", "Address", "");
_topology = _configuration.GetConfigurationValue("SwitchNiPxi", "Topology", "");
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="address"></param>
public SwitchNiPxi(string name, string address, string topology = "")
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_address = address;
_topology = topology;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
// set in Initialize()
_niSwitch = null;
/// <summary>
///
/// </summary>
/// <param name="deviceName"></param>
/// <param name="address"></param>
public SwitchNiPxi(string deviceName, string address, string topology = "")
{
_name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_address = address;
_topology = topology;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
// set in Initialize()
_niSwitch = null;
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
_niSwitch.RelayOperations.RelayControl(path, SwitchRelayAction.CloseRelay);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
_niSwitch.RelayOperations.RelayControl(path, SwitchRelayAction.OpenRelay);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
_niSwitch.RelayOperations.RelayControl(path, SwitchRelayAction.CloseRelay);
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
_niSwitch.Path.DisconnectAll();
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
_niSwitch.RelayOperations.RelayControl(path, SwitchRelayAction.OpenRelay);
}
/// <summary>
/// Dispose of this object.
/// </summary>
public void Dispose()
{
try
{
Dispose(true);
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
_niSwitch.Path.DisconnectAll();
}
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 this object.
/// </summary>
public void Dispose()
{
Dispose(true);
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a NI Switch";
}
}
GC.SuppressFinalize(this);
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a NI Switch";
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_niSwitch = new NISwitch(_address, _topology, false, true);
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
//_niSwitch.ModuleCharacteristics.PowerDownLatchingRelaysAfterDebounce
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_niSwitch = new NISwitch(_address, _topology, false, true);
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
//_niSwitch.ModuleCharacteristics.PowerDownLatchingRelaysAfterDebounce
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
Ivi.Driver.SelfTestResult res = _niSwitch.Utility.SelfTest();
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
if (res.Code != 0)
{
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
throw new Exception("self test returned: " + res.Code + "," + res.Message + " on card " + _name);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
Ivi.Driver.SelfTestResult res = _niSwitch.Utility.SelfTest();
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
if (res.Code != 0)
{
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
throw new Exception("self test returned: " + res.Code + "," + res.Message + " on card " + _name);
}
return _selfTestResult;
}
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
/// <summary>
///
/// </summary>
public void Reset()
{
_niSwitch.Utility.Reset();
}
return _selfTestResult;
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
_niSwitch.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)
{
_niSwitch.Utility.Reset();
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
_niSwitch.Close();
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
_niSwitch.Utility.Reset();
_niSwitch.Dispose();
_niSwitch.Close();
_state = State.Uninitialized;
}
}
_niSwitch.Dispose();
#endregion
}
_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 = "SwitchNiPxiFactory")]
public class SwitchNiPxiFactory : 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 = "SwitchNiPxiFactory")]
public class SwitchNiPxiFactory : IInstrumentFactory
{
private readonly List<Type> _supportedInterfaces = new List<Type>();
public SwitchNiPxiFactory(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 SwitchNiPxiFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
public SwitchNiPxiFactory(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>
/// SwitchNiPxiFactory injection constructor
/// </summary>
[ImportingConstructor]
public SwitchNiPxiFactory([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 SwitchNiPxi(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 SwitchNiPxi(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 SwitchNiPxi(name, _configurationManager, _logger);
return new SwitchNiPxi(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);
}
}
}