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

@@ -15,250 +15,246 @@ GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using System;
using NLog;
using Raytheon.Common;
using System;
namespace Raytheon.Instruments
{
public class SwitchNise : ISwitch
{
private int _hSession = 0;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
public class SwitchNise : ISwitch
{
private int _hSession = 0;
/// <summary>
/// SwitchNise factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchNise(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
private readonly ILogger _logger;
_logger = logger;
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
/// <summary>
/// SwitchNise factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchNise(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
var virtualDeviceName = _configuration.GetConfigurationValue("SwitchNise", "VirtualDeviceName", "");
string options = _configuration.GetConfigurationValue("SwitchNise", "Options", "");
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
try
{
int status = NiseNativeMethods.niSE_OpenSession(virtualDeviceName, options, out _hSession);
if (status != 0)
{
throw new InstrumentException(string.Format("Could not open NISE session '{0}', error # {1}", virtualDeviceName, status));
}
}
catch (BadImageFormatException ex)
{
throw new InstrumentException("Possible 32/64-bit issue with NI Switch Executive, see inner exception.", ex);
}
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
DetailedStatus = "";
DisplayEnabled = false;
FrontPanelEnabled = false;
Info = new InstrumentMetadata
{
ModelNumber = "NISE"
};
Name = virtualDeviceName;
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
Status = State.Ready;
}
var virtualDeviceName = _configuration.GetConfigurationValue("SwitchNise", "VirtualDeviceName", "");
string options = _configuration.GetConfigurationValue("SwitchNise", "Options", "");
public SwitchNise(string virtualDeviceName)
{
string options = "";
var status = -123;
try
{
int status = NiseNativeMethods.niSE_OpenSession(virtualDeviceName, options, out _hSession);
if (status != 0)
{
throw new InstrumentException(string.Format("Could not open NISE session '{0}', error # {1}", virtualDeviceName, status));
}
}
catch (BadImageFormatException ex)
{
throw new InstrumentException("Possible 32/64-bit issue with NI Switch Executive, see inner exception.", ex);
}
_logger = LogManager.GetCurrentClassLogger();
DetailedStatus = "";
DisplayEnabled = false;
FrontPanelEnabled = false;
Info = new InstrumentMetadata
{
ModelNumber = "NISE"
};
Name = virtualDeviceName;
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
Status = State.Ready;
}
try
{
status = NiseNativeMethods.niSE_OpenSession(virtualDeviceName, options, out _hSession);
public SwitchNise(string virtualDeviceName)
{
string options = "";
var status = -123;
if (status != 0)
{
throw new InstrumentException(string.Format("Could not open NISE session '{0}', error # {1}", virtualDeviceName, status));
}
}
catch (BadImageFormatException ex)
{
throw new InstrumentException("Possible 32/64-bit issue with NI Switch Executive, see inner exception.", ex);
}
_logger = LogManager.GetLogger($"{this.GetType().Name} - {virtualDeviceName}");
DetailedStatus = "";
DisplayEnabled = false;
FrontPanelEnabled = false;
Info = new InstrumentMetadata();
Info.ModelNumber = "NISE";
Name = virtualDeviceName;
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
Status = State.Ready;
}
try
{
status = NiseNativeMethods.niSE_OpenSession(virtualDeviceName, options, out _hSession);
public bool ClearErrors()
{
int status = NiseNativeMethods.niSE_ClearError(_hSession);
if (status != 0)
{
throw new InstrumentException(string.Format("Could not open NISE session '{0}', error # {1}", virtualDeviceName, status));
}
}
catch (BadImageFormatException ex)
{
throw new InstrumentException("Possible 32/64-bit issue with NI Switch Executive, see inner exception.", ex);
}
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "ClearError failed";
DetailedStatus = "";
DisplayEnabled = false;
FrontPanelEnabled = false;
Info = new InstrumentMetadata();
Info.ModelNumber = "NISE";
Name = virtualDeviceName;
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
Status = State.Ready;
}
throw new InstrumentException("" + string.Format("Could not clear errors, error # {0}", status));
}
public bool ClearErrors()
{
int status = NiseNativeMethods.niSE_ClearError(_hSession);
Status = State.Ready;
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "ClearError failed";
return true;
}
throw new InstrumentException("" + string.Format("Could not clear errors, error # {0}", status));
}
public void Connect(string path)
{
int status = NiseNativeMethods.niSE_Connect(_hSession, path, NiseNativeMethods.MulticonnectMode.NoMulticonnect, true);
Status = State.Ready;
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "Connect failed";
return true;
}
throw new InstrumentException("" + string.Format("Could not connect '{0}', NISE error # {1}", path, status));
}
}
public void Connect(string path)
{
int status = NiseNativeMethods.niSE_Connect(_hSession, path, NiseNativeMethods.MulticonnectMode.NoMulticonnect, true);
public string DetailedStatus
{
get;
private set;
}
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "Connect failed";
public void Disconnect(string path)
{
int status = NiseNativeMethods.niSE_Disconnect(_hSession, path);
throw new InstrumentException("" + string.Format("Could not connect '{0}', NISE error # {1}", path, status));
}
}
if (status != 0)
{
throw new InstrumentException(string.Format("" + "Could not disconnect '{0}', NISE error # {1}", path, status));
}
}
public string DetailedStatus
{
get;
private set;
}
public void DisconnectAll()
{
int status = NiseNativeMethods.niSE_DisconnectAll(_hSession);
public void Disconnect(string path)
{
int status = NiseNativeMethods.niSE_Disconnect(_hSession, path);
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "DisconnectAll failed";
if (status != 0)
{
throw new InstrumentException(string.Format("" + "Could not disconnect '{0}', NISE error # {1}", path, status));
}
}
throw new InstrumentException(string.Format("" + "Could not disconnect all, NISE error # {0}", status));
}
}
public void DisconnectAll()
{
int status = NiseNativeMethods.niSE_DisconnectAll(_hSession);
//*** consider implementing 'set' to change back to some default value
// not available
public bool DisplayEnabled
{
get;
set;
}
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "DisconnectAll failed";
//*** consider implementing 'set' to change back to some default value
// not available
public bool FrontPanelEnabled
{
get;
set;
}
throw new InstrumentException(string.Format("" + "Could not disconnect all, NISE error # {0}", status));
}
}
public InstrumentMetadata Info
{
get;
private set;
}
//*** consider implementing 'set' to change back to some default value
// not available
public bool DisplayEnabled
{
get;
set;
}
public void Initialize()
{
// do not want to allow user to open another session since they must close each one
// they open. already opened in constructor
//*** consider implementing 'set' to change back to some default value
// not available
public bool FrontPanelEnabled
{
get;
set;
}
ClearErrors();
}
public InstrumentMetadata Info
{
get;
private set;
}
public bool IsDebounced
{
get
{
bool isDebounced;
int status = NiseNativeMethods.niSE_IsDebounced(_hSession, out isDebounced);
public void Initialize()
{
// do not want to allow user to open another session since they must close each one
// they open. already opened in constructor
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "IsDebounced failed";
ClearErrors();
}
throw new InstrumentException("" + string.Format("Could not check debounce, error # {0}", status));
}
public bool IsDebounced
{
get
{
bool isDebounced;
int status = NiseNativeMethods.niSE_IsDebounced(_hSession, out isDebounced);
return isDebounced;
}
}
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "IsDebounced failed";
public string Name
{
get;
private set;
}
throw new InstrumentException("" + string.Format("Could not check debounce, error # {0}", status));
}
public SelfTestResult PerformSelfTest()
{
return SelfTestResult.Pass;
}
return isDebounced;
}
}
public void Reset()
{
ClearErrors();
DisconnectAll();
public string Name
{
get;
private set;
}
Status = State.Ready;
DetailedStatus = "";
}
public SelfTestResult PerformSelfTest()
{
return SelfTestResult.Pass;
}
// not available
public SelfTestResult SelfTestResult
{
get;
private set;
}
public void Reset()
{
ClearErrors();
DisconnectAll();
public void Shutdown()
{
Int32 status = NiseNativeMethods.niSE_CloseSession(_hSession);
Status = State.Ready;
DetailedStatus = "";
}
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "Close failed";
// not available
public SelfTestResult SelfTestResult
{
get;
private set;
}
throw new InstrumentException("" + string.Format("Could not close NISE session, error # {0}", status));
}
}
public void Shutdown()
{
Int32 status = NiseNativeMethods.niSE_CloseSession(_hSession);
public State Status
{
get;
private set;
}
}
if (status != 0)
{
Status = State.HardwareFailure;
DetailedStatus = "Close failed";
throw new InstrumentException("" + string.Format("Could not close NISE session, error # {0}", status));
}
}
public State Status
{
get;
private set;
}
}
}

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 = "SwitchNiseFactory")]
public class SwitchNiseFactory : 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 = "SwitchNiseFactory")]
public class SwitchNiseFactory : IInstrumentFactory
{
private readonly List<Type> _supportedInterfaces = new List<Type>();
public SwitchNiseFactory(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 SwitchNiseFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
public SwitchNiseFactory(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>
/// SwitchNiseFactory injection constructor
/// </summary>
[ImportingConstructor]
public SwitchNiseFactory([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 SwitchNise(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 SwitchNise(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 SwitchNise(name, _configurationManager, _logger);
return new SwitchNise(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);
}
}
}