My improved version of PowerSupply and TcpClient implementation
This commit is contained in:
@@ -0,0 +1,250 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments.PowerSupplies
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to simulate any power supply module
|
||||
/// </summary>
|
||||
class PowerSupplyModuleSim : PowerSupplyModule
|
||||
{
|
||||
private List<string> _groupedModules;
|
||||
private List<string> _coupledModules;
|
||||
private string _powerSupplySystemName;
|
||||
private bool _frontPanelEnabled = true;
|
||||
|
||||
private ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public PowerSupplyModuleSim(string iniFilePath, string powerSupplySystemName)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_powerSupplySystemName = powerSupplySystemName;
|
||||
|
||||
IConfigurationFile config = new ConfigurationFile(iniFilePath);
|
||||
|
||||
string moduleDef = config.ReadValue(PowerSupplyConfigIni.GENERAL.ToString(), PowerSupplyConfigIni.MODULE_DEFINITION.ToString());
|
||||
string coupledModules = config.ReadValue(PowerSupplyConfigIni.GENERAL.ToString(), PowerSupplyConfigIni.COUPLED_MODULES.ToString());
|
||||
string groupedModules = config.ReadValue(PowerSupplyConfigIni.GENERAL.ToString(), PowerSupplyConfigIni.GROUPED_MODULES.ToString());
|
||||
|
||||
PowerModules = moduleDef.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
_coupledModules = coupledModules.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
_groupedModules = groupedModules.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
|
||||
if (_groupedModules.Count() > 1)
|
||||
{
|
||||
PowerModules.Clear();
|
||||
// since modules are grouped, we pick the first module as the representative module
|
||||
PowerModules.Add(_groupedModules[0]);
|
||||
}
|
||||
|
||||
// build the power module map
|
||||
string moduleIndex = "";
|
||||
double ovp = 0.0;
|
||||
double ocp = 0.0;
|
||||
double voltageSetPoint = 0.0;
|
||||
double voltageSlewRate = 0.0;
|
||||
|
||||
double minVoltage = 0.0;
|
||||
double maxVoltage = 0.0;
|
||||
double minCurrent = 0.0;
|
||||
double maxCurrent = 0.0;
|
||||
|
||||
for (int i = 0; i < PowerModules.Count(); i++)
|
||||
{
|
||||
string moduleName = PowerModules[i];
|
||||
|
||||
moduleIndex = config.ReadValue(moduleName, PowerSupplyConfigIni.INDEX.ToString());
|
||||
Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.OCP.ToString()), out ocp);
|
||||
Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.OVP.ToString()), out ovp);
|
||||
Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.VOLTAGE_SETPOINT.ToString()), out voltageSetPoint);
|
||||
Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.VOLTAGE_SLEW_RATE.ToString()), out voltageSlewRate);
|
||||
Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.MIN_VOLTAGE.ToString()), out minVoltage);
|
||||
Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.MAX_VOLTAGE.ToString()), out maxVoltage);
|
||||
Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.MIN_CURRENT.ToString()), out minCurrent);
|
||||
Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.MAX_CURRENT.ToString()), out maxCurrent);
|
||||
|
||||
PowerModuleInfoDict[moduleName] = new Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo(moduleIndex, ocp, ovp, voltageSetPoint, voltageSlewRate, minVoltage, maxVoltage, minCurrent, maxCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable or Disable Front Panel
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public override bool DisplayEnabled
|
||||
{
|
||||
set { SemObj?.Release(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable or disable Front Panel
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public override bool FrontPanelEnabled
|
||||
{
|
||||
set {_frontPanelEnabled = value; SemObj?.Release(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn on power module's output
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public override void On()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (SyncObj)
|
||||
{
|
||||
CheckActivePowerModuleValidity();
|
||||
|
||||
if (_coupledModules.Contains(ActivePowerModule))
|
||||
{
|
||||
foreach (string module in _coupledModules)
|
||||
{
|
||||
PowerModuleInfoDict[module].isOn_ = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
PowerModuleInfoDict[ActivePowerModule].isOn_ = true;
|
||||
}
|
||||
}
|
||||
finally { SemObj?.Release(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn off power module's output
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public override void Off()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (SyncObj)
|
||||
{
|
||||
CheckActivePowerModuleValidity();
|
||||
|
||||
if (_coupledModules.Contains(ActivePowerModule))
|
||||
{
|
||||
foreach (string module in _coupledModules)
|
||||
{
|
||||
PowerModuleInfoDict[module].isOn_ = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
PowerModuleInfoDict[ActivePowerModule].isOn_ = false;
|
||||
}
|
||||
}
|
||||
finally { SemObj?.Release(); };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform self test
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
public override SelfTestResult PerformSelfTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (SyncObj)
|
||||
{
|
||||
SelfTestResult = SelfTestResult.Pass;
|
||||
}
|
||||
}
|
||||
finally { SemObj?.Release(); };
|
||||
|
||||
return SelfTestResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read voltage
|
||||
/// </summary>
|
||||
/// <param></param>
|
||||
/// <returns></returns>
|
||||
protected override double ReadVoltage()
|
||||
{
|
||||
double val = 0.0;
|
||||
|
||||
lock (SyncObj)
|
||||
{
|
||||
if (PowerModuleInfoDict[ActivePowerModule].isOn_)
|
||||
val = PowerModuleInfoDict[ActivePowerModule].voltageSetpoint_;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read current
|
||||
/// </summary>
|
||||
/// <param></param>
|
||||
/// <returns></returns>
|
||||
protected override double ReadCurrent()
|
||||
{
|
||||
double val = 0.0;
|
||||
|
||||
lock (SyncObj)
|
||||
{
|
||||
if (PowerModuleInfoDict[ActivePowerModule].isOn_)
|
||||
val = (PowerModuleInfoDict[ActivePowerModule].currentLowerLimit_ + PowerModuleInfoDict[ActivePowerModule].currentUpperLimit_) / 2.0;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read protection status
|
||||
/// </summary>
|
||||
/// <param></param>
|
||||
/// <returns></returns>
|
||||
protected override int ReadProtectionStatus()
|
||||
{
|
||||
lock (SyncObj)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get error code
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
protected override string GetErrorCode(out int errorCode)
|
||||
{
|
||||
lock (SyncObj)
|
||||
{
|
||||
errorCode = 0;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
119
Source/DucLib/PowerSupplies/PowerSupplySim/PowerSupplySim.cs
Normal file
119
Source/DucLib/PowerSupplies/PowerSupplySim/PowerSupplySim.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments.PowerSupplies
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to simulate any power supply system
|
||||
/// </summary>
|
||||
public class PowerSupplySim : PowerSupply
|
||||
{
|
||||
private string _iniFilePath;
|
||||
|
||||
private static ILogger _logger;
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public PowerSupplySim(string deviceInstanceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceInstanceName;
|
||||
_logger = logger;
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
_iniFilePath = Path.Combine(assemblyFolder,_configuration.GetConfigurationValue(deviceInstanceName, "IniFilePath"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform shutdown
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
public override void Shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform reset
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
public override void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear errors
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
public override bool ClearErrors()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Group or couple modules as specified in config file
|
||||
/// Gather information for each power module from config file
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
public override void Initialize()
|
||||
{
|
||||
_powerSupplyModule = new PowerSupplyModuleSim(_iniFilePath, Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implement Indexer to obtain a power module
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
public override PowerSupplyModule this[object powerDeviceId]
|
||||
{
|
||||
get
|
||||
{
|
||||
string powerDeviceName = String.Empty;
|
||||
|
||||
if (powerDeviceId != null && (powerDeviceId.GetType().IsEnum || powerDeviceId is string))
|
||||
{
|
||||
powerDeviceName = powerDeviceId.ToString();
|
||||
}
|
||||
else if (powerDeviceId != null)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(powerDeviceId)} must be null or enumerated or string type");
|
||||
}
|
||||
|
||||
_powerSupplyModule.GetSemphamore().WaitOne();
|
||||
|
||||
if (powerDeviceId != null)
|
||||
_powerSupplyModule.SetActivePowerModule(powerDeviceName);
|
||||
|
||||
return _powerSupplyModule;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<OutputType>Library</OutputType>
|
||||
<AssemblyName>Raytheon.Instruments.PowerSupplies.Simulation</AssemblyName>
|
||||
<Product>Power Supply Simulation</Product>
|
||||
<Description>Power Supply Simulation</Description>
|
||||
|
||||
<!-- Dynamic Versioning (Suitable for Release) -->
|
||||
<!-- <Version>$(Version)$(Suffix)</Version> -->
|
||||
|
||||
<!-- Static Versioning (Suitable for Development) -->
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<PackageReference Include="NLog" Version="5.0.0" />
|
||||
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
|
||||
|
||||
<!--
|
||||
<PackageReference Include="Raytheon.Instruments.PowerSupply.Contracts" Version="1.1.0" />
|
||||
-->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PowerSupplyBasic\PowerSupplyBasic.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,114 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Raytheon.Instruments.PowerSupplies
|
||||
{
|
||||
[ExportInstrumentFactory(ModelNumber = "PowerSupplySimulationFactory")]
|
||||
public class PowerSupplySimulationFactory : IInstrumentFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// The supported interfaces
|
||||
/// </summary>
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
private static ILogger _logger;
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
public PowerSupplySimulationFactory(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 PowerSupplySimulationFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
if (NLog.LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(PowerSupply));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public object GetInstrument(string name, bool simulateHw)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new PowerSupplySim(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, $"Unable to construct {name} instrument instance");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets supported interfaces
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
return _supportedInterfaces.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns confiuration 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