Major upgrade
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -30,71 +30,64 @@
|
||||
// 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;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
[ExportInstrumentFactory(ModelNumber = "ELoadScpiKeysightFactory")]
|
||||
public class ELoadScpiKeysightFactory : 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;
|
||||
[ExportInstrumentFactory(ModelNumber = "ELoadScpiKeysightFactory")]
|
||||
public class ELoadScpiKeysightFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public ELoadScpiKeysightFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
/// <summary>
|
||||
/// COECommDeviceInstrumentFactory injection constructor
|
||||
/// </summary>
|
||||
/// <param name="configManager"></param>
|
||||
/// <param name="simEngine"></param>
|
||||
/// <param name="logger"></param>
|
||||
[ImportingConstructor]
|
||||
public ELoadScpiKeysightFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public ELoadScpiKeysightFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
/// <summary>
|
||||
/// ELoadScpiKeysightFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public ELoadScpiKeysightFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(IEload));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new ELoadScpiKeysight(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
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(IEload));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new ELoadScpiKeysight(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -105,12 +98,10 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
if (simulateHw)
|
||||
return new EloadSim(name, _configurationManager, _logger);
|
||||
return new EloadSim(name, _configurationManager);
|
||||
else
|
||||
return new ELoadScpiKeysight(name, _configurationManager, _logger);
|
||||
return new ELoadScpiKeysight(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -123,17 +114,17 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
return _supportedInterfaces.ToArray();
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,366 +23,361 @@ using Raytheon.Units;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A simulated eload
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Raytheon configuration
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// FlowMeterOmegaDPF20 factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public EloadSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
const double SETPOINT_VOLTAGE = 28.0;
|
||||
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for an Eload (Simulation).
|
||||
/// </summary>
|
||||
/// <param name="channelNumber">The channel number for the Eload.</param>
|
||||
/// <param name="mode">The operation mode of the channel. Modes: Resistance, Voltage, Current.</param>
|
||||
/// <param name="setpointVal">The operation point of the load. This can be a voltage, current, or resistance.</param>
|
||||
/// <param name="overCurrentProtection">Overcurrent setpoint that will turn off the channel if exceeded.</param>
|
||||
/// <param name="overVoltageProtection">Overvoltage setpoint that will turn off channel if exceeded (double check).</param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The finalizer.
|
||||
/// </summary>
|
||||
~EloadSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a SCPI Command to the instrument and get a response.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to send.</param>
|
||||
/// <returns>THe instrument response.</returns>
|
||||
public string IOQuery(string commandString)
|
||||
{
|
||||
// just to provide a small delay 10ms for the sim
|
||||
Thread.Sleep(10);
|
||||
return "IOQuery Sim Response";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a SCPI Command to the instrument.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to be send.</param>
|
||||
public void IOWrite(string commandString)
|
||||
{
|
||||
// just to provide a small delay 10ms for the sim
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query if the Eload input is on (simulated).
|
||||
/// </summary>
|
||||
/// <returns>Status of Eload (simulated). True = On, False = Off.</returns>
|
||||
public bool IsInputOn()
|
||||
{
|
||||
return _isOn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns the Eload off (simulated).
|
||||
/// </summary>
|
||||
public void Enable()
|
||||
{
|
||||
_isOn = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns the Eload on (simulated).
|
||||
/// </summary>
|
||||
public void Disable()
|
||||
{
|
||||
_isOn = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the current of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The current (simulated).</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the mode of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The mode (simulated).</returns>
|
||||
public EloadModuleMode ReadMode()
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the overcurrent setting from an Eload.
|
||||
/// </summary>
|
||||
/// <returns>Overcurrent setting (simulated).</returns>
|
||||
public Current ReadOverCurrentProtection()
|
||||
{
|
||||
// just to provide a small delay 10ms for the sim
|
||||
Thread.Sleep(10);
|
||||
|
||||
return Current.FromAmps(_overCurrentProtection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the overvoltage setting from an Eload.
|
||||
/// </summary>
|
||||
/// <returns>Overvoltage setting (simulated).</returns>
|
||||
public Voltage ReadOverVoltageProtection()
|
||||
{
|
||||
// just to provide a small delay 10ms for the sim
|
||||
Thread.Sleep(10);
|
||||
|
||||
return Voltage.FromVolts(_overVoltageProtection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the resistance of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The resistance (simulated).</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the setpoint of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The setpoint (simulated).</returns>
|
||||
public double ReadSetpoint()
|
||||
{
|
||||
return _setpointVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the voltage of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The voltage (simulated).</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the protection status from an Eload.
|
||||
/// </summary>
|
||||
/// <returns>Protection status (simulated).</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets Initial Settings
|
||||
/// </summary>
|
||||
public void SetInitialSetting()
|
||||
{
|
||||
_mode = _originalMode;
|
||||
_setpointVal = _ini_setpointval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the operation mode of the Eload.
|
||||
/// </summary>
|
||||
/// <param name="mode">The desired Eload mode.</param>
|
||||
public void SetMode(EloadModuleMode mode)
|
||||
{
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the setpoint of the Eload.
|
||||
/// </summary>
|
||||
/// <param name="newSetpoint">The desired setpoint of the Eload.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
|
||||
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
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// A simulated eload
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// FlowMeterOmegaDPF20 factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for an Eload (Simulation).
|
||||
/// </summary>
|
||||
/// <param name="channelNumber">The channel number for the Eload.</param>
|
||||
/// <param name="mode">The operation mode of the channel. Modes: Resistance, Voltage, Current.</param>
|
||||
/// <param name="setpointVal">The operation point of the load. This can be a voltage, current, or resistance.</param>
|
||||
/// <param name="overCurrentProtection">Overcurrent setpoint that will turn off the channel if exceeded.</param>
|
||||
/// <param name="overVoltageProtection">Overvoltage setpoint that will turn off channel if exceeded (double check).</param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The finalizer.
|
||||
/// </summary>
|
||||
~EloadSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a SCPI Command to the instrument and get a response.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to send.</param>
|
||||
/// <returns>THe instrument response.</returns>
|
||||
public string IOQuery(string commandString)
|
||||
{
|
||||
// just to provide a small delay 10ms for the sim
|
||||
Thread.Sleep(10);
|
||||
return "IOQuery Sim Response";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a SCPI Command to the instrument.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to be send.</param>
|
||||
public void IOWrite(string commandString)
|
||||
{
|
||||
// just to provide a small delay 10ms for the sim
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query if the Eload input is on (simulated).
|
||||
/// </summary>
|
||||
/// <returns>Status of Eload (simulated). True = On, False = Off.</returns>
|
||||
public bool IsInputOn()
|
||||
{
|
||||
return _isOn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns the Eload off (simulated).
|
||||
/// </summary>
|
||||
public void Enable()
|
||||
{
|
||||
_isOn = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns the Eload on (simulated).
|
||||
/// </summary>
|
||||
public void Disable()
|
||||
{
|
||||
_isOn = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the current of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The current (simulated).</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the mode of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The mode (simulated).</returns>
|
||||
public EloadModuleMode ReadMode()
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the overcurrent setting from an Eload.
|
||||
/// </summary>
|
||||
/// <returns>Overcurrent setting (simulated).</returns>
|
||||
public Current ReadOverCurrentProtection()
|
||||
{
|
||||
// just to provide a small delay 10ms for the sim
|
||||
Thread.Sleep(10);
|
||||
|
||||
return Current.FromAmps(_overCurrentProtection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the overvoltage setting from an Eload.
|
||||
/// </summary>
|
||||
/// <returns>Overvoltage setting (simulated).</returns>
|
||||
public Voltage ReadOverVoltageProtection()
|
||||
{
|
||||
// just to provide a small delay 10ms for the sim
|
||||
Thread.Sleep(10);
|
||||
|
||||
return Voltage.FromVolts(_overVoltageProtection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the resistance of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The resistance (simulated).</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the setpoint of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The setpoint (simulated).</returns>
|
||||
public double ReadSetpoint()
|
||||
{
|
||||
return _setpointVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the voltage of the Eload.
|
||||
/// </summary>
|
||||
/// <returns>The voltage (simulated).</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the protection status from an Eload.
|
||||
/// </summary>
|
||||
/// <returns>Protection status (simulated).</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets Initial Settings
|
||||
/// </summary>
|
||||
public void SetInitialSetting()
|
||||
{
|
||||
_mode = _originalMode;
|
||||
_setpointVal = _ini_setpointval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the operation mode of the Eload.
|
||||
/// </summary>
|
||||
/// <param name="mode">The desired Eload mode.</param>
|
||||
public void SetMode(EloadModuleMode mode)
|
||||
{
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the setpoint of the Eload.
|
||||
/// </summary>
|
||||
/// <param name="newSetpoint">The desired setpoint of the Eload.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,71 +30,67 @@
|
||||
// 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;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
[ExportInstrumentFactory(ModelNumber = "ELoadSimFactory")]
|
||||
public class ELoadSimFactory : 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;
|
||||
[ExportInstrumentFactory(ModelNumber = "ELoadSimFactory")]
|
||||
public class ELoadSimFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public ELoadSimFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
/// <summary>
|
||||
/// COECommDeviceInstrumentFactory injection constructor
|
||||
/// </summary>
|
||||
/// <param name="configManager"></param>
|
||||
/// <param name="simEngine"></param>
|
||||
/// <param name="logger"></param>
|
||||
[ImportingConstructor]
|
||||
public ELoadSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public ELoadSimFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
/// <summary>
|
||||
/// ELoadSimFactory injection constructor
|
||||
/// </summary>
|
||||
/// <param name="configManager"></param>
|
||||
/// <param name="simEngine"></param>
|
||||
/// <param name="logger"></param>
|
||||
[ImportingConstructor]
|
||||
public ELoadSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(IEload));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new EloadSim(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
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(IEload));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new EloadSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -105,9 +101,7 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
return new EloadSim(name, _configurationManager, _logger);
|
||||
return new EloadSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -120,17 +114,17 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
return _supportedInterfaces.ToArray();
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,73 +30,66 @@
|
||||
// DISTRIBUTION/DISSEMINATION CONTROL: F
|
||||
// POC: Alex Kravchenko (1118268)
|
||||
// **********************************************************************************************************
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using Raytheon.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Reflection;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using Raytheon.Units;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
[ExportInstrumentFactory(ModelNumber = "EloadSystemScpiKeysightFactory")]
|
||||
public class EloadSystemScpiKeysightFactory : 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;
|
||||
[ExportInstrumentFactory(ModelNumber = "EloadSystemScpiKeysightFactory")]
|
||||
public class EloadSystemScpiKeysightFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public EloadSystemScpiKeysightFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
/// <summary>
|
||||
/// COECommDeviceInstrumentFactory injection constructor
|
||||
/// </summary>
|
||||
/// <param name="configManager"></param>
|
||||
/// <param name="simEngine"></param>
|
||||
/// <param name="logger"></param>
|
||||
[ImportingConstructor]
|
||||
public EloadSystemScpiKeysightFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public EloadSystemScpiKeysightFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
/// <summary>
|
||||
/// EloadSystemScpiKeysightFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public EloadSystemScpiKeysightFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(IEload));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new EloadSystemScpiKeysight(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
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(IEload));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new EloadSystemScpiKeysight(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -107,9 +100,7 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
return new EloadSystemScpiKeysight(name, _configurationManager, _logger);
|
||||
return new EloadSystemScpiKeysight(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -122,156 +113,156 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
return _supportedInterfaces.ToArray();
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
/// <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);
|
||||
}
|
||||
|
||||
|
||||
#region PrivateFuctions
|
||||
/// <summary>
|
||||
/// Parses the power controller ini file.
|
||||
/// This ini file defines the number of power systems/modules that this controller will manage.
|
||||
/// Upon parsing the file, this function populates this class members with the ini file information
|
||||
/// </summary>
|
||||
private static IELoadSystem CreateEloadSystemInstrument(string instrumentDefFile, string iniSectionName, bool isThereHardware)
|
||||
{
|
||||
const char COMMA_DELIM = ',';
|
||||
#region PrivateFuctions
|
||||
/// <summary>
|
||||
/// Parses the power controller ini file.
|
||||
/// This ini file defines the number of power systems/modules that this controller will manage.
|
||||
/// Upon parsing the file, this function populates this class members with the ini file information
|
||||
/// </summary>
|
||||
private static IELoadSystem CreateEloadSystemInstrument(string instrumentDefFile, string iniSectionName, bool isThereHardware)
|
||||
{
|
||||
const char COMMA_DELIM = ',';
|
||||
|
||||
// interface types
|
||||
const string GPIB = "GPIB";
|
||||
const string RS232 = "232";
|
||||
// interface types
|
||||
const string GPIB = "GPIB";
|
||||
const string RS232 = "232";
|
||||
|
||||
// system
|
||||
const string BOARD_NUMBER_KEY = "BOARD_NUMBER";
|
||||
const string INTERFACE_KEY = "INTERFACE";
|
||||
const string ADDRESS_KEY = "ADDRESS";
|
||||
const string BAUD_RATE = "BAUD_RATE";
|
||||
const string PARITY = "PARITY";
|
||||
const string DATA_BITS = "DATA_BITS";
|
||||
const string STOP_BITS = "STOP_BITS";
|
||||
const string FLOW_CONTROL = "FLOW_CONTROL";
|
||||
const string MODULE_DEFINITION_KEY = "MODULE_DEFINITION";
|
||||
// system
|
||||
const string BOARD_NUMBER_KEY = "BOARD_NUMBER";
|
||||
const string INTERFACE_KEY = "INTERFACE";
|
||||
const string ADDRESS_KEY = "ADDRESS";
|
||||
const string BAUD_RATE = "BAUD_RATE";
|
||||
const string PARITY = "PARITY";
|
||||
const string DATA_BITS = "DATA_BITS";
|
||||
const string STOP_BITS = "STOP_BITS";
|
||||
const string FLOW_CONTROL = "FLOW_CONTROL";
|
||||
const string MODULE_DEFINITION_KEY = "MODULE_DEFINITION";
|
||||
|
||||
// modules
|
||||
const string MODE = "MODE";
|
||||
const string CHANNEL_NUM = "CHANNEL_NUM";
|
||||
const string SETPOINT_VALUE = "SETPOINT_VALUE";
|
||||
const string OCP = "OVER_CURRENT_PROTECTION";
|
||||
const string OVP = "OVER_VOLTAGE_PROTECTION";
|
||||
// modules
|
||||
const string MODE = "MODE";
|
||||
const string CHANNEL_NUM = "CHANNEL_NUM";
|
||||
const string SETPOINT_VALUE = "SETPOINT_VALUE";
|
||||
const string OCP = "OVER_CURRENT_PROTECTION";
|
||||
const string OVP = "OVER_VOLTAGE_PROTECTION";
|
||||
|
||||
IniFile iniReader = new IniFile(instrumentDefFile);
|
||||
IniFile iniReader = new IniFile(instrumentDefFile);
|
||||
|
||||
// pull out the address and the list of definitions
|
||||
string interfaceType = iniReader.ReadValue(iniSectionName, INTERFACE_KEY);
|
||||
string[] moduleDefinitionList = null;
|
||||
IELoadSystem loadSystem = null;
|
||||
if (interfaceType.ToUpper() == GPIB)
|
||||
{
|
||||
int gpibBoardNumber = Convert.ToInt32(iniReader.ReadValue(iniSectionName, BOARD_NUMBER_KEY));
|
||||
byte gpibAddress = Convert.ToByte(iniReader.ReadValue(iniSectionName, ADDRESS_KEY));
|
||||
string moduleDefinitionSections = iniReader.ReadValue(iniSectionName, MODULE_DEFINITION_KEY);
|
||||
moduleDefinitionList = moduleDefinitionSections.Split(COMMA_DELIM);
|
||||
// pull out the address and the list of definitions
|
||||
string interfaceType = iniReader.ReadValue(iniSectionName, INTERFACE_KEY);
|
||||
string[] moduleDefinitionList = null;
|
||||
IELoadSystem loadSystem = null;
|
||||
if (interfaceType.ToUpper() == GPIB)
|
||||
{
|
||||
int gpibBoardNumber = Convert.ToInt32(iniReader.ReadValue(iniSectionName, BOARD_NUMBER_KEY));
|
||||
byte gpibAddress = Convert.ToByte(iniReader.ReadValue(iniSectionName, ADDRESS_KEY));
|
||||
string moduleDefinitionSections = iniReader.ReadValue(iniSectionName, MODULE_DEFINITION_KEY);
|
||||
moduleDefinitionList = moduleDefinitionSections.Split(COMMA_DELIM);
|
||||
|
||||
loadSystem = new EloadSystemScpiKeysight(iniSectionName, gpibBoardNumber, gpibAddress, isThereHardware);
|
||||
loadSystem = new EloadSystemScpiKeysight(iniSectionName, gpibBoardNumber, gpibAddress, isThereHardware);
|
||||
|
||||
}
|
||||
else if (interfaceType.ToUpper() == RS232)
|
||||
{
|
||||
string eloadSystemComAddress = iniReader.ReadValue(iniSectionName, ADDRESS_KEY);
|
||||
int eloadSystemComBaudRate = Convert.ToInt32(iniReader.ReadValue(iniSectionName, BAUD_RATE));
|
||||
Parity eloadSystemComParity = (Parity)Enum.Parse(typeof(Parity), iniReader.ReadValue(iniSectionName, PARITY));
|
||||
int eloadSystemComDataBits = Convert.ToInt32(iniReader.ReadValue(iniSectionName, DATA_BITS));
|
||||
Handshake flowControl = (Handshake)Enum.Parse(typeof(Handshake), iniReader.ReadValue(iniSectionName, FLOW_CONTROL));
|
||||
StopBits eloadSystemComStopBits = (StopBits)Enum.Parse(typeof(StopBits), iniReader.ReadValue(iniSectionName, STOP_BITS));
|
||||
}
|
||||
else if (interfaceType.ToUpper() == RS232)
|
||||
{
|
||||
string eloadSystemComAddress = iniReader.ReadValue(iniSectionName, ADDRESS_KEY);
|
||||
int eloadSystemComBaudRate = Convert.ToInt32(iniReader.ReadValue(iniSectionName, BAUD_RATE));
|
||||
Parity eloadSystemComParity = (Parity)Enum.Parse(typeof(Parity), iniReader.ReadValue(iniSectionName, PARITY));
|
||||
int eloadSystemComDataBits = Convert.ToInt32(iniReader.ReadValue(iniSectionName, DATA_BITS));
|
||||
Handshake flowControl = (Handshake)Enum.Parse(typeof(Handshake), iniReader.ReadValue(iniSectionName, FLOW_CONTROL));
|
||||
StopBits eloadSystemComStopBits = (StopBits)Enum.Parse(typeof(StopBits), iniReader.ReadValue(iniSectionName, STOP_BITS));
|
||||
|
||||
string moduleDefinitionSections = iniReader.ReadValue(iniSectionName, MODULE_DEFINITION_KEY);
|
||||
moduleDefinitionList = moduleDefinitionSections.Split(COMMA_DELIM);
|
||||
string moduleDefinitionSections = iniReader.ReadValue(iniSectionName, MODULE_DEFINITION_KEY);
|
||||
moduleDefinitionList = moduleDefinitionSections.Split(COMMA_DELIM);
|
||||
|
||||
loadSystem = new EloadSystemScpiKeysight(iniSectionName, eloadSystemComAddress, eloadSystemComBaudRate, eloadSystemComParity, eloadSystemComDataBits, eloadSystemComStopBits, flowControl, isThereHardware);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("EloadMeasurementInstruments::CreateEloadSystemInstrument() - Invalid Interface type in ini file. Ini file contained: " + interfaceType + ", supported types are: " + GPIB + "," + RS232);
|
||||
}
|
||||
loadSystem = new EloadSystemScpiKeysight(iniSectionName, eloadSystemComAddress, eloadSystemComBaudRate, eloadSystemComParity, eloadSystemComDataBits, eloadSystemComStopBits, flowControl, isThereHardware);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("EloadMeasurementInstruments::CreateEloadSystemInstrument() - Invalid Interface type in ini file. Ini file contained: " + interfaceType + ", supported types are: " + GPIB + "," + RS232);
|
||||
}
|
||||
|
||||
foreach (string module in moduleDefinitionList)
|
||||
{
|
||||
string trimmedModuleName = module.TrimStart(' ');
|
||||
trimmedModuleName = trimmedModuleName.TrimEnd(' ');
|
||||
foreach (string module in moduleDefinitionList)
|
||||
{
|
||||
string trimmedModuleName = module.TrimStart(' ');
|
||||
trimmedModuleName = trimmedModuleName.TrimEnd(' ');
|
||||
|
||||
int modeTemp = Convert.ToInt32(iniReader.ReadValue(trimmedModuleName, MODE));
|
||||
int channelNumber = Convert.ToInt32(iniReader.ReadValue(trimmedModuleName, CHANNEL_NUM));
|
||||
double setpoint = Convert.ToDouble(iniReader.ReadValue(trimmedModuleName, SETPOINT_VALUE));
|
||||
double ocp = Convert.ToDouble(iniReader.ReadValue(trimmedModuleName, OCP));
|
||||
double ovp = Convert.ToDouble(iniReader.ReadValue(trimmedModuleName, OVP));
|
||||
int modeTemp = Convert.ToInt32(iniReader.ReadValue(trimmedModuleName, MODE));
|
||||
int channelNumber = Convert.ToInt32(iniReader.ReadValue(trimmedModuleName, CHANNEL_NUM));
|
||||
double setpoint = Convert.ToDouble(iniReader.ReadValue(trimmedModuleName, SETPOINT_VALUE));
|
||||
double ocp = Convert.ToDouble(iniReader.ReadValue(trimmedModuleName, OCP));
|
||||
double ovp = Convert.ToDouble(iniReader.ReadValue(trimmedModuleName, OVP));
|
||||
|
||||
EloadModuleMode mode;
|
||||
EloadModuleMode mode;
|
||||
|
||||
if (modeTemp == 0)
|
||||
{
|
||||
mode = EloadModuleMode.RESISTANCE;
|
||||
}
|
||||
else if (modeTemp == 1)
|
||||
{
|
||||
mode = EloadModuleMode.VOLTAGE;
|
||||
}
|
||||
else if (modeTemp == 2)
|
||||
{
|
||||
mode = EloadModuleMode.CURRENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("EloadMeasurementInstruments::CreateEloadSystemInstrument() - Invalid mode input: " + modeTemp.ToString());
|
||||
}
|
||||
if (modeTemp == 0)
|
||||
{
|
||||
mode = EloadModuleMode.RESISTANCE;
|
||||
}
|
||||
else if (modeTemp == 1)
|
||||
{
|
||||
mode = EloadModuleMode.VOLTAGE;
|
||||
}
|
||||
else if (modeTemp == 2)
|
||||
{
|
||||
mode = EloadModuleMode.CURRENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("EloadMeasurementInstruments::CreateEloadSystemInstrument() - Invalid mode input: " + modeTemp.ToString());
|
||||
}
|
||||
|
||||
loadSystem.AddEloadChannel(trimmedModuleName.ToUpper(), channelNumber, mode, setpoint, Current.FromAmps(ocp), Voltage.FromVolts(ovp));
|
||||
}
|
||||
loadSystem.AddEloadChannel(trimmedModuleName.ToUpper(), channelNumber, mode, setpoint, Current.FromAmps(ocp), Voltage.FromVolts(ovp));
|
||||
}
|
||||
|
||||
return loadSystem;
|
||||
}
|
||||
#endregion
|
||||
return loadSystem;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFuctions
|
||||
public static List<IELoadSystem> CreateEloadSystemInstrument(string instrumentDefFile, bool isThereHardware)
|
||||
{
|
||||
const string KEYSIGHT_ELOAD_SCPI = "KEYSIGHT_SCPI_ELOAD_SYSTEM";
|
||||
#region PublicFuctions
|
||||
public static List<IELoadSystem> CreateEloadSystemInstrument(string instrumentDefFile, bool isThereHardware)
|
||||
{
|
||||
const string KEYSIGHT_ELOAD_SCPI = "KEYSIGHT_SCPI_ELOAD_SYSTEM";
|
||||
|
||||
List<IELoadSystem> loadSystemsToReturn = new List<IELoadSystem>();
|
||||
List<IELoadSystem> loadSystemsToReturn = new List<IELoadSystem>();
|
||||
|
||||
IniFile iniReader = new IniFile(instrumentDefFile);
|
||||
IniFile iniReader = new IniFile(instrumentDefFile);
|
||||
|
||||
List<string> loadSystemsToCreateKeys = iniReader.ReadAllKeys("ELOAD_SYSTEMS_TO_CREATE");
|
||||
List<string> loadSystemsToCreateKeys = iniReader.ReadAllKeys("ELOAD_SYSTEMS_TO_CREATE");
|
||||
|
||||
foreach (string loadSystemName in loadSystemsToCreateKeys)
|
||||
{
|
||||
string loadSystemType = iniReader.ReadValue("ELOAD_SYSTEMS_TO_CREATE", loadSystemName);
|
||||
foreach (string loadSystemName in loadSystemsToCreateKeys)
|
||||
{
|
||||
string loadSystemType = iniReader.ReadValue("ELOAD_SYSTEMS_TO_CREATE", loadSystemName);
|
||||
|
||||
if (loadSystemType.ToUpper() == KEYSIGHT_ELOAD_SCPI.ToUpper())
|
||||
{
|
||||
IELoadSystem loadSystem = CreateEloadSystemInstrument(instrumentDefFile, loadSystemName, isThereHardware);
|
||||
if (loadSystemType.ToUpper() == KEYSIGHT_ELOAD_SCPI.ToUpper())
|
||||
{
|
||||
IELoadSystem loadSystem = CreateEloadSystemInstrument(instrumentDefFile, loadSystemName, isThereHardware);
|
||||
|
||||
loadSystemsToReturn.Add(loadSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMsg = "EloadMeasurementInstruments::CreateEloadSystemInstrument() - Unsupported ELoad instrument: " + loadSystemName + "\n";
|
||||
errorMsg += "Supported instrument are: " + KEYSIGHT_ELOAD_SCPI;
|
||||
throw new Exception(errorMsg);
|
||||
}
|
||||
}
|
||||
loadSystemsToReturn.Add(loadSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
string errorMsg = "EloadMeasurementInstruments::CreateEloadSystemInstrument() - Unsupported ELoad instrument: " + loadSystemName + "\n";
|
||||
errorMsg += "Supported instrument are: " + KEYSIGHT_ELOAD_SCPI;
|
||||
throw new Exception(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
return loadSystemsToReturn;
|
||||
}
|
||||
#endregion
|
||||
return loadSystemsToReturn;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user