Big changes
This commit is contained in:
@@ -0,0 +1,641 @@
|
||||
// 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 Raytheon.Instruments;
|
||||
using System;
|
||||
using Raytheon.Instruments.Dmm;
|
||||
using Raytheon.Units;
|
||||
using Agilent.AgM918x.Interop;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A keysight implementation of the DMM interface
|
||||
/// </summary>
|
||||
public class DMMKeysightM9183 : IDmm
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
|
||||
private AgM918x _dmm;
|
||||
private string _name;
|
||||
private readonly string _address;
|
||||
private readonly string _options;
|
||||
private MeasurementFunction _lastType;
|
||||
private double _lastRange;
|
||||
private double _lastResolution;
|
||||
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;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this objects resources
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_34461A")]
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="range"></param>
|
||||
/// <param name="resolution"></param>
|
||||
/// <param name="currentType"></param>
|
||||
/// <returns></returns>
|
||||
private double ReadCurrent(double range, double resolution, MeasurementFunction currentType)
|
||||
{
|
||||
bool shallWeUseAutoRange = false;
|
||||
|
||||
if (range < 0)
|
||||
{
|
||||
shallWeUseAutoRange = true;
|
||||
// set the starting range for auto range to 2 micro amps
|
||||
range = 0.000002;
|
||||
}
|
||||
|
||||
if (currentType == MeasurementFunction.ACCurrent)
|
||||
{
|
||||
return _dmm.ACCurrent.Measure(range, resolution, shallWeUseAutoRange);
|
||||
}
|
||||
else if (currentType == MeasurementFunction.DCCurrent)
|
||||
{
|
||||
return _dmm.DCCurrent.Measure(range, resolution, shallWeUseAutoRange);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("only ac or dc current is acceptable for param type: " + currentType.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads frequency from the dmm
|
||||
/// </summary>
|
||||
/// <param name="range">The range to use on the DMM</param>
|
||||
/// <param name="resolution">The resolution to use on the DMM</param>
|
||||
/// <param name="voltRange">The voltage range for the measurement</param>
|
||||
/// <param name="numReads">The number of reads to make</param>
|
||||
/// <returns>The frequency or average of frequencies read</returns>
|
||||
private double ReadFrequency(double range, double resolution, double voltRange, double numReads)
|
||||
{
|
||||
bool shallWeUseAutoRange = false;
|
||||
|
||||
if (range < 0)
|
||||
{
|
||||
shallWeUseAutoRange = true;
|
||||
// set the starting range for auto range to 10
|
||||
range = 10;
|
||||
}
|
||||
|
||||
return _dmm.Frequency.Measure(range, shallWeUseAutoRange, voltRange);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads resistance
|
||||
/// </summary>
|
||||
/// <param name="range">The range to use on the DMM</param>
|
||||
/// <param name="resolution">The resolution to use on the DMM</param>\
|
||||
/// <param name="dmmResistanceType"></param>
|
||||
/// <returns>The resistance</returns>
|
||||
private double ReadResistance(double range, double resolution, MeasurementFunction resistanceType)
|
||||
{
|
||||
bool shallWeUseAutoRange = false;
|
||||
|
||||
if (range < 0)
|
||||
{
|
||||
shallWeUseAutoRange = true;
|
||||
// set the starting range for auto range to 10
|
||||
range = 10;
|
||||
}
|
||||
|
||||
if (resistanceType == MeasurementFunction.FourWireResistance)
|
||||
{
|
||||
return _dmm.Resistance4Wire.Measure(range, resolution, shallWeUseAutoRange);
|
||||
}
|
||||
else if (resistanceType == MeasurementFunction.TwoWireResistance)
|
||||
{
|
||||
return _dmm.Resistance.Measure(range, resolution, shallWeUseAutoRange);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("only 4 or 2 write resistance is acceptable for param type: " + resistanceType.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads voltage
|
||||
/// </summary>
|
||||
/// <param name="range">The range to use on the DMM</param>
|
||||
/// <param name="resolution">The resolution to use on the DMM</param>
|
||||
/// <returns></returns>
|
||||
private double ReadVoltage(double range, double resolution, MeasurementFunction voltageType)
|
||||
{
|
||||
bool shallWeUseAutoRange = false;
|
||||
|
||||
if (range < 0)
|
||||
{
|
||||
shallWeUseAutoRange = true;
|
||||
// set the starting range for auto range to 10
|
||||
range = 10;
|
||||
}
|
||||
|
||||
if (voltageType == MeasurementFunction.ACVolts)
|
||||
{
|
||||
return _dmm.ACVoltage.Measure(range, resolution, shallWeUseAutoRange);
|
||||
}
|
||||
else if (voltageType == MeasurementFunction.DCVolts)
|
||||
{
|
||||
return _dmm.DCVoltage.Measure(range, resolution, shallWeUseAutoRange);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("only ac or dc volt is acceptable for param type: " + voltageType.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert scpi data to string
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private string ConvertToString(ref byte[] data)
|
||||
{
|
||||
string rsp = System.Text.Encoding.ASCII.GetString(data);
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="numbers"></param>
|
||||
/// <returns></returns>
|
||||
private double GetFrequencyAvg(string numbers)
|
||||
{
|
||||
string[] numArr = numbers.Split(',');
|
||||
double retVal = 0;
|
||||
|
||||
foreach (string val in numArr)
|
||||
{
|
||||
retVal += Util.ConvertStringToDouble(val);
|
||||
}
|
||||
|
||||
retVal = retVal / numArr.Length;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// DMMKeysightM9183 factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public DMMKeysightM9183(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_address = _configuration.GetConfigurationValue("DMMKeysightM9183", "Address", "");
|
||||
_options = _configuration.GetConfigurationValue("DMMKeysightM9183", "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 and performs a self test on the instrument
|
||||
/// </summary>
|
||||
/// <param name="name">The name of this dmm</param>
|
||||
/// <param name="address">The address of the DMM</param>
|
||||
public DMMKeysightM9183(string name, string address, string options)
|
||||
{
|
||||
_name = name;
|
||||
_address = address;
|
||||
_options = options.Trim();
|
||||
_lastType = 0;
|
||||
_lastRange = 0;
|
||||
_lastResolution = 0;
|
||||
|
||||
//created in Initialize()
|
||||
_dmm = null;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer which will release resources if required
|
||||
/// </summary>
|
||||
~DMMKeysightM9183()
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (type != MeasurementFunction.ACCurrent && type != MeasurementFunction.DCCurrent)
|
||||
{
|
||||
throw new Exception("only AC or DC Current types are acceptable for param type: " + _lastType.ToString());
|
||||
}
|
||||
|
||||
_lastType = type;
|
||||
_lastRange = range.Amps;
|
||||
_lastResolution = resolution.Amps;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
///
|
||||
/// </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 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>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Keysight Dmm";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_dmm = new AgM918x();
|
||||
|
||||
if (_options != "" && _options.ToUpper() != "NONE")
|
||||
{
|
||||
_dmm.Initialize(_address, false, true, _options);
|
||||
}
|
||||
else
|
||||
{
|
||||
_dmm.Initialize(_address, false, true);
|
||||
}
|
||||
|
||||
//_selfTestResult = PerformSelfTest();
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MeasurementFunction MeasurementType
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public Current MeasureCurrent(int timeout)
|
||||
{
|
||||
if (_lastType != MeasurementFunction.DCCurrent && _lastType != MeasurementFunction.ACCurrent)
|
||||
{
|
||||
throw new Exception("only DC or AC Current is acceptable for param type: " + _lastType.ToString());
|
||||
}
|
||||
|
||||
return Current.FromAmps(ReadCurrent(_lastRange, _lastResolution, _lastType));
|
||||
}
|
||||
|
||||
/// <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());
|
||||
}
|
||||
|
||||
return Frequency.FromHertz(ReadFrequency(_lastRange, _lastResolution, _lastRange, 1));
|
||||
}
|
||||
|
||||
/// <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());
|
||||
}
|
||||
|
||||
return Resistance.FromOhms(ReadResistance(_lastRange, _lastResolution, _lastType));
|
||||
}
|
||||
|
||||
/// <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());
|
||||
}
|
||||
|
||||
return Voltage.FromVolts(ReadVoltage(_lastRange, _lastResolution, _lastType));
|
||||
}
|
||||
|
||||
/// <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.In = 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<AssemblyName>Raytheon.Instruments.DMMKeysightM9183</AssemblyName>
|
||||
<Product>DMM Keysight M9183 implementation</Product>
|
||||
<Description>DMM Keysight M9183 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="Agilent.AgM918x.Interop">
|
||||
<HintPath>..\..\Common\COTS\Keysight\Agilent.AgM918x.Interop.dll</HintPath>
|
||||
</Reference>
|
||||
<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>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,140 @@
|
||||
// **********************************************************************************************************
|
||||
// DMMKeysightM9183Factory.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 = "DMMKeysightM9183Factory")]
|
||||
public class DMMKeysightM9183Factory : 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 DMMKeysightM9183Factory(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 DMMKeysightM9183Factory([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 DMMKeysightM9183(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 DMMKeysightM9183(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,785 @@
|
||||
// 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 Raytheon.Instruments;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Raytheon.Instruments.Dmm;
|
||||
using Raytheon.Units;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A keysight implementation of the DMM interface
|
||||
/// </summary>
|
||||
public class DMMKeysightScpi : IDmm
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
|
||||
private const string READ_ERROR_STATUS_CMD = "SYST:ERR?";
|
||||
private const string _SELFTESTCMD = "*TST?";
|
||||
private const string _RESETCMD = "*RST";
|
||||
private const string _MEASUREFRES = "MEAS:FRES? "; //Resistance 4-wire
|
||||
private const string _MEASURERES = "MEAS:RES? "; //Resistance 2-wire
|
||||
private const string _MEASUREDCVOLT = "MEAS:VOLT:DC? ";
|
||||
private const string _MEASUREACVOLT = "MEAS:VOLT:AC? ";
|
||||
|
||||
//Frequency
|
||||
private const string _FREQ_SETUP1 = "CONF:FREQ ";
|
||||
private const string _FREQ_SETUP2 = "SENS:FREQ:VOLT:RANGE:AUTO OFF";
|
||||
private const string _FREQ_SETUP3 = "FREQ:VOLT:RANG ";
|
||||
private const string _FREQ_SETUP4 = "SAMPLE:COUNT ";
|
||||
private const string _MEASUREFREQ = "READ? ";
|
||||
|
||||
private const string _AUTO = "AUTO";
|
||||
private const string _DEFAULT = "DEF";
|
||||
|
||||
private const int _PORT = 5025;
|
||||
private const int _READ_TIMEOUT = 5000;
|
||||
private byte[] _readBuffer;
|
||||
private NetworkStream _tcpStream;
|
||||
private string _name;
|
||||
private readonly string _address;
|
||||
private MeasurementFunction _lastType;
|
||||
private double _lastRange;
|
||||
private double _lastResolution;
|
||||
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;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this objects resources
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_34461A")]
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
Reset();
|
||||
|
||||
_tcpStream.Dispose();
|
||||
|
||||
_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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads frequency from the dmm
|
||||
/// </summary>
|
||||
/// <param name="range">The range to use on the DMM</param>
|
||||
/// <param name="resolution">The resolution to use on the DMM</param>
|
||||
/// <param name="voltRange">The voltage range for the measurement</param>
|
||||
/// <param name="numReads">The number of reads to make</param>
|
||||
/// <returns>The frequency or average of frequencies read</returns>
|
||||
private double ReadFrequency(double range, double resolution, double voltRange, double numReads)
|
||||
{
|
||||
//Setup the frequency measurement
|
||||
string command = _FREQ_SETUP1;
|
||||
|
||||
if (range == -1)
|
||||
{
|
||||
command += _DEFAULT + ", " + _DEFAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
command += range + ", " + resolution;
|
||||
}
|
||||
|
||||
command += ";:" + _FREQ_SETUP2 + ";:" + _FREQ_SETUP3 + voltRange;
|
||||
|
||||
//want to read frequency more than once
|
||||
if (numReads > 1)
|
||||
{
|
||||
command += ";:" + _FREQ_SETUP4 + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
command += "\n";
|
||||
}
|
||||
|
||||
// send the command
|
||||
IOWrite(command);
|
||||
|
||||
//read the frequency
|
||||
command = _MEASUREFREQ + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
double frequency = 0.0;
|
||||
|
||||
if (rspStr.IndexOf(',') > -1)
|
||||
{
|
||||
frequency = GetFrequencyAvg(rspStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
frequency = Util.ConvertStringToDouble(rspStr);
|
||||
}
|
||||
|
||||
return frequency;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads resistance
|
||||
/// </summary>
|
||||
/// <param name="range">The range to use on the DMM</param>
|
||||
/// <param name="resolution">The resolution to use on the DMM</param>\
|
||||
/// <param name="dmmResistanceType"></param>
|
||||
/// <returns>The resistance</returns>
|
||||
private double ReadResistance(double range, double resolution, MeasurementFunction resistanceType)
|
||||
{
|
||||
string command = "";
|
||||
|
||||
if (resistanceType == MeasurementFunction.FourWireResistance)
|
||||
{
|
||||
command = _MEASUREFRES;
|
||||
}
|
||||
else if (resistanceType == MeasurementFunction.TwoWireResistance)
|
||||
{
|
||||
command = _MEASURERES;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("only 4 or 2 write resistance is acceptable for param type: " + resistanceType.ToString());
|
||||
}
|
||||
|
||||
if (range == -1)
|
||||
{
|
||||
command += _AUTO + ", " + _DEFAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
command += range + ", " + resolution;
|
||||
}
|
||||
|
||||
command += "\n";
|
||||
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
double resistance = Util.ConvertStringToDouble(rspStr);
|
||||
|
||||
return resistance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads voltage
|
||||
/// </summary>
|
||||
/// <param name="range">The range to use on the DMM</param>
|
||||
/// <param name="resolution">The resolution to use on the DMM</param>
|
||||
/// <returns></returns>
|
||||
private double ReadVoltage(double range, double resolution, MeasurementFunction voltageType)
|
||||
{
|
||||
string command = "";
|
||||
|
||||
if (voltageType == MeasurementFunction.ACVolts)
|
||||
{
|
||||
command = _MEASUREACVOLT;
|
||||
}
|
||||
else if (voltageType == MeasurementFunction.DCVolts)
|
||||
{
|
||||
command = _MEASUREDCVOLT;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("only ac or dc volt is acceptable for param type: " + voltageType.ToString());
|
||||
}
|
||||
|
||||
if (range == -1)
|
||||
{
|
||||
command += _AUTO + ", " + _DEFAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
command += range + ", " + resolution;
|
||||
}
|
||||
|
||||
command += "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
double dcVoltage = Util.ConvertStringToDouble(rspStr);
|
||||
return dcVoltage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert scpi data to string
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private string ConvertToString(ref byte[] data)
|
||||
{
|
||||
string rsp = System.Text.Encoding.ASCII.GetString(data);
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="numbers"></param>
|
||||
/// <returns></returns>
|
||||
private double GetFrequencyAvg(string numbers)
|
||||
{
|
||||
string[] numArr = numbers.Split(',');
|
||||
double retVal = 0;
|
||||
|
||||
foreach (string val in numArr)
|
||||
{
|
||||
retVal += Util.ConvertStringToDouble(val);
|
||||
}
|
||||
|
||||
retVal = retVal / numArr.Length;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the error code.
|
||||
/// </summary>
|
||||
/// <returns>The error code (number).</returns>
|
||||
private int GetErrorCode()
|
||||
{
|
||||
// not calling IOQuery() here so IOQuery() can call GetErrorCode() after each query
|
||||
|
||||
string command = READ_ERROR_STATUS_CMD + "\n";
|
||||
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(command);
|
||||
|
||||
// send the data out
|
||||
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// read the response
|
||||
int numBytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// convert to a string
|
||||
string rspStr = ConvertToString(ref _readBuffer);
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split(',');
|
||||
|
||||
int ret = Util.ConvertStringToInt32(tokens[0]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a command to the DMM and get the response
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to send</param>
|
||||
/// <returns>The DMM response</returns>
|
||||
private string IOQuery(string commandString)
|
||||
{
|
||||
// send the command
|
||||
IOWrite(commandString, false);
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// read from the response
|
||||
int numBytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
if (numBytesRead == 0)
|
||||
{
|
||||
throw new Exception($"DMMKeysightScpi:IOQuery() - Number of bytes read from stream was {numBytesRead}");
|
||||
}
|
||||
|
||||
// convert response to a string
|
||||
string rspStr = ConvertToString(ref _readBuffer);
|
||||
|
||||
// check for errors
|
||||
int err = GetErrorCode();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception("DMMKeysightScpi:IOQuery() - returned error code: " + err.ToString());
|
||||
}
|
||||
|
||||
return rspStr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a SCPI Command to the instrument.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The SCPI Command to be sent to the instrument.</param>
|
||||
private void IOWrite(string commandString, bool checkForError = true)
|
||||
{
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(commandString);
|
||||
|
||||
// send the data out
|
||||
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
|
||||
|
||||
if (checkForError)
|
||||
{
|
||||
// check for errors
|
||||
int err = GetErrorCode();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception("DMMKeysightScpi:IOWrite() - returned error code: " + err.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// DMMKeysightScpi factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public DMMKeysightScpi(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_address = _configuration.GetConfigurationValue("DMMKeysightScpi", "Address", "");
|
||||
|
||||
_lastType = 0;
|
||||
_lastRange = 0;
|
||||
_lastResolution = 0;
|
||||
|
||||
const int READ_BUFFER_SIZE = 512;
|
||||
_readBuffer = new byte[READ_BUFFER_SIZE];
|
||||
|
||||
// created in initialize
|
||||
_tcpStream = null;
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor which opens the handle to the DMM and performs a self test on the instrument
|
||||
/// </summary>
|
||||
/// <param name="name">The name of this dmm</param>
|
||||
/// <param name="address">The address of the DMM</param>
|
||||
public DMMKeysightScpi(string name, string address)
|
||||
{
|
||||
const int READ_BUFFER_SIZE = 512;
|
||||
|
||||
_name = name;
|
||||
_address = address;
|
||||
_lastType = 0;
|
||||
_lastRange = 0;
|
||||
_lastResolution = 0;
|
||||
|
||||
_readBuffer = new byte[READ_BUFFER_SIZE];
|
||||
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
// created in initialize
|
||||
_tcpStream = null;
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer which will release resources if required
|
||||
/// </summary>
|
||||
~DMMKeysightScpi()
|
||||
{
|
||||
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 Keysight Dmm";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
TcpClient dmmSocketConn = new TcpClient(_address, _PORT);
|
||||
_tcpStream = dmmSocketConn.GetStream();
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
_selfTestResult = PerformSelfTest();
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MeasurementFunction MeasurementType
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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());
|
||||
}
|
||||
|
||||
return Frequency.FromHertz(ReadFrequency(_lastRange, _lastResolution, _lastRange, 1));
|
||||
}
|
||||
|
||||
/// <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());
|
||||
}
|
||||
|
||||
return Resistance.FromOhms(ReadResistance(_lastRange, _lastResolution, _lastType));
|
||||
}
|
||||
|
||||
/// <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());
|
||||
}
|
||||
|
||||
return Voltage.FromVolts(ReadVoltage(_lastRange, _lastResolution, _lastType));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
// change the timeout to account for the long self test
|
||||
_tcpStream.ReadTimeout = 30000;
|
||||
|
||||
// send the command and get the response
|
||||
string command = _SELFTESTCMD + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
int rsp = Util.ConvertStringToInt32(tokens[0].Replace("+", "").Split(',')[0]);
|
||||
|
||||
|
||||
if (rsp != 0)
|
||||
{
|
||||
string errorMsg = "returned an error: " + rspStr;
|
||||
_selfTestResult = SelfTestResult.Fail;
|
||||
throw new Exception(errorMsg);
|
||||
}
|
||||
_selfTestResult = SelfTestResult.Pass;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// restore the timeout
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
}
|
||||
|
||||
return SelfTestResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
IOWrite(_RESETCMD + "\n");
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
Reset();
|
||||
|
||||
_tcpStream.Dispose();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.DMMKeysightScpi</AssemblyName>
|
||||
<Product>DMM Keysight Scpi implementation</Product>
|
||||
<Description>DMM Keysight Scpi 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>
|
||||
|
||||
<!-- 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 @@
|
||||
// **********************************************************************************************************
|
||||
// DMMKeysightScpiFactory.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 = "DMMKeysightScpiFactory")]
|
||||
public class DMMKeysightScpiFactory : 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 DMMKeysightScpiFactory(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 DMMKeysightScpiFactory([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 DMMKeysightScpi(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 DMMKeysightScpi(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
560
Source/TSRealLib/HAL/Implementations/DMM/DMMNiPxi/DMMNiPxi.cs
Normal file
560
Source/TSRealLib/HAL/Implementations/DMM/DMMNiPxi/DMMNiPxi.cs
Normal file
@@ -0,0 +1,560 @@
|
||||
// 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 NationalInstruments.ModularInstruments.NIDmm;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using Raytheon.Instruments.Dmm;
|
||||
using Raytheon.Units;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A simulation implementation of the DMM interface.
|
||||
/// This class basically just absorbs function calls and returns dummy data.
|
||||
/// </summary>
|
||||
public class DMMNiPxi : IDmm, IDisposable
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
|
||||
private NIDmm _niDmm;
|
||||
private string _name;
|
||||
private readonly string _address;
|
||||
//private readonly string _options;
|
||||
private double _lastRange;
|
||||
private double _lastResolution;
|
||||
private MeasurementFunction _lastType;
|
||||
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;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer.
|
||||
/// </summary>
|
||||
~DMMNiPxi()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
_niDmm.DriverUtility.Reset();
|
||||
|
||||
_niDmm.Close();
|
||||
|
||||
_niDmm.Dispose();
|
||||
|
||||
_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>
|
||||
/// DMMNiPxi factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public DMMNiPxi(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_address = _configuration.GetConfigurationValue("DMMNiPxi", "Address", "");
|
||||
//_options = _configuration.GetConfigurationValue("DMMNiPxi", "Options", "");
|
||||
|
||||
_lastType = 0;
|
||||
_lastRange = 0;
|
||||
_lastResolution = 0;
|
||||
|
||||
//created in Initialize()
|
||||
_niDmm = null;
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="options"></param>
|
||||
public DMMNiPxi(string name, string address)//, string options)
|
||||
{
|
||||
_name = name;
|
||||
_address = address;
|
||||
//_options = options;
|
||||
_lastType = 0;
|
||||
_lastRange = 0;
|
||||
_lastResolution = 0;
|
||||
|
||||
// set in Initialize()
|
||||
_niDmm = null;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <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 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>
|
||||
///
|
||||
/// </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 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>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a NI Dmm";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </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 bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_niDmm = new NIDmm(_address, false, true);// _options);
|
||||
_selfTestResult = PerformSelfTest();
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MeasurementFunction MeasurementType
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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());
|
||||
}
|
||||
|
||||
DmmAuto auto = DmmAuto.Off;
|
||||
|
||||
if (_lastRange < 0)
|
||||
{
|
||||
auto = DmmAuto.On;
|
||||
// set the starting range for auto range to 10
|
||||
_lastRange = 10;
|
||||
}
|
||||
|
||||
_niDmm.MeasurementFunction = DmmMeasurementFunction.Frequency;
|
||||
|
||||
_niDmm.Range = _lastRange;
|
||||
|
||||
_niDmm.Resolution = _lastResolution;
|
||||
|
||||
_niDmm.AutoRange = auto;
|
||||
|
||||
double frequency = _niDmm.Measurement.Read();
|
||||
|
||||
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)
|
||||
{
|
||||
_niDmm.MeasurementFunction = DmmMeasurementFunction.FourWireResistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
_niDmm.MeasurementFunction = DmmMeasurementFunction.TwoWireResistance;
|
||||
}
|
||||
|
||||
DmmAuto auto = DmmAuto.Off;
|
||||
|
||||
if (_lastRange < 0)
|
||||
{
|
||||
auto = DmmAuto.On;
|
||||
// set the starting range for auto range to 10
|
||||
_lastRange = 10;
|
||||
}
|
||||
|
||||
_niDmm.Range = _lastRange;
|
||||
|
||||
_niDmm.Resolution = _lastResolution;
|
||||
|
||||
_niDmm.AutoRange = auto;
|
||||
|
||||
double resistance = _niDmm.Measurement.Read();
|
||||
|
||||
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)
|
||||
{
|
||||
_niDmm.MeasurementFunction = DmmMeasurementFunction.ACVolts;
|
||||
}
|
||||
else
|
||||
{
|
||||
_niDmm.MeasurementFunction = DmmMeasurementFunction.DCVolts;
|
||||
}
|
||||
|
||||
DmmAuto auto = DmmAuto.Off;
|
||||
|
||||
if (_lastRange < 0)
|
||||
{
|
||||
auto = DmmAuto.On;
|
||||
// set the starting range for auto range to 10
|
||||
_lastRange = 10;
|
||||
}
|
||||
|
||||
_niDmm.Range = _lastRange;
|
||||
|
||||
_niDmm.Resolution = _lastResolution;
|
||||
|
||||
_niDmm.AutoRange = auto;
|
||||
|
||||
double volts = _niDmm.Measurement.Read();
|
||||
|
||||
if (double.IsNaN(volts))
|
||||
{
|
||||
volts = double.MaxValue;
|
||||
}
|
||||
|
||||
return Voltage.FromVolts(volts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
DmmSelfTestResult res = _niDmm.DriverUtility.SelfTest();
|
||||
|
||||
if (res.Code != 0)
|
||||
{
|
||||
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
|
||||
throw new Exception("self test returned: " + res.Code + "," + res.Message + " on card " + _name);
|
||||
}
|
||||
|
||||
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
|
||||
return _selfTestResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
_niDmm.DriverUtility.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)
|
||||
{
|
||||
_niDmm.DriverUtility.Reset();
|
||||
|
||||
_niDmm.Close();
|
||||
|
||||
_niDmm.Dispose();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.DMMNiPxi</AssemblyName>
|
||||
<Product>DMM NI Pxi implementation</Product>
|
||||
<Description>DMM NI Pxi 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="NationalInstruments.ModularInstruments.NIDmm.Fx45">
|
||||
<HintPath>..\..\Common\COTS\NI\NationalInstruments.ModularInstruments.NIDmm.Fx45.dll</HintPath>
|
||||
</Reference>
|
||||
</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 @@
|
||||
// **********************************************************************************************************
|
||||
// DMMKeysightScpiFactory.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 = "DMMNiPxiFactory")]
|
||||
public class DMMNiPxiFactory : 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 DMMNiPxiFactory(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 DMMNiPxiFactory([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 DMMNiPxi(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 DMMNiPxi(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
435
Source/TSRealLib/HAL/Implementations/DMM/DMMSim/DMMSim.cs
Normal file
435
Source/TSRealLib/HAL/Implementations/DMM/DMMSim/DMMSim.cs
Normal file
@@ -0,0 +1,435 @@
|
||||
// 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 System.Threading;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using Raytheon.Instruments.Dmm;
|
||||
using Raytheon.Units;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A simulation implementation of the DMM interface.
|
||||
/// This class basically just absorbs function calls and returns dummy data.
|
||||
/// </summary>
|
||||
public class DMMSim : IDmm
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
|
||||
private string _name;
|
||||
private double _lastRange;
|
||||
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;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer.
|
||||
/// </summary>
|
||||
~DMMSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// nothing to clean up
|
||||
}
|
||||
}
|
||||
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>
|
||||
/// DMMSim factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public DMMSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_lastRange = 0;
|
||||
|
||||
_state = State.Uninitialized;
|
||||
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public DMMSim(string name)
|
||||
{
|
||||
_name = name;
|
||||
|
||||
_lastRange = 0;
|
||||
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
_lastRange = range.Amps;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="range"></param>
|
||||
/// <param name="resolution"></param>
|
||||
public void ConfigureFrequencyMeasurement(MeasurementFunction type, Frequency range, Frequency resolution)
|
||||
{
|
||||
_lastRange = range.Hertz;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="range"></param>
|
||||
/// <param name="resolution"></param>
|
||||
public void ConfigureResistanceMeasurement(MeasurementFunction type, Resistance range, Resistance resolution)
|
||||
{
|
||||
_lastRange = range.Ohms;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="range"></param>
|
||||
/// <param name="resolution"></param>
|
||||
public void ConfigureVoltageMeasurement(MeasurementFunction type, Voltage range, Voltage resolution)
|
||||
{
|
||||
_lastRange = range.Volts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Sim Dmm";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </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 bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_selfTestResult = PerformSelfTest();
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public Current MeasureCurrent(int timeout)
|
||||
{
|
||||
double max = _lastRange;
|
||||
|
||||
double min = 1.0;
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
double dataToReturn = (seed * (max - min)) + min;
|
||||
|
||||
Thread.Sleep(200);
|
||||
|
||||
return Current.FromAmps(dataToReturn);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public Frequency MeasureFrequency(int timeout)
|
||||
{
|
||||
double max = _lastRange;
|
||||
|
||||
double min = 1.0;
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
double dataToReturn = (seed * (max - min)) + min;
|
||||
|
||||
Thread.Sleep(200);
|
||||
|
||||
return Frequency.FromHertz(dataToReturn);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public Resistance MeasureResistance(int timeout)
|
||||
{
|
||||
double max = _lastRange;
|
||||
|
||||
double min = 1.0;
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
double dataToReturn = (seed * (max - min)) + min;
|
||||
|
||||
Thread.Sleep(200);
|
||||
|
||||
return Resistance.FromOhms(dataToReturn);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public Voltage MeasureVoltage(int timeout)
|
||||
{
|
||||
double max = _lastRange;
|
||||
|
||||
double min = 1.0;
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
double dataToReturn = (seed * (max - min)) + min;
|
||||
|
||||
Thread.Sleep(200);
|
||||
|
||||
return Voltage.FromVolts(dataToReturn);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MeasurementFunction MeasurementType
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
_selfTestResult = SelfTestResult.Pass;
|
||||
return _selfTestResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selfTestResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.DMMSim</AssemblyName>
|
||||
<RootNamespace>Raytheon.Instruments</RootNamespace>
|
||||
<Product>DMM Sim implementation</Product>
|
||||
<Description>DMM Sim implementation</Description>
|
||||
<OutputType>Library</OutputType>
|
||||
|
||||
<!-- Static versioning (Suitable for Development) -->
|
||||
<!-- Disable the line below for dynamic versioning -->
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<NoWarn>NU1603</NoWarn>
|
||||
</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>
|
||||
|
||||
</Project>
|
||||
137
Source/TSRealLib/HAL/Implementations/DMM/DMMSim/DMMSimFactory.cs
Normal file
137
Source/TSRealLib/HAL/Implementations/DMM/DMMSim/DMMSimFactory.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
// **********************************************************************************************************
|
||||
// DMMSimFactory.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 = "DMMSimFactory")]
|
||||
public class DMMSimFactory : 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 DMMSimFactory(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 DMMSimFactory([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 DMMSim(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);
|
||||
|
||||
return new DMMSim(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,541 @@
|
||||
// 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 Raytheon.Instruments.Dmm;
|
||||
using Raytheon.Units;
|
||||
using System.IO.Ports;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A Space Electronics (Squib meter) of the DMM interface
|
||||
/// </summary>
|
||||
public class DMMSquibMeter101SQBRAK : IDmm, IDisposable
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
|
||||
private string _name;
|
||||
private readonly string _address;
|
||||
private readonly SerialPort _serialPort;
|
||||
private MeasurementFunction _lastType;
|
||||
private double _lastRange;
|
||||
private double _lastResolution;
|
||||
private State _state;
|
||||
private SelfTestResult _selfTestResult;
|
||||
private byte[] _readBuffer;
|
||||
private string versionInfo;
|
||||
|
||||
/// <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 objects resources
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_34461A")]
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
IOWrite("RST"); // send reset command
|
||||
IOWrite("LM"); // sets squib meter to local mode (it is set to remote in initilize)
|
||||
|
||||
_serialPort.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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private string ConvertToString(ref byte[] data)
|
||||
{
|
||||
string rsp = System.Text.Encoding.ASCII.GetString(data);
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a command to the squib meter and get the response.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to send.</param>
|
||||
/// <returns>The squib meter response as string.</returns>
|
||||
|
||||
private string IOQuery(string commandString)
|
||||
{
|
||||
// Flush squib meter buffer
|
||||
_serialPort.Write("FS");
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// send the data out
|
||||
_serialPort.Write(commandString);
|
||||
|
||||
// read from the response
|
||||
int numBytesRead = _serialPort.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// convert response to a string
|
||||
string rspStr = ConvertToString(ref _readBuffer);
|
||||
|
||||
// split out the command responce from the return data (divided by carriage return)
|
||||
string[] result = rspStr.Split(new string[] { "\n", "\r\n", "<CR>" }, StringSplitOptions.None);
|
||||
|
||||
// Check command responce (0 = OK)
|
||||
if (result[0] == "1")
|
||||
{
|
||||
throw new Exception("Unknown Command");
|
||||
}
|
||||
if (result[0] == "2")
|
||||
{
|
||||
throw new Exception("Command now allowed in present mode");
|
||||
}
|
||||
|
||||
return result[1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a serial Command to the instrument.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The serial Command to be sent to the instrument.</param>
|
||||
private void IOWrite(string commandString)
|
||||
{
|
||||
// note each command sent has different return data/status/error formatting, IOWrite is just a direct write
|
||||
// IOQuery will do a read, and return all the data
|
||||
|
||||
// send command to serial port
|
||||
_serialPort.Write(commandString);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// DMMSquibMeter101SQBRAK factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public DMMSquibMeter101SQBRAK(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
string comPortName = _configuration.GetConfigurationValue("DMMSquibMeter101SQBRAK", "ComPortName", "COM1");
|
||||
_address = comPortName;
|
||||
int baudRate = _configuration.GetConfigurationValue("DMMSquibMeter101SQBRAK", "BaudRate", 9600);
|
||||
Parity parity = _configuration.GetConfigurationValue("DMMSquibMeter101SQBRAK", "Parity", Parity.None);
|
||||
int dataBits = _configuration.GetConfigurationValue("DMMSquibMeter101SQBRAK", "DataBits", 8);
|
||||
StopBits stopBits = _configuration.GetConfigurationValue("DMMSquibMeter101SQBRAK", "StopBits", StopBits.One);
|
||||
|
||||
_serialPort = new SerialPort(comPortName, baudRate, parity, dataBits, stopBits);
|
||||
_lastType = 0;
|
||||
_lastRange = 0;
|
||||
_lastResolution = 0;
|
||||
_readBuffer = new byte[1000];
|
||||
|
||||
//created in Initialize()
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor which opens the handle to the DMM and performs a self test on the instrument
|
||||
/// </summary>
|
||||
/// <param name="name">The name of this dmm</param>
|
||||
/// <param name="address">The address of the DMM</param>
|
||||
public DMMSquibMeter101SQBRAK(string name, string comPortName, int baudRate = 9600, Parity parity = Parity.None, int dataBits = 8, StopBits stopBits = StopBits.One)
|
||||
{
|
||||
_name = name;
|
||||
_address = comPortName;
|
||||
_serialPort = new SerialPort(comPortName, baudRate, parity, dataBits, stopBits);
|
||||
_lastType = 0;
|
||||
_lastRange = 0;
|
||||
_lastResolution = 0;
|
||||
_readBuffer = new byte[1000];
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
//created in Initialize()
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer which will release resources if required
|
||||
/// </summary>
|
||||
~DMMSquibMeter101SQBRAK()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException(); // if serial command for clearing errors add here, if not leave as is
|
||||
}
|
||||
|
||||
/// <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(); // if serial command for clearing errors add here, if not leave as is
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="range"></param>
|
||||
/// <param name="resolution"></param>
|
||||
public void ConfigureFrequencyMeasurement(MeasurementFunction type, Frequency range, Frequency resolution)
|
||||
{
|
||||
throw new NotImplementedException(); // if serial command for clearing errors add here, if not leave as is
|
||||
}
|
||||
|
||||
/// <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 ConfigureVoltageMeasurement(MeasurementFunction type, Voltage range, Voltage resolution)
|
||||
{
|
||||
throw new NotImplementedException(); // if serial command for clearing errors add here, if not leave as is
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
versionInfo = IOQuery("VR");
|
||||
return "Squib Meter version Information (Cage Code | Model Number | Serial Number | Firmware Version | Calibration Date): " + versionInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
// Open the port
|
||||
_serialPort.Open();
|
||||
|
||||
// set the squib meter to remote state
|
||||
IOQuery("RM");
|
||||
|
||||
// Ensure continuous reading is off
|
||||
IOQuery("COFF");
|
||||
|
||||
// Flush FIFO buffer
|
||||
IOQuery("FS");
|
||||
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MeasurementFunction MeasurementType
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public Current MeasureCurrent(int timeout)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public Frequency MeasureFrequency(int timeout)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <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());
|
||||
}
|
||||
|
||||
IOQuery("SR"); //todo need to add in range values
|
||||
|
||||
// send serial command to send & read response
|
||||
// set range
|
||||
// set resolution
|
||||
// any other settings that need to be sent (write) before taking measurement
|
||||
|
||||
string response = IOQuery("RV");
|
||||
|
||||
// parse the response //TODO Parse the return data (0= command ok, 1= unknown command, 2= command not allowed in present mode | reading | over range state | wiring error state | calibration state (ok or bad) | hardware state (ok or bad))
|
||||
double rsp = Util.ConvertStringToDouble(response); //if string is only number this is ok, if there are any other char must strip them off
|
||||
|
||||
return Resistance.FromOhms(rsp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public Voltage MeasureVoltage(int timeout)
|
||||
{
|
||||
throw new NotImplementedException(); // if serial command for clearing errors add here, if not leave as is
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
int testResult = 0;
|
||||
const string BatteryState = "LOW";
|
||||
string result = IOQuery("RV");
|
||||
|
||||
// Set measurement input to backplane after performing self test. Default is front panel.
|
||||
// _dmm.Measurement.In = VTEXDmmInputSelectEnum.VTEXDmmInputSelectInternal;
|
||||
|
||||
if (result == BatteryState)
|
||||
{
|
||||
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
|
||||
throw new Exception("Battery state: " + testResult + " Battery State Message: " + result);
|
||||
}
|
||||
|
||||
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
|
||||
return _selfTestResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
IOWrite("RST");
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
IOWrite("RST"); // send reset command
|
||||
IOWrite("LM"); // sets squib meter to local mode (it is set to remote in initilize)
|
||||
|
||||
_serialPort.Close();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.DMMSquibMeter101SQBRAK</AssemblyName>
|
||||
<Product>DMM Squib Meter 101SQBRAK implementation</Product>
|
||||
<Description>DMM Squib Meter 101SQBRAK 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>
|
||||
|
||||
<!-- 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 @@
|
||||
// **********************************************************************************************************
|
||||
// DMMSquibMeter101SQBRAKFactory.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 = "DMMSquibMeter101SQBRAKFactory")]
|
||||
public class DMMSquibMeter101SQBRAKFactory : 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 DMMSquibMeter101SQBRAKFactory(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 DMMSquibMeter101SQBRAKFactory([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 DMMSquibMeter101SQBRAK(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 DMMSquibMeter101SQBRAK(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
533
Source/TSRealLib/HAL/Implementations/DMM/DMMVTI/DMMVTI.cs
Normal file
533
Source/TSRealLib/HAL/Implementations/DMM/DMMVTI/DMMVTI.cs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
140
Source/TSRealLib/HAL/Implementations/DMM/DMMVTI/DMMVTIFactory.cs
Normal file
140
Source/TSRealLib/HAL/Implementations/DMM/DMMVTI/DMMVTIFactory.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user