// 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 { /// /// A VTI Dmm /// 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; /// /// NLog logger /// private readonly ILogger _logger; /// /// Raytheon configuration /// private readonly IConfigurationManager _configurationManager; private readonly IConfiguration _configuration; #endregion #region PrivateFunctions /// /// Dispose of this object /// /// True = currently disposing, False = not disposing. 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 /// /// DMMVTI factory constructor /// /// /// 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; } /// /// The constructor which opens the handle to the DMM instrument. /// /// The address of the DMM. /// The options used for setting up the instrument. 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; } /// /// The Finalizer. /// ~DMMVTI() { Dispose(false); } /// /// /// /// public bool ClearErrors() { throw new NotImplementedException(); } /// /// /// /// /// /// public void ConfigureCurrentMeasurement(MeasurementFunction type, Current range, Current resolution) { throw new NotImplementedException(); /*_lastType = type; _lastRange = range.Amps; _lastResolution = resolution.Amps;*/ } /// /// /// /// /// /// 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; } /// /// /// /// /// /// 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; } /// /// /// /// /// /// 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; } /// /// Dispose of this objects resources /// 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 } } } /// /// /// public string DetailedStatus { get { return "This is a VTI Dmm"; } } /// /// /// public bool DisplayEnabled { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } /// /// /// public bool FrontPanelEnabled { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } /// /// /// public InstrumentMetadata Info { get { throw new NotSupportedException(); } } /// /// /// 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()); } } /// /// /// public MeasurementFunction MeasurementType { get { throw new NotSupportedException(); } } /// /// /// /// /// 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();*/ } /// /// /// /// /// 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); } /// /// /// /// /// 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); } /// /// /// /// /// 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); } /// /// /// public string Name { get { return _name; } set { _name = value; } } /// /// /// /// 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; } /// /// /// public void Reset() { _dmm.Utility.Reset(); } /// /// /// public SelfTestResult SelfTestResult { get { return _selfTestResult; } } /// /// /// public State Status { get { return _state; } } /// /// /// public void Shutdown() { if (_state == State.Ready) { _dmm.Utility.Reset(); _dmm.Close(); _state = State.Uninitialized; } } #endregion } }