Big changes
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
// Ignore Spelling: FRONTPANEL WATCHDOGDELAY WATCHDOGON WATCHDOGOFF OCP OVP SELFTEST
|
||||
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
public class PowerScpiCommands
|
||||
{
|
||||
// module current commands
|
||||
public string _SET_OCP_INRUSH_DELAY_CMD;
|
||||
public string _SET_OCP_CMD;
|
||||
public string _SET_OCP_ON_CMD;
|
||||
public string _READ_CURRENT_CMD;
|
||||
public string _READ_OCP_CMD;
|
||||
public string _READ_INRUSH_DELAY_CMD;
|
||||
//public string _READ_OCP_CMD = "CURR:LIM" ?;
|
||||
|
||||
// module voltage commands
|
||||
public string _SET_OVP_CMD;
|
||||
public string _SET_VOLTAGE_SLEW_CMD;
|
||||
public string _SET_VOLTAGE_SETPOINT_CMD;
|
||||
public string _SET_CONSTANT_VOLTAGE_CMD;
|
||||
public string _READ_VOLTAGE_CMD;
|
||||
public string _READ_VOLTAGE_SETPOINT_CMD;
|
||||
public string _READ_OVP_CMD;
|
||||
public string _READ_VOLTAGE_SLEW_CMD;
|
||||
|
||||
// module set output commands
|
||||
public string _SET_OUTPUT_DISABLE_CMD;
|
||||
public string _SET_OUTPUT_ENABLE_CMD;
|
||||
|
||||
// module query status
|
||||
public string _READ_OUTPUT_STATUS_CMD;
|
||||
public string _READ_ERROR_STATUS_CMD;
|
||||
public string _READ_PROTECTION_STATUS_CMD;
|
||||
|
||||
// system commands
|
||||
public string _CLEAR_CMD;
|
||||
public string _RESET_CMD;
|
||||
public string _SELFTEST_CMD;
|
||||
public string _REBOOT_CMD;
|
||||
public string _READ_ERROR_CODE_CMD;
|
||||
|
||||
// system disable/enable commands
|
||||
public string _SET_FRONTPANEL_DISABLE_CMD;
|
||||
public string _SET_FRONTPANEL_ENABLE_CMD;
|
||||
|
||||
// system watchdog commands
|
||||
public string _SET_WATCHDOGDELAY_CMD;
|
||||
public string _SET_WATCHDOGON_CMD;
|
||||
public string _SET_WATCHDOGOFF_CMD;
|
||||
|
||||
// system coupling commands
|
||||
public string _SET_COUPLE_CHANNELS_CMD;
|
||||
public string _SET_COUPLE_ON_CMD;
|
||||
public string _SET_COUPLE_OUTPUT_PROTECT_ON_CMD;
|
||||
public string _QUERY_COUPLE_CHANNELS_CMD;
|
||||
public string _QUERY_COUPLE_STATE_CMD;
|
||||
|
||||
// system grouping Commands
|
||||
public string _SET_GROUP_DEFINE_CMD;
|
||||
public string _UNGROUP_ALL_CHANNELS_CMD;
|
||||
public string _QUERY_GROUP_CHANNELS_CMD;
|
||||
|
||||
private void ReadModuleCommands(string defFile)
|
||||
{
|
||||
IniFile ini = new IniFile(defFile);
|
||||
_SET_OCP_INRUSH_DELAY_CMD = ini.ReadValue("MODULE", "SET_INRUSH_DELAY_CMD");
|
||||
_SET_OCP_CMD = ini.ReadValue("MODULE", "SET_OCP_CMD");
|
||||
_SET_OCP_ON_CMD = ini.ReadValue("MODULE", "SET_OCP_ON_CMD");
|
||||
_READ_CURRENT_CMD = ini.ReadValue("MODULE", "READ_CURRENT_CMD");
|
||||
_READ_OCP_CMD = ini.ReadValue("MODULE", "READ_OCP_CMD");
|
||||
_READ_INRUSH_DELAY_CMD = ini.ReadValue("MODULE", "READ_INRUSH_DELAY_CMD");
|
||||
|
||||
_SET_OVP_CMD = ini.ReadValue("MODULE", "SET_OVP_CMD");
|
||||
_SET_VOLTAGE_SLEW_CMD = ini.ReadValue("MODULE", "SET_VOLTAGE_SLEW_CMD");
|
||||
_SET_VOLTAGE_SETPOINT_CMD = ini.ReadValue("MODULE", "SET_VOLTAGE_SETPOINT_CMD");
|
||||
_SET_CONSTANT_VOLTAGE_CMD = ini.ReadValue("MODULE", "SET_CONSTANT_VOLTAGE_CMD");
|
||||
_READ_VOLTAGE_CMD = ini.ReadValue("MODULE", "READ_VOLTAGE_CMD");
|
||||
_READ_VOLTAGE_SETPOINT_CMD = ini.ReadValue("MODULE", "READ_VOLTAGE_SETPOINT_CMD");
|
||||
_READ_OVP_CMD = ini.ReadValue("MODULE", "READ_OVP_CMD");
|
||||
_READ_VOLTAGE_SLEW_CMD = ini.ReadValue("MODULE", "READ_VOLTAGE_SLEW_CMD");
|
||||
|
||||
_SET_OUTPUT_DISABLE_CMD = ini.ReadValue("MODULE", "SET_OUTPUT_DISABLE_CMD");
|
||||
_SET_OUTPUT_ENABLE_CMD = ini.ReadValue("MODULE", "SET_OUTPUT_ENABLE_CMD");
|
||||
_READ_OUTPUT_STATUS_CMD = ini.ReadValue("MODULE", "READ_OUTPUT_STATUS_CMD");
|
||||
_READ_ERROR_STATUS_CMD = ini.ReadValue("MODULE", "READ_ERROR_STATUS_CMD");
|
||||
_READ_PROTECTION_STATUS_CMD = ini.ReadValue("MODULE", "READ_PROTECTION_STATUS_CMD");
|
||||
}
|
||||
|
||||
private void ReadSystemCommands(string defFile)
|
||||
{
|
||||
IniFile ini = new IniFile(defFile);
|
||||
|
||||
_CLEAR_CMD = ini.ReadValue("SYSTEM", "CLEAR_CMD");
|
||||
_RESET_CMD = ini.ReadValue("SYSTEM", "RESET_CMD");
|
||||
_SELFTEST_CMD = ini.ReadValue("SYSTEM", "SELFTEST_CMD");
|
||||
_REBOOT_CMD = ini.ReadValue("SYSTEM", "REBOOT_CMD");
|
||||
_READ_ERROR_CODE_CMD = ini.ReadValue("SYSTEM", "READ_ERROR_CODE_CMD");
|
||||
|
||||
_SET_FRONTPANEL_DISABLE_CMD = ini.ReadValue("SYSTEM", "SET_FRONTPANEL_DISABLE_CMD");
|
||||
_SET_FRONTPANEL_ENABLE_CMD = ini.ReadValue("SYSTEM", "SET_FRONTPANEL_ENABLE_CMD");
|
||||
|
||||
_SET_WATCHDOGDELAY_CMD = ini.ReadValue("SYSTEM", "SET_WATCHDOGDELAY_CMD");
|
||||
_SET_WATCHDOGON_CMD = ini.ReadValue("SYSTEM", "SET_WATCHDOGON_CMD");
|
||||
_SET_WATCHDOGOFF_CMD = ini.ReadValue("SYSTEM", "SET_WATCHDOGOFF_CMD");
|
||||
|
||||
_SET_COUPLE_CHANNELS_CMD = ini.ReadValue("SYSTEM", "SET_COUPLE_CHANNELS_CMD");
|
||||
_SET_COUPLE_ON_CMD = ini.ReadValue("SYSTEM", "SET_COUPLE_ON_CMD");
|
||||
_SET_COUPLE_OUTPUT_PROTECT_ON_CMD = ini.ReadValue("SYSTEM", "SET_COUPLE_OUTPUT_PROTECT_ON_CMD");
|
||||
_QUERY_COUPLE_CHANNELS_CMD = ini.ReadValue("SYSTEM", "QUERY_COUPLE_CHANNELS");
|
||||
_QUERY_COUPLE_STATE_CMD = ini.ReadValue("SYSTEM", "QUERY_COUPLE_STATE");
|
||||
|
||||
_SET_GROUP_DEFINE_CMD = ini.ReadValue("SYSTEM", "SET_GROUP_DEFINE_CMD");
|
||||
_UNGROUP_ALL_CHANNELS_CMD = ini.ReadValue("SYSTEM", "UNGROUP_ALL_CHANNELS_CMD");
|
||||
_QUERY_GROUP_CHANNELS_CMD = ini.ReadValue("SYSTEM", "QUERY_GROUP_CHANNELS");
|
||||
}
|
||||
|
||||
public PowerScpiCommands(string scpiDefFile)
|
||||
{
|
||||
IniFile ini = new IniFile(scpiDefFile);
|
||||
|
||||
ReadModuleCommands(scpiDefFile);
|
||||
ReadSystemCommands(scpiDefFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,979 @@
|
||||
// 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 NLog;
|
||||
using Raytheon.Common;
|
||||
using Raytheon.Units;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that provides an interface for controlling power supply modules via SCPI commands.
|
||||
/// </summary>
|
||||
public class PowerSupplyKeysight : IDCPwr
|
||||
{
|
||||
#region PublicClassMembers
|
||||
#pragma warning disable CS0067
|
||||
public event EventHandler<OverCurrentEventArgs> OverCurrent;
|
||||
public event EventHandler<OverVoltageEventArgs> OverVoltage;
|
||||
#pragma warning restore
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateClassMembers
|
||||
|
||||
private string _name;
|
||||
private readonly PowerScpiCommands _scpiCommands;
|
||||
private double _overCurrentProtection;
|
||||
private double _overVoltageProtection;
|
||||
private double _voltageSetpoint;
|
||||
private readonly double _voltageSetpointInitial;
|
||||
private readonly double _maxVoltageSetpoint;
|
||||
private readonly double _minVoltageSetpoint;
|
||||
private readonly double _inRushDelay;
|
||||
private readonly double _slewRateVoltsPerSecond;
|
||||
private readonly int _moduleNumber;
|
||||
private byte[] _readBuffer;
|
||||
private NetworkStream _tcpStream;
|
||||
private State _state;
|
||||
private const int _READ_TIMEOUT = 5000;
|
||||
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicFuctions
|
||||
|
||||
/// <summary>
|
||||
/// The constructor which sets the power supply to constant voltage mode, set the OCP, OVP and setpoint voltage
|
||||
/// </summary>
|
||||
/// <param name="name">The logical name of the supply.</param>
|
||||
/// <param name="scpiCommands">Scpi commands to use.</param>
|
||||
/// <param name="overCurrentProtection">The overcurrent protection setting (Amps).</param>
|
||||
/// <param name="overVoltageProtection">The overvoltage protection setting (Volts).</param>
|
||||
/// <param name="voltageSetpoint">The voltage setpoint (Volts).</param>
|
||||
/// <param name="maxVoltageSetpoint">The voltage setpoint max (Volts) soft limit.</param>
|
||||
/// <param name="minVoltageSetpoint">The voltage setpoint min (Volts) soft limit.</param>
|
||||
/// <param name="inRushDelayInSeconds">In rush delay in seconds.-1 to leave it as default</param>
|
||||
/// <param name="slewRateVoltsPerSecond">The ramp up rate.-1 to leave it as default</param>
|
||||
/// <param name="tcpStream">TCP Stream (Ethernet).</param>
|
||||
/// <param name="moduleNumber">The module number (multiple modules in a system).</param>
|
||||
public PowerSupplyKeysight(string name, PowerScpiCommands scpiCommands, double overCurrentProtection, double overVoltageProtection, double voltageSetpoint, double maxVoltageSetpoint, double minVoltageSetpoint, double inRushDelayInSeconds, double slewRateVoltsPerSecond, NetworkStream tcpStream, int moduleNumber = -1)
|
||||
{
|
||||
const int READ_BUFFER_SIZE = 512;
|
||||
|
||||
_name = name;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_scpiCommands = scpiCommands;
|
||||
_overCurrentProtection = overCurrentProtection;
|
||||
_overVoltageProtection = overVoltageProtection;
|
||||
_voltageSetpoint = voltageSetpoint;
|
||||
_voltageSetpointInitial = voltageSetpoint;
|
||||
_maxVoltageSetpoint = maxVoltageSetpoint;
|
||||
_minVoltageSetpoint = minVoltageSetpoint;
|
||||
_inRushDelay = inRushDelayInSeconds;
|
||||
_slewRateVoltsPerSecond = slewRateVoltsPerSecond;
|
||||
_moduleNumber = moduleNumber;
|
||||
_readBuffer = new byte[READ_BUFFER_SIZE];
|
||||
|
||||
_tcpStream = tcpStream;
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
return _state == State.Uninitialized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object.
|
||||
/// </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 Current CurrentLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
return Current.FromAmps(ReadOcpSetpoint());
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_overCurrentProtection = value.Amps;
|
||||
|
||||
SetAndConfirmOCP();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Keysight Scpi Power Supply";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsOutputOn();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value == false)
|
||||
{
|
||||
Off();
|
||||
}
|
||||
else
|
||||
{
|
||||
On();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns this object's module number.
|
||||
/// </summary>
|
||||
/// <returns>The module number.</returns>
|
||||
/*public int GetModuleNumber()
|
||||
{
|
||||
return _moduleNumber;
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool InhibitEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
// make sure it is off
|
||||
Off();
|
||||
|
||||
// set up power supply
|
||||
// for 6702 look at page 36
|
||||
SetConstantVoltageMode();
|
||||
SetAndConfirmOVP();
|
||||
SetAndConfirmOCP();
|
||||
SetVoltageSetpoint(_voltageSetpoint);
|
||||
|
||||
// -1.0 means leave as default
|
||||
if (_inRushDelay != -1.0)
|
||||
{
|
||||
SetAndConfirmInRushDelay();
|
||||
}
|
||||
|
||||
// -1.0 means leave as default
|
||||
if (_slewRateVoltsPerSecond != -1.0)
|
||||
{
|
||||
SetAndConfirmSlewRate();
|
||||
}
|
||||
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("PowerSupplyKeysight::Initialize() - " + _name + " expected the state to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Control the power supply internal mechanical relay state
|
||||
/// </summary>
|
||||
/// <param name="shallWeConnect">True to connect, false to disconnect</param>
|
||||
public void MechanicalRelayOutputControl(bool shallWeConnect)
|
||||
{
|
||||
throw new Exception("Not yet implemented");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Current MeasureCurrent()
|
||||
{
|
||||
return Current.FromAmps(ReadCurrent());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Voltage MeasureVoltage()
|
||||
{
|
||||
return Voltage.FromVolts(ReadVoltage());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Voltage OutputVoltage
|
||||
{
|
||||
get
|
||||
{
|
||||
return Voltage.FromVolts(ReadVoltageSetpoint());
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
double volts = value.Volts;
|
||||
|
||||
// do not let host set the voltage out of range, unless it is being set to 0
|
||||
if (volts != 0.0)
|
||||
{
|
||||
if (volts > _maxVoltageSetpoint || volts < _minVoltageSetpoint)
|
||||
{
|
||||
throw new Exception("PowerSupplyKeysight::OutputVoltage() - Desired voltage setpoint out of range for supply " + _name + ". Commanded setpoint: " + value.ToString() + ", Max: " + _maxVoltageSetpoint.ToString() + ", Min: " + _minVoltageSetpoint.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
SetVoltageSetpoint(volts);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Voltage OverVoltageProtection
|
||||
{
|
||||
get
|
||||
{
|
||||
return Voltage.FromVolts(ReadOvpSetpoint());
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_overVoltageProtection = value.Volts;
|
||||
|
||||
SetAndConfirmOVP();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool OverVoltageProtectionEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException("PowerSupplyKeysight::PerformSelfTest() - self test is not implemented in the " + _name + " supply");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the overvoltage and overcurrent protection status.
|
||||
/// </summary>
|
||||
/// <returns>The binary sum of all bits (decimal value) set in the Questionable Status Condition register.</returns>
|
||||
public int ReadProtectionStatus()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._READ_PROTECTION_STATUS_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
int ret = Util.ConvertStringToInt32(tokens[0]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException("PowerSupplyKeysight::Reset() - cant reset a module, only the system");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
string errorMsg = "";
|
||||
|
||||
try
|
||||
{
|
||||
Off();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
errorMsg += err.Message + " ";
|
||||
}
|
||||
|
||||
_state = State.Uninitialized;
|
||||
|
||||
if (errorMsg != "")
|
||||
{
|
||||
throw new Exception("PowerSupplyKeysight::ShutdDown() - Power Supply " + _name + " had an error: " + errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Voltage VoltageSoftLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
return Voltage.FromVolts(_maxVoltageSetpoint);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFuctions
|
||||
/// <summary>
|
||||
/// The finalizer.
|
||||
/// </summary>
|
||||
~PowerSupplyKeysight()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
try
|
||||
{
|
||||
Off();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
_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>
|
||||
/// <returns></returns>
|
||||
private double GetSlewRate()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._READ_VOLTAGE_SLEW_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
// parse the response
|
||||
double rsp = Util.ConvertStringToDouble(tokens[0]);
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query the output state.
|
||||
/// </summary>
|
||||
/// <returns>The output state. True = On, False = Off.</returns>
|
||||
private bool IsOutputOn()
|
||||
{
|
||||
// send the command and read the rsp
|
||||
string command = _scpiCommands._READ_OUTPUT_STATUS_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
int rsp = Util.ConvertStringToInt32(tokens[0]);
|
||||
|
||||
if (rsp == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn off the output.
|
||||
/// </summary>
|
||||
private void Off()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._SET_OUTPUT_DISABLE_CMD + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn on the output.
|
||||
/// </summary>
|
||||
private void On()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._SET_OUTPUT_ENABLE_CMD + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the current.
|
||||
/// </summary>
|
||||
/// <returns>The current (Amps).</returns>
|
||||
private double ReadCurrent()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._READ_CURRENT_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
// parse the response
|
||||
double rsp = Util.ConvertStringToDouble(tokens[0]);
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the voltage.
|
||||
/// </summary>
|
||||
/// <returns>The voltage (Volts).</returns>
|
||||
private double ReadVoltage()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._READ_VOLTAGE_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
// parse the response
|
||||
double rsp = Util.ConvertStringToDouble(tokens[0]);
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set the slew rate of the supply
|
||||
/// </summary>
|
||||
/// <param name="commandedSlew">slew in volts per second</param>
|
||||
private void SetAndConfirmSlewRate()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._SET_VOLTAGE_SLEW_CMD + " " + _slewRateVoltsPerSecond + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(command);
|
||||
|
||||
// read back the slew
|
||||
double programmedSlewValue = GetSlewRate();
|
||||
|
||||
if (programmedSlewValue != _slewRateVoltsPerSecond)
|
||||
{
|
||||
string errMsg = "PowerSupplyKeysight:SetAndConfirmSlewRate() - power supply " + _name + " reported a setpoint slew rate that was not cmmanded. Trying to set it to: " + _slewRateVoltsPerSecond + ", the power supply returned: " + programmedSlewValue;
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the voltage setpoint.
|
||||
/// </summary>
|
||||
/// <param name="voltage">The desired voltage setpoint.</param>
|
||||
private void SetVoltageSetpoint(double voltage)
|
||||
{
|
||||
const double TOLERANCE = .1;
|
||||
|
||||
// do not let host set the voltage out of range, unless it is being set to 0
|
||||
if (voltage != 0.0)
|
||||
{
|
||||
if (voltage > _maxVoltageSetpoint || voltage < _minVoltageSetpoint)
|
||||
{
|
||||
throw new Exception("PowerSupplyKeysight:SetVoltageSetpoint() - Desired voltage setpoint for supply " + _name + " out of range. Commanded setpoint: " + voltage.ToString() + ", Max: " + _maxVoltageSetpoint.ToString() + ", Min: " + _minVoltageSetpoint.ToString());
|
||||
}
|
||||
|
||||
if (voltage > _overVoltageProtection)
|
||||
{
|
||||
throw new Exception("PowerSupplyKeysight:SetVoltageSetpoint() - Desired voltage setpoint for supply " + _name + " out of range. Commanded setpoint: " + voltage.ToString() + ", OVP is: " + _overVoltageProtection.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// send the command
|
||||
string voltageCommand = _scpiCommands._SET_VOLTAGE_SETPOINT_CMD + " " + voltage + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(voltageCommand);
|
||||
|
||||
// read back the voltage to make sure the command worked
|
||||
double voltageSetpointReturned = ReadVoltageSetpoint();
|
||||
|
||||
if (voltageSetpointReturned < (voltage - TOLERANCE))
|
||||
{
|
||||
string errMsg = "PowerSupplyKeysight:SetVoltageSetpoint() - power supply " + _name + " reported setpoint voltage lower than expected. Trying to set it to: " + voltage + ", the power supply returned: " + voltageSetpointReturned;
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
else if (voltageSetpointReturned > (voltage + TOLERANCE))
|
||||
{
|
||||
string errMsg = "PowerSupplyKeysight:SetVoltageSetpoint() - power supply " + _name + " reported setpoint voltage higher than expected. Trying to set it to: " + voltage + ", the power supply returned: " + voltageSetpointReturned;
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
|
||||
// update our member now that everything checks out
|
||||
_voltageSetpoint = voltage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private string GetResponse()
|
||||
{
|
||||
string response = String.Empty;
|
||||
|
||||
int bytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
response = Encoding.ASCII.GetString(_readBuffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="readTimeout"></param>
|
||||
private void CommSetReadTimeout(int readTimeout)
|
||||
{
|
||||
_tcpStream.ReadTimeout = readTimeout;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void CommInterfaceWrite(byte[] dataToWrite)
|
||||
{
|
||||
_tcpStream.Write(dataToWrite, 0, dataToWrite.Length);
|
||||
}
|
||||
|
||||
/// <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 = _scpiCommands._READ_ERROR_STATUS_CMD + "\n";
|
||||
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(command);
|
||||
|
||||
// send the data out
|
||||
CommInterfaceWrite(commandBuffer);
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// read the response
|
||||
string rspStr = GetResponse();
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split(',');
|
||||
|
||||
int ret = Util.ConvertStringToInt32(tokens[0]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the module formatted string.
|
||||
/// </summary>
|
||||
/// <returns>The module formatted string.</returns>
|
||||
private string GetModuleCmd()
|
||||
{
|
||||
string ret = "";
|
||||
|
||||
if (_moduleNumber > 0)
|
||||
{
|
||||
ret = "(@" + _moduleNumber + ")";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a command to the power supply and get the response.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to send.</param>
|
||||
/// <returns>The response.</returns>
|
||||
private string IOQuery(string commandString)
|
||||
{
|
||||
// not calling IOWrite() so IOWrite() can check for errors after each write
|
||||
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(commandString);
|
||||
|
||||
// send the data out
|
||||
CommInterfaceWrite(commandBuffer);
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// read the response
|
||||
string rspStr = GetResponse();
|
||||
|
||||
// check for errors
|
||||
int err = GetErrorCode();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception("PowerSupplyKeysight:IOQuery() - Power Supply " + _name + " 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)
|
||||
{
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(commandString);
|
||||
|
||||
// send the data out
|
||||
CommInterfaceWrite(commandBuffer);
|
||||
|
||||
// check for errors
|
||||
int err = GetErrorCode();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception("PowerSupplyKeysight:IOWrite() - Power Supply " + _name + " returned error code: " + err.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the overcurrent protection setting from the supply.
|
||||
/// </summary>
|
||||
/// <returns>The overcurrent setting (Amps).</returns>
|
||||
private double ReadOcpSetpoint()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._READ_OCP_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
// parse the response
|
||||
double rsp = Util.ConvertStringToDouble(tokens[0]);
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private double ReadInrushDelaySetpoint()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._READ_INRUSH_DELAY_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
// parse the response
|
||||
double rsp = Util.ConvertStringToDouble(tokens[0]);
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the overvoltage protection setting from the supply.
|
||||
/// </summary>
|
||||
/// <returns>The overvoltage setting (Volts).</returns>
|
||||
private double ReadOvpSetpoint()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._READ_OVP_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
// parse the response
|
||||
double rsp = Util.ConvertStringToDouble(tokens[0]);
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the voltage setpoint.
|
||||
/// </summary>
|
||||
/// <returns>The voltage< setpoint (Volts)./returns>
|
||||
private double ReadVoltageSetpoint()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._READ_VOLTAGE_SETPOINT_CMD + " " + GetModuleCmd() + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
// parse the response
|
||||
double rsp = Util.ConvertStringToDouble(tokens[0]);
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put supply in constant voltage mode.
|
||||
/// </summary>
|
||||
private void SetConstantVoltageMode()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._SET_CONSTANT_VOLTAGE_CMD + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void SetAndConfirmInRushDelay()
|
||||
{
|
||||
// set in rush delay
|
||||
if (_inRushDelay != -1)
|
||||
{
|
||||
string inrushCommand = _scpiCommands._SET_OCP_INRUSH_DELAY_CMD + " " + _inRushDelay + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(inrushCommand);
|
||||
|
||||
// confirm
|
||||
double inrushCommandSetpointReturned = ReadInrushDelaySetpoint();
|
||||
if (inrushCommandSetpointReturned != _inRushDelay)
|
||||
{
|
||||
string errMsg = "PowerSupplyKeysight::SetAndConfirmInRushDelay() - power supply " + _name + " reported in rush delay not as expected. Trying to set it to: " + _inRushDelay + ", the power supply returned: " + inrushCommandSetpointReturned;
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets and confirms the overcurrent protection value.
|
||||
/// </summary>
|
||||
private void SetAndConfirmOCP()
|
||||
{
|
||||
// set current
|
||||
string setCurrentCommand = _scpiCommands._SET_OCP_CMD + " " + _overCurrentProtection + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(setCurrentCommand);
|
||||
|
||||
// confirm
|
||||
double currentSetpointReturned = ReadOcpSetpoint();
|
||||
if (currentSetpointReturned != _overCurrentProtection)
|
||||
{
|
||||
string errMsg = "PowerSupplyKeysight::SetAndConfirmOCP() - power supply " + _name + " reported setpoint current not as expected. Trying to set it to: " + _overCurrentProtection + ", the power supply returned: " + currentSetpointReturned;
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
|
||||
//enable OCP
|
||||
string ocpEnableCommand = _scpiCommands._SET_OCP_ON_CMD + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(ocpEnableCommand);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets and confirms the overvoltage protection value.
|
||||
/// </summary>
|
||||
private void SetAndConfirmOVP()
|
||||
{
|
||||
// send the command
|
||||
string command = _scpiCommands._SET_OVP_CMD + " " + _overVoltageProtection + "," + GetModuleCmd() + "\n";
|
||||
IOWrite(command);
|
||||
|
||||
// confirm
|
||||
double ovpReturned = ReadOvpSetpoint();
|
||||
|
||||
if (ovpReturned != _overVoltageProtection)
|
||||
{
|
||||
string errMsg = "PowerSupplyKeysight:SetAndConfirmOVP() - power supply " + _name + " reported setpoint ovp not as expected. Trying to set it to: " + _overVoltageProtection + ", the power supply returned: " + ovpReturned;
|
||||
throw new Exception(errMsg);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.PowerSupplySystemKeysight</AssemblyName>
|
||||
<Product>Power Supply System Keysight Manual implementation</Product>
|
||||
<Description>Power Supply System Keysight Manual implementation</Description>
|
||||
<OutputType>Library</OutputType>
|
||||
|
||||
<!-- Static versioning (Suitable for Development) -->
|
||||
<!-- Disable the line below for dynamic versioning -->
|
||||
<Version>1.1.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="5.0.0" />
|
||||
<PackageReference Include="Raytheon.Instruments.PowerSupplySystem.Contracts" Version="1.3.0" />
|
||||
<PackageReference Include="Raytheon.Instruments.DCPwr.Contracts" Version="2.7.0" />
|
||||
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PowerSupplySystemSim\PowerSupplySystemSim.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 @@
|
||||
// **********************************************************************************************************
|
||||
// PowerSupplySystemKeysightFactory.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 = "PowerSupplySystemKeysightFactory")]
|
||||
public class PowerSupplySystemKeysightFactory : 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 PowerSupplySystemKeysightFactory(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 PowerSupplySystemKeysightFactory([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(IPowerSupplySystem));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new PowerSupplySystemKeysight(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 PowerSupplySystemSim(name, _configurationManager, _logger);
|
||||
else
|
||||
return new PowerSupplySystemKeysight(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,600 @@
|
||||
// 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 NLog;
|
||||
using Raytheon.Common;
|
||||
using Raytheon.Units;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that provides an interface for controlling simulated power supply systems and their modules.
|
||||
/// </summary>
|
||||
public class PowerSupplySim : IDCPwr
|
||||
{
|
||||
#region PublicClassMembers
|
||||
#pragma warning disable CS0067
|
||||
public event EventHandler<OverCurrentEventArgs> OverCurrent;
|
||||
public event EventHandler<OverVoltageEventArgs> OverVoltage;
|
||||
#pragma warning restore
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicFuctions
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a sim power supply (simulated).
|
||||
/// </summary>
|
||||
/// <param name="overCurrentProtection">The overcurrent protection setting (Amps).</param>
|
||||
/// <param name="overVoltageProtection">The overvoltage protection setting (Volts).</param>
|
||||
/// <param name="voltageSetpoint">The voltage setpoint (Volts).</param>
|
||||
/// <param name="maxVoltageSetpoint">The max voltage setpoint (Volts).</param>
|
||||
/// <param name="minVoltageSetpoint">The min voltage setpoint (Volts).</param>
|
||||
/// <param name="moduleNumber">The module number (multiple modules in a system).</param>
|
||||
public PowerSupplySim(string name, double overCurrentProtection, double overVoltageProtection, double voltageSetpoint, double maxVoltageSetpoint, double minVoltageSetpoint, double slewRateVoltsPerSecond, int moduleNumber = -1)
|
||||
{
|
||||
_name = name;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_overCurrentProtection = overCurrentProtection;
|
||||
_overVoltageProtection = overVoltageProtection;
|
||||
_voltageSetpoint = voltageSetpoint;
|
||||
_voltageSetpointInitial = voltageSetpoint;
|
||||
_maxVoltageSetpoint = maxVoltageSetpoint;
|
||||
_minVoltageSetpoint = minVoltageSetpoint;
|
||||
_moduleNumber = moduleNumber;
|
||||
_isPowerOn = false;
|
||||
_slewRateVoltsPerSecond = slewRateVoltsPerSecond;
|
||||
|
||||
// make sure it is off
|
||||
Enabled = false;
|
||||
|
||||
// set up power supply
|
||||
OutputVoltage = Voltage.FromVolts(_voltageSetpoint);
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Current CurrentLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
return Current.FromAmps(_overCurrentProtection);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_overCurrentProtection = value.Amps;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Sim Power Supply called " + _name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's 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 Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
return _isPowerOn;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
if (value == false)
|
||||
{
|
||||
|
||||
_isPowerOn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_isPowerOn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetSlewRate()
|
||||
{
|
||||
return _slewRateVoltsPerSecond;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool InhibitEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
// if we have not yet been initialized, go ahead and create the socket
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("PowerSupplySim::Initialize() - expected the supply " + _name + " to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Control the power supply internal mechanical relay state
|
||||
/// </summary>
|
||||
/// <param name="shallWeConnect">True to connect, false to disconnect</param>
|
||||
public void MechanicalRelayOutputControl(bool shallWeConnect)
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Current MeasureCurrent()
|
||||
{
|
||||
return Current.FromAmps(ReadCurrent());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Voltage MeasureVoltage()
|
||||
{
|
||||
return Voltage.FromVolts(ReadVoltage());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Voltage OutputVoltage
|
||||
{
|
||||
get
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
return Voltage.FromVolts(_voltageSetpoint);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
double volts = value.Volts;
|
||||
|
||||
// do not let host set the voltage out of range, unless it is being set to 0
|
||||
if (volts != 0.0)
|
||||
{
|
||||
if (volts > _maxVoltageSetpoint || volts < _minVoltageSetpoint)
|
||||
{
|
||||
throw new Exception("PowerSupplySim::OutputVoltage() - Desired voltage setpoint out of range for supply " + _name + ". Commanded setpoint: " + value.ToString() + ", Max: " + _maxVoltageSetpoint.ToString() + ", Min: " + _minVoltageSetpoint.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
_voltageSetpoint = volts;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Voltage OverVoltageProtection
|
||||
{
|
||||
get
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
return Voltage.FromVolts(_overVoltageProtection);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_overVoltageProtection = value.Volts;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool OverVoltageProtectionEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the overcurrent and overvoltage protection (simulation).
|
||||
/// </summary>
|
||||
/// <returns>No Errors (simulated).</returns>
|
||||
public int ReadProtectionStatus()
|
||||
{
|
||||
const int PROTECTION_STATUS = 0;
|
||||
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
return PROTECTION_STATUS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="slew"></param>
|
||||
/*public void SetSlewRate(double slew)
|
||||
{
|
||||
_slew = slew;
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
Off();
|
||||
|
||||
Reset();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Voltage VoltageSoftLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
return Voltage.FromVolts(_maxVoltageSetpoint);
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateClassMembers
|
||||
|
||||
private string _name;
|
||||
private double _overCurrentProtection;
|
||||
private double _overVoltageProtection;
|
||||
private double _voltageSetpoint;
|
||||
private double _voltageSetpointInitial;
|
||||
private readonly double _maxVoltageSetpoint;
|
||||
private readonly double _minVoltageSetpoint;
|
||||
private readonly int _moduleNumber;
|
||||
private bool _isPowerOn;
|
||||
private double _slewRateVoltsPerSecond;
|
||||
private State _state;
|
||||
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFuctions
|
||||
|
||||
/// <summary>
|
||||
/// The finalizer.
|
||||
/// </summary>
|
||||
~PowerSupplySim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
Off();
|
||||
|
||||
_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>
|
||||
/// Returns this object module number.
|
||||
/// </summary>
|
||||
/// <returns>The module number.</returns>
|
||||
/*public int GetModuleNumber()
|
||||
{
|
||||
return _moduleNumber;
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// Turn the output off (simulated).
|
||||
/// </summary>
|
||||
private void Off()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
_isPowerOn = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn the output on (simulated).
|
||||
/// </summary>
|
||||
private void On()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
_isPowerOn = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the current (simulated).
|
||||
/// </summary>
|
||||
/// <returns>The current (simulated).</returns>
|
||||
private double ReadCurrent()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(100);
|
||||
|
||||
double currentToReturn = 0.0;
|
||||
|
||||
if (_isPowerOn)
|
||||
{
|
||||
double maxCurrent = _overCurrentProtection;
|
||||
double minCurrent = _overCurrentProtection - .5;
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
currentToReturn = (seed * (maxCurrent - minCurrent)) + minCurrent;
|
||||
}
|
||||
|
||||
return currentToReturn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the voltage.
|
||||
/// </summary>
|
||||
/// <returns>The voltage (simulated).</returns>
|
||||
private double ReadVoltage()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(100);
|
||||
|
||||
double voltageToReturn = 0.0;
|
||||
|
||||
if (_isPowerOn)
|
||||
{
|
||||
double maxVoltage = _voltageSetpoint + 1;
|
||||
double minVoltage = _voltageSetpoint - 1;
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
voltageToReturn = (seed * (maxVoltage - minVoltage)) + minVoltage;
|
||||
}
|
||||
|
||||
return voltageToReturn;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,934 @@
|
||||
// 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.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
// Ignore Spelling: ocp
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Raytheon.Units;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System.Net.Sockets;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Raytheon.Instruments.PowerSupply;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to control a power supply system.
|
||||
/// </summary>
|
||||
public class PowerSupplySystemSim : IPowerSupplySystem
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private SortedDictionary<string, IDCPwr> _powerModuleMap;
|
||||
private Dictionary<string, PowerSupplyModuleInfo> _powerModuleInfoDict = new Dictionary<string, PowerSupplyModuleInfo>();
|
||||
|
||||
private SortedDictionary<string, double> _powerModuleInitialVoltageSetpoint;
|
||||
private string _name;
|
||||
private object _syncObj = new Object();
|
||||
private List<int> _moduleNumbersThatHaveBeenAdded;
|
||||
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 PrivateFuctions
|
||||
/// <summary>
|
||||
/// The Finalizer.
|
||||
/// </summary>
|
||||
~PowerSupplySystemSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object.
|
||||
/// </summary>
|
||||
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Reset System
|
||||
Reset();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (KeyValuePair<string, IDCPwr> entry in _powerModuleMap)
|
||||
{
|
||||
entry.Value.Shutdown();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
_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 PublicFuctions
|
||||
|
||||
/// <summary>
|
||||
/// PowerSupplySystemSim factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
/// <param name="logger"></param>
|
||||
public PowerSupplySystemSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
string powerSupplySystemDefPath = _configuration.GetConfigurationValue(deviceName, PowerSupply.ConfigXml.POWER_SUPPLY_SYSTEM_DEF_FILEPATH.ToString());
|
||||
|
||||
if (!Path.IsPathRooted(powerSupplySystemDefPath))
|
||||
powerSupplySystemDefPath = Path.GetFullPath(Path.Combine(assemblyFolder, powerSupplySystemDefPath));
|
||||
|
||||
IConfigurationFile config = new ConfigurationFile(powerSupplySystemDefPath);
|
||||
|
||||
_powerModuleInitialVoltageSetpoint = new SortedDictionary<string, double>(StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
_moduleNumbersThatHaveBeenAdded = new List<int>();
|
||||
|
||||
_powerModuleMap = new SortedDictionary<string, IDCPwr>(StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
string moduleDef = config.ReadValue(deviceName, PowerSupply.ConfigIni.MODULE_DEFINITION.ToString());
|
||||
List<string> powerModules = moduleDef.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
|
||||
double overCurrentProtection;
|
||||
double overVoltageProtection;
|
||||
double voltageSetpoint;
|
||||
double maxVoltageSetpoint;
|
||||
double minVoltageSetpoint;
|
||||
double slewRateVoltsPerSecond;
|
||||
double inRushDelaySecs;
|
||||
int moduleNumber = -1;
|
||||
for (int i = 0; i < powerModules.Count(); i++)
|
||||
{
|
||||
string moduleName = powerModules[i];
|
||||
|
||||
int.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.INDEX.ToString()), out moduleNumber);
|
||||
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.OCP.ToString()), out overCurrentProtection);
|
||||
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.OVP.ToString()), out overVoltageProtection);
|
||||
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.VOLTAGE_SETPOINT.ToString()), out voltageSetpoint);
|
||||
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.MIN_VOLTAGE.ToString()), out minVoltageSetpoint);
|
||||
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.MAX_VOLTAGE.ToString()), out maxVoltageSetpoint);
|
||||
|
||||
try
|
||||
{
|
||||
if (!Double.TryParse(config.ReadValue($"{Name}.{moduleName}", PowerSupply.ConfigIni.VOLTAGE_SLEW_RATE.ToString()), out slewRateVoltsPerSecond))
|
||||
slewRateVoltsPerSecond = -1.0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
slewRateVoltsPerSecond = -1.0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!Double.TryParse(config.ReadValue($"{Name}.{moduleName}", PowerSupply.ConfigIni.IN_RUSH_DELAY_SECS.ToString()), out inRushDelaySecs))
|
||||
inRushDelaySecs = -1.0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
inRushDelaySecs = -1.0;
|
||||
}
|
||||
|
||||
_powerModuleInfoDict[moduleName] = new PowerSupplyModuleInfo(moduleNumber, overCurrentProtection, overVoltageProtection, voltageSetpoint, slewRateVoltsPerSecond, minVoltageSetpoint, maxVoltageSetpoint);
|
||||
|
||||
// create and initialize the power module
|
||||
IDCPwr powerSupply = new PowerSupplySim(moduleName, overCurrentProtection, overVoltageProtection, voltageSetpoint, maxVoltageSetpoint, minVoltageSetpoint, inRushDelaySecs, moduleNumber);
|
||||
|
||||
// remember that we have added this module
|
||||
_moduleNumbersThatHaveBeenAdded.Add(moduleNumber);
|
||||
|
||||
// remember the module name
|
||||
_powerModuleMap.Add(moduleName.ToUpper(), powerSupply);
|
||||
|
||||
// remember the initial voltage setpoint
|
||||
_powerModuleInitialVoltageSetpoint.Add(moduleName.ToUpper(), voltageSetpoint);
|
||||
}
|
||||
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Couple modules together
|
||||
/// </summary>
|
||||
/// <param name="moduleNameList"></param>
|
||||
public void CoupleChannels(List<string> moduleNameList)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Power Supply System Sim called " + _name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set { ; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
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>
|
||||
/// Get the error code.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">The error code.</param>
|
||||
/// <returns>The error description.</returns>
|
||||
public string GetErrorCode(out int errorCode)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
errorCode = 0;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the names of the modules in this system
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<string> GetModuleNames()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
List<string> moduleNames = new List<string>();
|
||||
|
||||
foreach (KeyValuePair<string, IDCPwr> modules in _powerModuleMap)
|
||||
{
|
||||
moduleNames.Add(modules.Key);
|
||||
}
|
||||
|
||||
return moduleNames;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the dictionary that contains configuration information for each module
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, PowerSupplyModuleInfo> GetPowerSupplyModuleInfoDict(string powerSystem)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
return _powerModuleInfoDict;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the overcurrent protection setting.
|
||||
/// </summary>
|
||||
/// <param name="name">The module to get the overcurrent protection setting.</param>
|
||||
/// <returns>The current (Amps).</returns>
|
||||
public double GetOverCurrentSetting(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::GetOverCurrentSetting() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
return _powerModuleMap[name.ToUpper()].CurrentLimit.Amps;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the overvoltage protection setting.
|
||||
/// </summary>
|
||||
/// <param name="name">The module to get the overvoltage protection setting.</param>
|
||||
/// <returns>The voltage (Volts).</returns>
|
||||
public double GetOverVoltageSetting(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::GetOverVoltageSetting() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
return _powerModuleMap[name.ToUpper()].OverVoltageProtection.Volts;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetSlewRate(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::GetSlewRate() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
|
||||
//return _powerModuleMap[name.ToUpper()].GetSlewRate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the voltage setpoint.
|
||||
/// </summary>
|
||||
/// <param name="name">The module to get the voltage setpoint setting.</param>
|
||||
/// <returns>the voltage setpoint (Volts).</returns>
|
||||
public double GetVoltageSetting(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::GetVoltageSetting() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
return _powerModuleMap[name.ToUpper()].OutputVoltage.Volts;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Group Modules Together
|
||||
/// </summary>
|
||||
/// <param name="modules"></param>
|
||||
public void GroupModules(List<string> moduleNameList)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
// if we have not yet been initialized, go ahead and create the socket
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
Reset();
|
||||
|
||||
PerformSelfTest();
|
||||
|
||||
// initialize each module
|
||||
foreach (KeyValuePair<string, IDCPwr> powerModPair in _powerModuleMap)
|
||||
{
|
||||
powerModPair.Value.Initialize();
|
||||
}
|
||||
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::Initialize() - expected the System " + _name + " to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a command and return the response
|
||||
/// </summary>
|
||||
/// <param name="commandString"></param>
|
||||
/// <returns></returns>
|
||||
public string IOQuery(string commandString)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
|
||||
// return something
|
||||
return "1.11";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a command
|
||||
/// </summary>
|
||||
/// <param name="commandString"></param>
|
||||
public void IOWrite(string commandString)
|
||||
{
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query the output state.
|
||||
/// </summary>
|
||||
/// <param name="name">The module to query.</param>
|
||||
/// <returns>The output state. True = On, False = Off.</returns>
|
||||
public bool IsOutputOn(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::IsOutputOn() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
return _powerModuleMap[name.ToUpper()].Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Control the power supply internal mechanical relay state
|
||||
/// </summary>
|
||||
/// <param name="name">The module to act on</param>
|
||||
/// <param name="shallWeConnect">True to connect, false to disconnect</param>
|
||||
public void MechanicalRelayOutputControl(string name, bool shallWeConnect)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::MechanicalRelayOutputControl() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the current.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the module.</param>
|
||||
/// <returns>The current (Amps).</returns>
|
||||
public double MeasureCurrent(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::MeasureCurrent() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
return _powerModuleMap[name.ToUpper()].MeasureCurrent().Amps;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the voltage.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the module.</param>
|
||||
/// <returns>The voltage (Volts).</returns>
|
||||
public double MeasureVoltage(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::MeasureVoltage() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
return _powerModuleMap[name.ToUpper()].MeasureVoltage().Volts;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn the output off.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the module.</param>
|
||||
public void Off(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::Off() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
_powerModuleMap[name.ToUpper()].Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn the output on.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the module.</param>
|
||||
public void On(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::On() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
_powerModuleMap[name.ToUpper()].Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
_selfTestResult = SelfTestResult.Pass;
|
||||
|
||||
return _selfTestResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the overvoltage and overcurrent protection status.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the module.</param>
|
||||
/// <returns>The binary sum of all bits (decimal value) set in the Questionable Status Enable register.</returns>
|
||||
public int ReadProtectionStatus(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::ReadProtectionStatus() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
return _powerModuleMap[name.ToUpper()].ReadProtectionStatus();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public PowerData ReadPowerData(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// voltage, voltage setpoint, current, output status
|
||||
double voltage = MeasureVoltage(name);
|
||||
double voltageSetpoint = GetVoltageSetting(name);
|
||||
double current = MeasureCurrent(name);
|
||||
bool outputStatus = IsOutputOn(name);
|
||||
int faultStatus = ReadProtectionStatus(name);
|
||||
double overVoltageProtection = GetOverVoltageSetting(name);
|
||||
double overCurrentProtection = GetOverCurrentSetting(name);
|
||||
|
||||
return new PowerData(voltage, voltageSetpoint, overVoltageProtection, current, overCurrentProtection, outputStatus, faultStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selfTestResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public void SetInitialVoltage(string name)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::SetInitialVoltage() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
double initializeVoltage = _powerModuleInitialVoltageSetpoint[name.ToUpper()];
|
||||
|
||||
SetVoltageSetpoint(name.ToUpper(), initializeVoltage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the slew rate
|
||||
/// </summary>
|
||||
/// <param name="commandedSlew">slew in volts per second</param>
|
||||
public void SetSlewRate(string name, double commandedSlew)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::SetSlewRate() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
|
||||
//_powerModuleMap[name.ToUpper()].SetSlewRate(commandedSlew);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="moduleName"></param>
|
||||
/// <param name="ocpValue"></param>
|
||||
public void SetOverCurrentProtection(string moduleName, double ocpValue)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(moduleName.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::SetOverCurrentProtection() - could not find supply: " + moduleName.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
_powerModuleMap[moduleName.ToUpper()].CurrentLimit = Current.FromAmps(ocpValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="moduleName"></param>
|
||||
/// <param name="ovpValue"></param>
|
||||
public void SetOverVoltageProtection(string moduleName, double ovpValue)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(moduleName.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::SetOverVoltageProtection() - could not find supply: " + moduleName.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
_powerModuleMap[moduleName.ToUpper()].OverVoltageProtection = Voltage.FromVolts(ovpValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the voltage setpoint.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the module.</param>
|
||||
/// <param name="voltage">The desired voltage.</param>
|
||||
public void SetVoltageSetpoint(string name, double volts)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::SetVoltageSetpoint() - could not find supply: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
_powerModuleMap[name.ToUpper()].OutputVoltage = Voltage.FromVolts(volts);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
string errorMsg = "";
|
||||
|
||||
try
|
||||
{
|
||||
//Reset System
|
||||
Reset();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
errorMsg += err.Message + " ";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (KeyValuePair<string, IDCPwr> entry in _powerModuleMap)
|
||||
{
|
||||
entry.Value.Shutdown();
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
errorMsg += err.Message + " ";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
errorMsg += err.Message + " ";
|
||||
}
|
||||
|
||||
_state = State.Uninitialized;
|
||||
|
||||
if (errorMsg != "")
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::ShutdDown() - System " + _name + " had an error: " + errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn off the watchdog capability.
|
||||
/// </summary>
|
||||
public void WatchdogDisable()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn on the watchdog capability.
|
||||
/// </summary>
|
||||
/// <param name="time">The watchdog time in seconds.</param>
|
||||
public void WatchdogEnable(uint time)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds another power supply to the Power Supply System
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="overCurrentProtection"></param>
|
||||
/// <param name="overVoltageProtection"></param>
|
||||
/// <param name="voltageSetpoint"></param>
|
||||
/// <param name="maxVoltageSetpoint"></param>
|
||||
/// <param name="minVoltageSetpoint"></param>
|
||||
/// <param name="moduleNumber"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void AddPowerSupply(string name, double overCurrentProtection, double overVoltageProtection, double voltageSetpoint, double maxVoltageSetpoint, double minVoltageSetpoint, int moduleNumber = -1)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_powerModuleMap.ContainsKey(name.ToUpper()) == true)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::AddPowerSupply() - system already contains a supply named: " + name.ToUpper() + " In System " + _name);
|
||||
}
|
||||
|
||||
// check to see if this index has already been added
|
||||
// would like to ask the IDCPwr object, but that functionality is not exposed in the interface
|
||||
if (_moduleNumbersThatHaveBeenAdded.Contains(moduleNumber) == true)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::AddPowerSupply() - module number has already been added: " + moduleNumber + " In System " + _name);
|
||||
}
|
||||
|
||||
// confirm we are already initialized
|
||||
if (_state != State.Uninitialized)
|
||||
{
|
||||
throw new Exception("PowerSupplySystemSim::AddPowerSupply() - System " + _name + " must be Uninitialized when adding power supplies. Current state is: " + _state.ToString());
|
||||
}
|
||||
|
||||
// create and initialize the power module
|
||||
IDCPwr powerSupply = new PowerSupplySim(name, overCurrentProtection, overVoltageProtection, voltageSetpoint, maxVoltageSetpoint, minVoltageSetpoint, moduleNumber);
|
||||
|
||||
_moduleNumbersThatHaveBeenAdded.Add(moduleNumber);
|
||||
|
||||
_powerModuleMap.Add(name.ToUpper(), powerSupply);
|
||||
|
||||
_powerModuleInitialVoltageSetpoint.Add(name.ToUpper(), voltageSetpoint);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns system name
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetSystemName() => Name;
|
||||
|
||||
/// <summary>
|
||||
/// reads power data
|
||||
/// </summary>
|
||||
/// <param name="moduleName"></param>
|
||||
/// <param name="voltage"></param>
|
||||
/// <param name="voltageSetpoint"></param>
|
||||
/// <param name="current"></param>
|
||||
/// <param name="outputStatus"></param>
|
||||
/// <param name="faultStatus"></param>
|
||||
public void ReadPowerData(string moduleName, out double voltage, out double voltageSetpoint, out double current, out bool outputStatus, out int faultStatus)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// voltage, voltage setpoint, current, output status
|
||||
voltage = MeasureVoltage(moduleName);
|
||||
voltageSetpoint = GetVoltageSetting(moduleName);
|
||||
current = MeasureCurrent(moduleName);
|
||||
outputStatus = IsOutputOn(moduleName);
|
||||
faultStatus = ReadProtectionStatus(moduleName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.PowerSupplySystemSim</AssemblyName>
|
||||
<Product>Power Supply System Sim implementation</Product>
|
||||
<Description>Power Supply System Sim implementation</Description>
|
||||
<OutputType>Library</OutputType>
|
||||
|
||||
<!-- Static versioning (Suitable for Development) -->
|
||||
<!-- Disable the line below for dynamic versioning -->
|
||||
<Version>1.1.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="5.0.0" />
|
||||
<PackageReference Include="Raytheon.Instruments.PowerSupplySystem.Contracts" Version="1.3.0" />
|
||||
<PackageReference Include="Raytheon.Instruments.DCPwr.Contracts" Version="2.7.0" />
|
||||
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,136 @@
|
||||
// **********************************************************************************************************
|
||||
// PowerSupplySystemSimFactory.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 = "PowerSupplySystemSimFactory")]
|
||||
public class PowerSupplySystemSimFactory : 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 PowerSupplySystemSimFactory(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 PowerSupplySystemSimFactory([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(IPowerSupplySystem));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new PowerSupplySystemSim(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 PowerSupplySystemSim(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