Big changes

This commit is contained in:
Duc
2025-03-13 12:04:22 -07:00
parent c689fcb7f9
commit ffa9905494
748 changed files with 199255 additions and 3743 deletions

View File

@@ -0,0 +1,533 @@
// 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 System;
using VTI.VTEXDmm.Interop;
using Raytheon.Instruments.Dmm;
using Raytheon.Units;
using NLog;
using Raytheon.Common;
namespace Raytheon.Instruments
{
/// <summary>
/// A VTI Dmm
/// </summary>
public class DMMVTI : IDmm
{
#region PrivateMemberVariables
private readonly string _address;
private VTEXDmm _dmm;
private State _state;
private SelfTestResult _selfTestResult;
private readonly string _options;
private const int _READ_TIMEOUT = 1000;
private string _name;
private MeasurementFunction _lastType;
private double _lastRange;
private double _lastResolution;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#endregion
#region PrivateFunctions
/// <summary>
/// Dispose of this object
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
_dmm.Utility.Reset();
_dmm.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
}
}
}
#endregion
#region PublicFunctions
/// <summary>
/// DMMVTI factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public DMMVTI(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
_logger = logger;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_address = _configuration.GetConfigurationValue("DMMVTI", "Address", "");
_options = _configuration.GetConfigurationValue("DMMVTI", "Options", "");
_lastType = 0;
_lastRange = 0;
_lastResolution = 0;
//created in Initialize()
_dmm = null;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
/// The constructor which opens the handle to the DMM instrument.
/// </summary>
/// <param name="address">The address of the DMM.</param>
/// <param name="options">The options used for setting up the instrument.</param>
public DMMVTI(string name, string address, string options)
{
_name = name;
_address = address;
_options = options;
_lastType = 0;
_lastRange = 0;
_lastResolution = 0;
_logger = LogManager.GetCurrentClassLogger();
// create in Initialize()
_dmm = null;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
/// The Finalizer.
/// </summary>
~DMMVTI()
{
Dispose(false);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="range"></param>
/// <param name="resolution"></param>
public void ConfigureCurrentMeasurement(MeasurementFunction type, Current range, Current resolution)
{
throw new NotImplementedException();
/*_lastType = type;
_lastRange = range.Amps;
_lastResolution = resolution.Amps;*/
}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="range"></param>
/// <param name="resolution"></param>
public void ConfigureVoltageMeasurement(MeasurementFunction type, Voltage range, Voltage resolution)
{
if (type != MeasurementFunction.DCVolts && type != MeasurementFunction.ACVolts)
{
throw new Exception("only ac or dc volt is acceptable for param type: " + type.ToString());
}
_lastType = type;
_lastRange = range.Volts;
_lastResolution = resolution.Volts;
}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="range"></param>
/// <param name="resolution"></param>
public void ConfigureResistanceMeasurement(MeasurementFunction type, Resistance range, Resistance resolution)
{
if (type != MeasurementFunction.FourWireResistance && type != MeasurementFunction.TwoWireResistance)
{
throw new Exception("only FourWireResistance or TwoWireResistance is acceptable for param type: " + _lastType.ToString());
}
_lastType = type;
_lastRange = range.Ohms;
_lastResolution = resolution.Ohms;
}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="range"></param>
/// <param name="resolution"></param>
public void ConfigureFrequencyMeasurement(MeasurementFunction type, Frequency range, Frequency resolution)
{
if (type != MeasurementFunction.Frequency)
{
throw new Exception("only frequency is acceptable for param type: " + _lastType.ToString());
}
_lastType = type;
_lastRange = range.Hertz;
_lastResolution = resolution.Hertz;
}
/// <summary>
/// Dispose of this objects resources
/// </summary>
public void Dispose()
{
try
{
Dispose(true);
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>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a VTI Dmm";
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotSupportedException();
}
set
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotSupportedException();
}
set
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_dmm = new VTEXDmm();
_dmm.Initialize(_address, true, true, _options);
// Set measurement input to backplane after performing init(). Default is front panel.
_dmm.Measurement.Input = VTEXDmmInputSelectEnum.VTEXDmmInputSelectInternal;
_selfTestResult = PerformSelfTest();
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
public MeasurementFunction MeasurementType
{
get
{
throw new NotSupportedException();
}
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public Current MeasureCurrent(int timeout)
{
throw new NotImplementedException();
/*
if (_lastType != MeasurementFunction.DCVolts && _lastType != MeasurementFunction.ACVolts)
{
throw new Exception("only ac or dc volt is acceptable for param type: " + type.ToString());
}
return Current.FromAmps(ReadCurrent();*/
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public Frequency MeasureFrequency(int timeout)
{
if (_lastType != MeasurementFunction.Frequency)
{
throw new Exception("only frequency is acceptable for param type: " + _lastType.ToString());
}
double frequency = 0.0;
_dmm.Function = VTEXDmmFunctionEnum.VTEXDmmFunctionFreq;
_dmm.Range = _lastRange;
_dmm.Resolution = _lastResolution;
_dmm.Measurement.Read(_READ_TIMEOUT, ref frequency);
return Frequency.FromHertz(frequency);
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public Resistance MeasureResistance(int timeout)
{
if (_lastType != MeasurementFunction.FourWireResistance && _lastType != MeasurementFunction.TwoWireResistance)
{
throw new Exception("only FourWireResistance or TwoWireResistance is acceptable for param type: " + _lastType.ToString());
}
if (_lastType == MeasurementFunction.FourWireResistance)
{
_dmm.Function = VTEXDmmFunctionEnum.VTEXDmmFunction4WireRes;
}
else
{
_dmm.Function = VTEXDmmFunctionEnum.VTEXDmmFunction2WireRes;
}
double resistance = 0.0;
_dmm.Range = _lastRange;
_dmm.Resolution = _lastResolution;
_dmm.Measurement.Read(_READ_TIMEOUT, ref resistance);
if (double.IsNaN(resistance))
{
resistance = double.MaxValue;
}
return Resistance.FromOhms(resistance);
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public Voltage MeasureVoltage(int timeout)
{
if (_lastType != MeasurementFunction.DCVolts && _lastType != MeasurementFunction.ACVolts)
{
throw new Exception("only ac or dc volt is acceptable for param type: " + _lastType.ToString());
}
if (_lastType == MeasurementFunction.ACVolts)
{
_dmm.Function = VTEXDmmFunctionEnum.VTEXDmmFunctionACVolts;
}
else
{
_dmm.Function = VTEXDmmFunctionEnum.VTEXDmmFunctionDCVolts;
}
double dcVoltage = 0.0;
_dmm.Measurement.Read(_READ_TIMEOUT, ref dcVoltage);
if (double.IsNaN(dcVoltage))
{
dcVoltage = double.MaxValue;
}
return Voltage.FromVolts(dcVoltage);
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
int testResult = 0;
string result = "";
_dmm.Utility.SelfTest(ref testResult, ref result);
// Set measurement input to backplane after performing self test. Default is front panel.
_dmm.Measurement.Input = VTEXDmmInputSelectEnum.VTEXDmmInputSelectInternal;
if (testResult > 0)
{
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
throw new Exception("self test failed with an Error Code: " + testResult + " and Error Message: " + result);
}
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
return _selfTestResult;
}
/// <summary>
///
/// </summary>
public void Reset()
{
_dmm.Utility.Reset();
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
_dmm.Utility.Reset();
_dmm.Close();
_state = State.Uninitialized;
}
}
#endregion
}
}

View File

@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
<AssemblyName>Raytheon.Instruments.DMMVTI</AssemblyName>
<Product>DMM VTI implementation</Product>
<Description>DMM VTI 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.Dmm.Contracts" Version="2.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DMMSim\DMMSim.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Ivi.Dmm.Interop">
<HintPath>..\..\Common\COTS\VTI\Ivi.Dmm.Interop.dll</HintPath>
</Reference>
<Reference Include="Ivi.Driver.Interop">
<HintPath>..\..\Common\COTS\VTI\Ivi.Driver.Interop.dll</HintPath>
</Reference>
<Reference Include="VTI.VTEXDmm.Interop">
<HintPath>..\..\Common\COTS\VTI\VTI.VTEXDmm.Interop.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,140 @@
// **********************************************************************************************************
// DMMVTIFactory.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 = "DMMVTIFactory")]
public class DMMVTIFactory : 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 DMMVTIFactory(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 DMMVTIFactory([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(IDmm));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new DMMVTI(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 DMMSim(name, _configurationManager, _logger);
else
return new DMMVTI(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);
}
}
}