Big changes
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
public static class NiseNativeMethods
|
||||
{
|
||||
public enum MulticonnectMode
|
||||
{
|
||||
MulticonnectRoutes,
|
||||
NoMulticonnect,
|
||||
UseDefault
|
||||
}
|
||||
|
||||
// NISEStatus niSE_ClearError(Val NISESession hSession)
|
||||
[DllImport(@"C:\Windows\SysWOW64\nise.dll", CharSet = CharSet.Ansi, BestFitMapping = false)]
|
||||
internal static extern Int32 niSE_ClearError(Int32 hSession);
|
||||
|
||||
// NISEStatus niSE_CloseSession(Val NISESession hSession)
|
||||
[DllImport(@"C:\Windows\SysWOW64\nise.dll", CharSet = CharSet.Ansi, BestFitMapping = false)]
|
||||
internal static extern Int32 niSE_CloseSession(Int32 hSession);
|
||||
|
||||
// NISEStatus niSE_Connect(Val NISESession hSession, Val string connectSpec, Val __MIDL___MIDL_itf_Nise_0115_0003 multiconnectMode, NISEBoolean waitForDebounce);
|
||||
[DllImport(@"C:\Windows\SysWOW64\nise.dll", CharSet = CharSet.Ansi, BestFitMapping = false)]
|
||||
internal static extern Int32 niSE_Connect(Int32 hSession, string route, MulticonnectMode multiconnectMode, bool waitForDebounce);
|
||||
|
||||
// NISEStatus niSE_Disconnect(Val NISESession hSession, Val string disconnectSpec);
|
||||
[DllImport(@"C:\Windows\SysWOW64\nise.dll", CharSet = CharSet.Ansi, BestFitMapping = false)]
|
||||
internal static extern Int32 niSE_Disconnect(Int32 hSession, string disconnectSpec);
|
||||
|
||||
// NISEStatus niSE_DisconnectAll(Val NISESession hSession);
|
||||
[DllImport(@"C:\Windows\SysWOW64\nise.dll", CharSet = CharSet.Ansi, BestFitMapping = false)]
|
||||
internal static extern Int32 niSE_DisconnectAll(Int32 hSession);
|
||||
|
||||
// NISEStatus niSE_IsDebounced(Val NISESession hSession, Var NISEBoolean isDebounced);
|
||||
[DllImport(@"C:\Windows\SysWOW64\nise.dll", CharSet = CharSet.Ansi, BestFitMapping = false)]
|
||||
internal static extern Int32 niSE_IsDebounced(Int32 hSession, out bool isDebounced);
|
||||
|
||||
// NISEStatus niSE_OpenSession(Val string virtualDeviceName, Val string option, Var NISESession hSession)
|
||||
[DllImport(@"C:\Windows\SysWOW64\nise.dll", CharSet = CharSet.Ansi, BestFitMapping = false)]
|
||||
internal static extern Int32 niSE_OpenSession(string virtualDeviceName, string options, out Int32 hSession);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// SwitchNise factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchNise(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
var virtualDeviceName = _configuration.GetConfigurationValue("SwitchNise", "VirtualDeviceName", "");
|
||||
string options = _configuration.GetConfigurationValue("SwitchNise", "Options", "");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
DetailedStatus = "";
|
||||
DisplayEnabled = false;
|
||||
FrontPanelEnabled = false;
|
||||
Info = new InstrumentMetadata
|
||||
{
|
||||
ModelNumber = "NISE"
|
||||
};
|
||||
Name = virtualDeviceName;
|
||||
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
Status = State.Ready;
|
||||
}
|
||||
|
||||
public SwitchNise(string virtualDeviceName)
|
||||
{
|
||||
string options = "";
|
||||
var status = -123;
|
||||
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
DetailedStatus = "";
|
||||
DisplayEnabled = false;
|
||||
FrontPanelEnabled = false;
|
||||
Info = new InstrumentMetadata();
|
||||
Info.ModelNumber = "NISE";
|
||||
Name = virtualDeviceName;
|
||||
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
Status = State.Ready;
|
||||
}
|
||||
|
||||
public bool ClearErrors()
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_ClearError(_hSession);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "ClearError failed";
|
||||
|
||||
throw new InstrumentException("" + string.Format("Could not clear errors, error # {0}", status));
|
||||
}
|
||||
|
||||
Status = State.Ready;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Connect(string path)
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_Connect(_hSession, path, NiseNativeMethods.MulticonnectMode.NoMulticonnect, true);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "Connect failed";
|
||||
|
||||
throw new InstrumentException("" + string.Format("Could not connect '{0}', NISE error # {1}", path, status));
|
||||
}
|
||||
}
|
||||
|
||||
public string DetailedStatus
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_Disconnect(_hSession, path);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
throw new InstrumentException(string.Format("" + "Could not disconnect '{0}', NISE error # {1}", path, status));
|
||||
}
|
||||
}
|
||||
|
||||
public void DisconnectAll()
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_DisconnectAll(_hSession);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "DisconnectAll failed";
|
||||
|
||||
throw new InstrumentException(string.Format("" + "Could not disconnect all, NISE error # {0}", status));
|
||||
}
|
||||
}
|
||||
|
||||
//*** consider implementing 'set' to change back to some default value
|
||||
// not available
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
//*** consider implementing 'set' to change back to some default value
|
||||
// not available
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get;
|
||||
private 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
|
||||
|
||||
ClearErrors();
|
||||
}
|
||||
|
||||
public bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
bool isDebounced;
|
||||
int status = NiseNativeMethods.niSE_IsDebounced(_hSession, out isDebounced);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "IsDebounced failed";
|
||||
|
||||
throw new InstrumentException("" + string.Format("Could not check debounce, error # {0}", status));
|
||||
}
|
||||
|
||||
return isDebounced;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
return SelfTestResult.Pass;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
ClearErrors();
|
||||
DisconnectAll();
|
||||
|
||||
Status = State.Ready;
|
||||
DetailedStatus = "";
|
||||
}
|
||||
|
||||
// not available
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
Int32 status = NiseNativeMethods.niSE_CloseSession(_hSession);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.SwitchNise</AssemblyName>
|
||||
<Product>Switch Nise implementation</Product>
|
||||
<Description>Switch Nise implementation</Description>
|
||||
<OutputType>Library</OutputType>
|
||||
|
||||
<!-- Static versioning (Suitable for Development) -->
|
||||
<!-- Disable the line below for dynamic versioning -->
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="5.0.0" />
|
||||
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
|
||||
<PackageReference Include="Raytheon.Instruments.Switch.Contracts" Version="1.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SwitchSim\SwitchSim.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Copy all *.dlls and *.pdb in the output folder to a temp folder -->
|
||||
<Target Name="CopyFiles" AfterTargets="AfterBuild">
|
||||
<ItemGroup>
|
||||
<FILES_1 Include="$(OutDir)*.dll" />
|
||||
<FILES_2 Include="$(OutDir)*.pdb" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(FILES_1)" DestinationFolder="$(HalTempFolder)" />
|
||||
<Copy SourceFiles="@(FILES_2)" DestinationFolder="$(HalTempFolder)" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,140 @@
|
||||
// **********************************************************************************************************
|
||||
// SwitchNiseFactory.cs
|
||||
// 2/20/2023
|
||||
// NGI - Next Generation Interceptor
|
||||
//
|
||||
// Contract No. HQ0856-21-C-0003/1022000209
|
||||
//
|
||||
// THIS DOCUMENT DOES NOT CONTAIN TECHNOLOGY OR TECHNICAL DATA CONTROLLED UNDER EITHER THE U.S.
|
||||
// INTERNATIONAL TRAFFIC IN ARMS REGULATIONS OR THE U.S. EXPORT ADMINISTRATION REGULATIONS.
|
||||
//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON
|
||||
// COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT.
|
||||
// DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON
|
||||
// COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED
|
||||
// TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF
|
||||
// RAYTHEON COMPANY.
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// DESTRUCTION NOTICE: FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN DOD 5220.22-M,
|
||||
// NATIONAL INDUSTRIAL SECURITY PROGRAM OPERATING MANUAL, FEBRUARY 2006,
|
||||
// INCORPORATING CHANGE 1, MARCH 28, 2013, CHAPTER 5, SECTION 7, OR DODM 5200.01-VOLUME 3,
|
||||
// DOD INFORMATION SECURITY PROGRAM: PROTECTION OF CLASSIFIED INFORMATION, ENCLOSURE 3,
|
||||
// SECTION 17. FOR CONTROLLED UNCLASSIFIED INFORMATION FOLLOW THE PROCEDURES IN DODM 5200.01-VOLUME 4,
|
||||
// INFORMATION SECURITY PROGRAM: CONTROLLED UNCLASSIFIED INFORMATION.
|
||||
//
|
||||
// CONTROLLED BY: MISSILE DEFENSE AGENCY
|
||||
// CONTROLLED BY: GROUND-BASED MIDCOURSE DEFENSE PROGRAM OFFICE
|
||||
// CUI CATEGORY: CTI
|
||||
// DISTRIBUTION/DISSEMINATION CONTROL: F
|
||||
// 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;
|
||||
|
||||
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;
|
||||
|
||||
public SwitchNiseFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
/// <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;
|
||||
|
||||
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
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new SwitchNise(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public object GetInstrument(string name, bool simulateHw)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
if (simulateHw)
|
||||
return new SwitchSim(name, _configurationManager, _logger);
|
||||
else
|
||||
return new SwitchNise(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets supported interfaces
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user