My improved version of PowerSupply and TcpClient implementation

This commit is contained in:
Duc
2025-03-13 17:41:23 -07:00
parent 6419acb073
commit fd85735c93
18 changed files with 2249 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
/*-------------------------------------------------------------------------
// 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 System.Text;
using System.Threading.Tasks;
namespace Raytheon.Instruments
{
/// <summary>
/// Base class that defines interface for power supply systems
/// </summary>
public abstract class PowerSupply : Instrument
{
protected PowerSupplyModule _powerSupplyModule;
/// <summary>
/// Implement Indexer in order to access a specific power module
/// </summary>
/// <param></param>
/// <returns></returns>
public virtual PowerSupplyModule this[object i]
{
get { return null; }
}
/// <summary>
/// Get power supply module info dictionary
/// </summary>
/// <param></param>
/// <returns></returns>
public Dictionary<string, PowerSupplies.PowerSupplyModuleInfo> GetPowerSupplyModuleInfoDict()
{
return _powerSupplyModule.PowerModuleInfoDict;
}
/// <summary>
/// Get power supply module names
/// </summary>
/// <param></param>
/// <returns></returns>
public List<string> GetPowerSupplyModuleNames()
{
return _powerSupplyModule.PowerModules;
}
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<OutputType>Library</OutputType>
<AssemblyName>Raytheon.Instruments.PowerSupplyBasic</AssemblyName>
<Description>PowerSupply Basic</Description>
<Product>PowerSupply Basic</Product>
<Version>1.1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Raytheon.Communication.Rpc.Contracts" Version="1.*" />
<PackageReference Include="Raytheon.Communication.Ums.Core.Contracts" Version="1.*" />
<PackageReference Include="Raytheon.Communication.Ums.Rpc.Attributes" Version="1.*" />
<PackageReference Include="Raytheon.Instruments.Contracts" Version="1.6.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,47 @@
/*-------------------------------------------------------------------------
// 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 System.Text;
using System.Threading.Tasks;
namespace Raytheon.Instruments.PowerSupplies
{
public enum PowerSupplyConfigIni
{
// list all the sections here
GENERAL,
// list all the keys here
ETHERNET_ADDRESS,
ETHERNET_PORT,
MODULE_DEFINITION,
COUPLED_MODULES,
GROUPED_MODULES,
INDEX,
OCP,
OVP,
VOLTAGE_SETPOINT,
VOLTAGE_SLEW_RATE,
MIN_VOLTAGE,
MAX_VOLTAGE,
MIN_CURRENT,
MAX_CURRENT
}
}

View File

@@ -0,0 +1,31 @@
/*-------------------------------------------------------------------------
// 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 System.Text;
using System.Threading.Tasks;
namespace Raytheon.Instruments.PowerSupplies
{
public enum PowerSupplyConfigXml
{
// list all the keys here
INI_FILE_PATH
}
}

View File

@@ -0,0 +1,207 @@
/*-------------------------------------------------------------------------
// 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 Raytheon.Instruments.PowerSupplies;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Raytheon.Instruments
{
/// <summary>
/// Base class that defines interface for power supply modules
/// </summary>
public abstract class PowerSupplyModule
{
protected Semaphore SemObj = new System.Threading.Semaphore(initialCount: 1, maximumCount: 1);
protected object SyncObj = new object();
protected string ActivePowerModule;
public List<string> PowerModules { get; protected set; }
public Dictionary<string, PowerSupplyModuleInfo> PowerModuleInfoDict { get; protected set; }
/// <summary>
/// Constructor
/// </summary>
public PowerSupplyModule()
{
PowerModuleInfoDict = new Dictionary<string, PowerSupplyModuleInfo>();
}
/// <summary>
/// DisplayEnabled - some instruments will be no-op, but likely needed on all
/// will shut down any display on the hardware to hide any
/// classified information if visible
/// </summary>
public virtual bool DisplayEnabled
{
get;
set;
}
/// <summary>
/// FrontPanelEnabled - some instruments will be no-op, but likely needed on all
/// has the ability to disable any panel buttons, so that
/// the hardware may not be changed by human touch
/// </summary>
public virtual bool FrontPanelEnabled
{
private get;
set;
}
/// <summary>
/// SelfTestResult - end result of the hardware self test performed
/// </summary>
public SelfTestResult SelfTestResult
{
get;
set;
}
/// <summary>
/// PerformSelfTest - do a hardware self test
/// </summary>
/// <returns>result of the self test</returns>
public abstract SelfTestResult PerformSelfTest();
/// <summary>
/// Set active module
/// </summary>
/// <param></param>
/// <returns></returns>
public void SetActivePowerModule(string activePowerModule)
{
ActivePowerModule = activePowerModule;
}
/// <summary>
/// Check if active module is valid
/// </summary>
/// <param></param>
/// <returns></returns>
protected void CheckActivePowerModuleValidity()
{
if (ActivePowerModule == null || ActivePowerModule.Length == 0)
throw new Exception($"{nameof(ActivePowerModule)} is not set");
if (!PowerModuleInfoDict.ContainsKey(ActivePowerModule))
throw new Exception($"Invalid power module: {ActivePowerModule}");
}
/// <summary>
/// Return semaphore
/// </summary>
/// <param></param>
/// <returns></returns>
public Semaphore GetSemphamore() { return SemObj; }
/// <summary>
/// Turn on power module's output
/// </summary>
/// <param></param>
/// <returns></returns>
public abstract void On();
/// <summary>
/// Turn off power module's output
/// </summary>
/// <param></param>
/// <returns></returns>
public abstract void Off();
/// <summary>
/// Determine if module's output is on
/// </summary>
/// <param></param>
/// <returns></returns>
protected virtual bool IsOutputOn()
{
bool isOn = false;
lock (SyncObj)
{
CheckActivePowerModuleValidity();
isOn = PowerModuleInfoDict[ActivePowerModule].isOn_;
}
return isOn;
}
/// <summary>
/// Read power supply module's data all at once
/// </summary>
/// <param></param>
/// <returns></returns>
public virtual void ReadPowerSupplyData(out double volts, out double current, out double voltSetpoint, out bool isOn, out int faultStatus)
{
volts = 0.0;
current = 0.0;
voltSetpoint = 0.0;
isOn = false;
faultStatus = 0;
try
{
lock (SyncObj)
{
CheckActivePowerModuleValidity();
volts = ReadVoltage();
current = ReadCurrent();
voltSetpoint = PowerModuleInfoDict[ActivePowerModule].voltageSetpoint_;
isOn = IsOutputOn();
faultStatus = ReadProtectionStatus();
}
}
finally { SemObj?.Release(); };
}
/// <summary>
/// Read voltage
/// </summary>
/// <param></param>
/// <returns></returns>
protected abstract double ReadVoltage();
/// <summary>
/// Read current
/// </summary>
/// <param></param>
/// <returns></returns>
protected abstract double ReadCurrent();
/// <summary>
/// Read protection status
/// </summary>
/// <param></param>
/// <returns></returns>
protected abstract int ReadProtectionStatus();
/// <summary>
/// Get error code
/// </summary>
/// <param></param>
/// <returns></returns>
protected abstract string GetErrorCode(out int errorCode);
}
}

View File

@@ -0,0 +1,70 @@
/*-------------------------------------------------------------------------
// 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 System.Text;
using System.Threading.Tasks;
namespace Raytheon.Instruments.PowerSupplies
{
public class PowerSupplyModuleInfo
{
public PowerSupplyModuleInfo()
{
overCurrentProtection_ = -1.0;
overVoltageProtection_ = -1.0;
voltageSetpoint_ = -1.0;
voltageSlewRate_ = -1.0;
voltageLowerLimit_ = -1.0;
voltageUpperLimit_ = -1.0;
currentLowerLimit_ = -1.0;
currentUpperLimit_ = -1.0;
isOn_ = false;
faultStatus = -1;
}
public PowerSupplyModuleInfo(string moduleIndex, double overCurrentProtection, double overVoltageProtection, double voltageSetpoint, double voltageSlewRate, double minVoltage, double maxVoltage, double minCurrent, double maxCurrent)
{
overCurrentProtection_ = overCurrentProtection;
overVoltageProtection_ = overVoltageProtection;
voltageSetpoint_ = voltageSetpoint;
voltageSlewRate_ = voltageSlewRate;
voltageLowerLimit_ = minVoltage;
voltageUpperLimit_ = maxVoltage;
currentLowerLimit_ = minCurrent;
currentUpperLimit_ = maxCurrent;
isOn_ = false;
faultStatus = -1;
moduleNameFormat = "(@" + moduleIndex + ")";
}
public string moduleNameFormat;
public double overCurrentProtection_;
public double overVoltageProtection_;
public double voltageLowerLimit_;
public double voltageUpperLimit_;
public double currentLowerLimit_;
public double currentUpperLimit_;
public double voltageSetpoint_;
public double voltageSlewRate_;
public bool isOn_;
public int faultStatus;
}
}