// 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.Units; namespace Raytheon.Instruments { /// /// A simulated eload /// public class EloadSim : IEload { #region PrivateClassMembers private readonly double _overCurrentProtection; private readonly double _overVoltageProtection; private double _setpointVal; private double _ini_setpointval; private double _voltage; private readonly int _channelNumber; private bool _isOn; private EloadModuleMode _mode; private EloadModuleMode _originalMode; private readonly ILogger _logger; private readonly IConfigurationManager _configurationManager; private readonly IConfiguration _configuration; public string DetailedStatus { get; protected set; } public bool DisplayEnabled { get; set; } public bool FrontPanelEnabled { get; set; } public InstrumentMetadata Info { get; set; } public string Name { get; protected set; } public SelfTestResult SelfTestResult => PerformSelfTest(); public State Status { get; set; } #endregion #region PublicFuctions /// /// FlowMeterOmegaDPF20 factory constructor /// /// /// public EloadSim(string deviceName, IConfigurationManager configurationManager) { const double SETPOINT_VOLTAGE = 28.0; Name = deviceName; _logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}"); _configurationManager = configurationManager; _configuration = _configurationManager.GetConfiguration(Name); _channelNumber = _configuration.GetConfigurationValue("EloadSim", "ChannelNumber", 0); _mode = _configuration.GetConfigurationValue("EloadSim", "Mode", EloadModuleMode.CURRENT); _setpointVal = _configuration.GetConfigurationValue("EloadSim", "SetpointVal", 0.0); _ini_setpointval = _configuration.GetConfigurationValue("EloadSim", "IniSetpointVal", 0.0); _overCurrentProtection = _configuration.GetConfigurationValue("EloadSim", "OverCurrentProtection", 0.0); _overVoltageProtection = _configuration.GetConfigurationValue("EloadSim", "OverVoltageProtection", 0.0); _voltage = SETPOINT_VOLTAGE; _originalMode = _mode; // make sure it is off Disable(); } /// /// The constructor for an Eload (Simulation). /// /// The channel number for the Eload. /// The operation mode of the channel. Modes: Resistance, Voltage, Current. /// The operation point of the load. This can be a voltage, current, or resistance. /// Overcurrent setpoint that will turn off the channel if exceeded. /// Overvoltage setpoint that will turn off channel if exceeded (double check). public EloadSim(int channelNumber, EloadModuleMode mode, double setpointVal, double overCurrentProtection, double overVoltageProtection) { const double SETPOINT_VOLTAGE = 28.0; _logger = LogManager.GetCurrentClassLogger(); _channelNumber = channelNumber; _setpointVal = setpointVal; _ini_setpointval = setpointVal; _overCurrentProtection = overCurrentProtection; _overVoltageProtection = overVoltageProtection; _voltage = SETPOINT_VOLTAGE; _mode = mode; _originalMode = mode; Disable(); } /// /// The finalizer. /// ~EloadSim() { Dispose(false); } /// /// Dispose of this object's resources. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Send a SCPI Command to the instrument and get a response. /// /// The command to send. /// THe instrument response. public string IOQuery(string commandString) { // just to provide a small delay 10ms for the sim Thread.Sleep(10); return "IOQuery Sim Response"; } /// /// Send a SCPI Command to the instrument. /// /// The command to be send. public void IOWrite(string commandString) { // just to provide a small delay 10ms for the sim Thread.Sleep(10); } /// /// Query if the Eload input is on (simulated). /// /// Status of Eload (simulated). True = On, False = Off. public bool IsInputOn() { return _isOn; } /// /// Turns the Eload off (simulated). /// public void Enable() { _isOn = false; } /// /// Turns the Eload on (simulated). /// public void Disable() { _isOn = true; } /// /// Reads the current of the Eload. /// /// The current (simulated). public Current ReadCurrent() { const double MIN_CURRENT = 1.0; // just to provide a small delay 10ms for the sim Thread.Sleep(10); double currentToReturn = 0.0; if (_isOn) { double maxCurrent = _overCurrentProtection; Random rnd = new Random(); double seed = rnd.NextDouble(); currentToReturn = (seed * (maxCurrent - MIN_CURRENT)) + MIN_CURRENT; } return Current.FromAmps(currentToReturn); } /// /// Reads the mode of the Eload. /// /// The mode (simulated). public EloadModuleMode ReadMode() { return _mode; } /// /// Reads the overcurrent setting from an Eload. /// /// Overcurrent setting (simulated). public Current ReadOverCurrentProtection() { // just to provide a small delay 10ms for the sim Thread.Sleep(10); return Current.FromAmps(_overCurrentProtection); } /// /// Reads the overvoltage setting from an Eload. /// /// Overvoltage setting (simulated). public Voltage ReadOverVoltageProtection() { // just to provide a small delay 10ms for the sim Thread.Sleep(10); return Voltage.FromVolts(_overVoltageProtection); } /// /// Reads the resistance of the Eload. /// /// The resistance (simulated). public Resistance ReadResistance() { // just to provide a small delay 10ms for the sim Thread.Sleep(10); double resistanceToReturn = 0.0; if (_isOn) { double maxCurrent = _setpointVal + 1; double minCurrent = _setpointVal - 1; Random rnd = new Random(); double seed = rnd.NextDouble(); resistanceToReturn = (seed * (maxCurrent - minCurrent)) + minCurrent; } return Resistance.FromOhms(resistanceToReturn); } /// /// Reads the setpoint of the Eload. /// /// The setpoint (simulated). public double ReadSetpoint() { return _setpointVal; } /// /// Reads the voltage of the Eload. /// /// The voltage (simulated). public Voltage ReadVoltage() { // just to provide a small delay 10ms for the sim Thread.Sleep(10); double voltageToReturn = 0.0; if (_isOn) { double maxVoltage = _voltage + 1; double minVoltage = _voltage - 1; Random rnd = new Random(); double seed = rnd.NextDouble(); voltageToReturn = (seed * (maxVoltage - minVoltage)) + minVoltage; } return Voltage.FromVolts(voltageToReturn); } /// /// Reads the protection status from an Eload. /// /// Protection status (simulated). public ushort ReadProtectionStatus() { // just to provide a small delay 10ms for the sim Thread.Sleep(10); // The sim never triggers the protection status return 0; } /// /// Sets Initial Settings /// public void SetInitialSetting() { _mode = _originalMode; _setpointVal = _ini_setpointval; } /// /// Change the operation mode of the Eload. /// /// The desired Eload mode. public void SetMode(EloadModuleMode mode) { _mode = mode; } /// /// Change the setpoint of the Eload. /// /// The desired setpoint of the Eload. public void SetSetpoint(double newSetpoint, EloadModuleMode mode) { if (mode != _mode) { throw new Exception("the current mode and the specified mode do not match. Current Mode: " + _mode.ToString() + ", specified mode: " + mode.ToString()); } _setpointVal = newSetpoint; } /// /// Dispose of this object's resources. /// /// True = currently disposing, False = not disposing. protected virtual void Dispose(bool disposing) { } public bool ClearErrors() { return true; } public void Initialize() { SetInitialSetting(); } public SelfTestResult PerformSelfTest() { throw new NotImplementedException(); } public void Reset() { Disable(); Enable(); } public void Shutdown() { Dispose(); } #endregion } }