Update GUI with power supply's voltage and current readings
This commit is contained in:
@@ -119,6 +119,8 @@ namespace ProgramLib
|
|||||||
|
|
||||||
if (_sttoSuccess)
|
if (_sttoSuccess)
|
||||||
{
|
{
|
||||||
|
Program.Instance()._powerSupplySharedData.ResetAll();
|
||||||
|
|
||||||
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.IMPEDANCE_CHECK].Dispatcher.Invoke((Action)delegate
|
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.IMPEDANCE_CHECK].Dispatcher.Invoke((Action)delegate
|
||||||
{
|
{
|
||||||
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Show();
|
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Show();
|
||||||
|
|||||||
27
Source/Program/DataDef/PowerSupplyData.cs
Normal file
27
Source/Program/DataDef/PowerSupplyData.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProgramLib
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stores voltage and current reading
|
||||||
|
/// </summary>
|
||||||
|
internal class PowerSupplyData
|
||||||
|
{
|
||||||
|
public double _voltage;
|
||||||
|
public double _current;
|
||||||
|
public Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo _powerSupplyModuleInfo;
|
||||||
|
public bool _initialized;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set data to unitialized
|
||||||
|
/// </summary>
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
_initialized = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
94
Source/Program/DataDef/PowerSupplySharedData.cs
Normal file
94
Source/Program/DataDef/PowerSupplySharedData.cs
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProgramLib
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stores voltage and current reading for each power module
|
||||||
|
/// </summary>
|
||||||
|
internal class PowerSupplySharedData
|
||||||
|
{
|
||||||
|
private object syncObj = new object();
|
||||||
|
private Dictionary<string,object> syncObjDict = new Dictionary<string, object>();
|
||||||
|
private Dictionary<string, PowerSupplyData> _powerSupplyDataDict = new Dictionary<string, PowerSupplyData>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set data for a power supply module
|
||||||
|
/// </summary>
|
||||||
|
public void SetData(string moduleName, double voltage, double current, Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo powerSupplyModuleInfo)
|
||||||
|
{
|
||||||
|
lock (syncObj)
|
||||||
|
{
|
||||||
|
if (!syncObjDict.ContainsKey(moduleName))
|
||||||
|
{
|
||||||
|
// create a mutex for each module
|
||||||
|
syncObjDict[moduleName] = new object();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (syncObjDict[moduleName])
|
||||||
|
{
|
||||||
|
if (!_powerSupplyDataDict.ContainsKey(moduleName))
|
||||||
|
{
|
||||||
|
_powerSupplyDataDict[moduleName] = new PowerSupplyData();
|
||||||
|
}
|
||||||
|
|
||||||
|
_powerSupplyDataDict[moduleName]._voltage = voltage;
|
||||||
|
_powerSupplyDataDict[moduleName]._current = current;
|
||||||
|
_powerSupplyDataDict[moduleName]._initialized = true;
|
||||||
|
_powerSupplyDataDict[moduleName]._powerSupplyModuleInfo = powerSupplyModuleInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get data for a power supply module
|
||||||
|
/// </summary>
|
||||||
|
public PowerSupplyData GetData(string moduleName)
|
||||||
|
{
|
||||||
|
lock (syncObj)
|
||||||
|
{
|
||||||
|
if (!syncObjDict.ContainsKey(moduleName))
|
||||||
|
{
|
||||||
|
// create a mutex for each module
|
||||||
|
syncObjDict[moduleName] = new object();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (syncObjDict[moduleName])
|
||||||
|
{
|
||||||
|
if (!_powerSupplyDataDict.ContainsKey(moduleName))
|
||||||
|
{
|
||||||
|
throw new Exception($"{moduleName} is invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
return _powerSupplyDataDict[moduleName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set each power supply data to uninialized
|
||||||
|
/// </summary>
|
||||||
|
public void ResetAll()
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<string, PowerSupplyData> entry in _powerSupplyDataDict)
|
||||||
|
{
|
||||||
|
lock (syncObj)
|
||||||
|
{
|
||||||
|
if (!syncObjDict.ContainsKey(entry.Key))
|
||||||
|
{
|
||||||
|
// create a mutex for each module
|
||||||
|
syncObjDict[entry.Key] = new object();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (syncObjDict[entry.Key])
|
||||||
|
{
|
||||||
|
entry.Value.Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,8 +26,14 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProgramLib
|
namespace ProgramLib
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Methods to call into actions
|
||||||
|
/// </summary>
|
||||||
public partial class Program
|
public partial class Program
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Power on UUT
|
||||||
|
/// </summary>
|
||||||
public void UutPowerOn()
|
public void UutPowerOn()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -49,6 +55,9 @@ namespace ProgramLib
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Power off UUT
|
||||||
|
/// </summary>
|
||||||
public void UutPowerOff()
|
public void UutPowerOff()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ namespace ProgramLib
|
|||||||
private PowerSupplyMeasurementManager _psManager = null;
|
private PowerSupplyMeasurementManager _psManager = null;
|
||||||
private ProgramGuiManager _guiManager = null;
|
private ProgramGuiManager _guiManager = null;
|
||||||
|
|
||||||
|
internal bool _isUutPwrOn = false;
|
||||||
|
internal PowerSupplySharedData _powerSupplySharedData = new PowerSupplySharedData();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize power supply measurement manager
|
/// Initialize power supply measurement manager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -112,7 +115,7 @@ namespace ProgramLib
|
|||||||
_threadList.Add(new PassthroughDataGuiUpdateThread());
|
_threadList.Add(new PassthroughDataGuiUpdateThread());
|
||||||
_threadList.Last().Start();
|
_threadList.Last().Start();
|
||||||
|
|
||||||
_threadList.Add(new PowerSupplyGuiUpdateThread());
|
_threadList.Add(new PowerSupplyUpdateThread());
|
||||||
_threadList.Last().Start();
|
_threadList.Last().Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ namespace ProgramLib
|
|||||||
internal EventManager _eventManager = new EventManager();
|
internal EventManager _eventManager = new EventManager();
|
||||||
internal FileAndFolderManager _fileAndFolderManager;
|
internal FileAndFolderManager _fileAndFolderManager;
|
||||||
internal IConfigurationFile _programConfig { get; private set; }
|
internal IConfigurationFile _programConfig { get; private set; }
|
||||||
internal bool _isUutPwrOn = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create an instance of this class. Only one instance is allowed
|
/// Create an instance of this class. Only one instance is allowed
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ namespace ProgramLib
|
|||||||
if (id == Events.EVENT_TIMED_OUT)
|
if (id == Events.EVENT_TIMED_OUT)
|
||||||
{
|
{
|
||||||
rnd = new Random();
|
rnd = new Random();
|
||||||
|
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_OFF];
|
||||||
|
|
||||||
float num = 70.0f + GenerateRandomFraction();
|
float num = 70.0f + GenerateRandomFraction();
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR1, num.ToString("0.00"));
|
_passthroughData.SetValue(PassthroughData.Variables.VAR1, num.ToString("0.00"));
|
||||||
@@ -151,6 +152,7 @@ namespace ProgramLib
|
|||||||
num = 50.0f + GenerateRandomFraction();
|
num = 50.0f + GenerateRandomFraction();
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR4, num.ToString("0.00"));
|
_passthroughData.SetValue(PassthroughData.Variables.VAR4, num.ToString("0.00"));
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_ON];
|
||||||
num = 60.0f + GenerateRandomFraction();
|
num = 60.0f + GenerateRandomFraction();
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR5, num.ToString("0.00"));
|
_passthroughData.SetValue(PassthroughData.Variables.VAR5, num.ToString("0.00"));
|
||||||
Thread.Sleep(200);
|
Thread.Sleep(200);
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ namespace ProgramLib
|
|||||||
|
|
||||||
if (IsVoltageWithinLimits(moduleName, voltage))
|
if (IsVoltageWithinLimits(moduleName, voltage))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Program.Instance()._powerSupplySharedData.SetData(moduleName, voltage, current, _powerSupplyModuleInfoDict[moduleName]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace ProgramLib
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class to spawn thread to update power supply data on GUI
|
/// Class to spawn thread to update power supply data on GUI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class PowerSupplyGuiUpdateThread : BasicThread
|
internal class PowerSupplyUpdateThread : BasicThread
|
||||||
{
|
{
|
||||||
private enum Events
|
private enum Events
|
||||||
{
|
{
|
||||||
@@ -53,7 +53,7 @@ namespace ProgramLib
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PowerSupplyGuiUpdateThread()
|
public PowerSupplyUpdateThread()
|
||||||
{
|
{
|
||||||
_logger = LogManager.GetCurrentClassLogger();
|
_logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ namespace ProgramLib
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
~PowerSupplyGuiUpdateThread()
|
~PowerSupplyUpdateThread()
|
||||||
{
|
{
|
||||||
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
|
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ namespace ProgramLib
|
|||||||
|
|
||||||
if (id == Events.UUT_POWER_ON)
|
if (id == Events.UUT_POWER_ON)
|
||||||
{
|
{
|
||||||
UpdatePowerSupplyGui();
|
UpdatePowerSupplyData();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
@@ -113,11 +113,11 @@ namespace ProgramLib
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update GUI with data
|
/// Log and update GUI with power supply data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name=""></param>
|
/// <param name=""></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private void UpdatePowerSupplyGui()
|
private void UpdatePowerSupplyData()
|
||||||
{
|
{
|
||||||
int pollRateMs = 1000;
|
int pollRateMs = 1000;
|
||||||
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
||||||
@@ -138,24 +138,18 @@ namespace ProgramLib
|
|||||||
|
|
||||||
if (id == Events.EVENT_TIMED_OUT)
|
if (id == Events.EVENT_TIMED_OUT)
|
||||||
{
|
{
|
||||||
rnd = new Random();
|
PowerSupplyData data = Program.Instance()._powerSupplySharedData.GetData(PowerSupplyConstants.POWER_DEVICE.STE_PVM_5V.ToString());
|
||||||
|
|
||||||
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_OFF];
|
if (data._initialized)
|
||||||
float num = 20.0f + GenerateRandomFraction();
|
{
|
||||||
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualVoltage = num.ToString("0.00");
|
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualVoltage = data._voltage.ToString("0.00");
|
||||||
_powerModuleToPowerDataModelDict["UUT_P20V"].ExpectedVoltage = "20.0";
|
_powerModuleToPowerDataModelDict["UUT_P20V"].ExpectedVoltage = data._powerSupplyModuleInfo.voltageSetpoint_.ToString("0.00");
|
||||||
Thread.Sleep(100);
|
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualCurrent = data._current.ToString("0.00");
|
||||||
num = 1.0f + GenerateRandomFraction();
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualCurrent = num.ToString("0.00");
|
|
||||||
Thread.Sleep(100);
|
|
||||||
num = 20.0f + GenerateRandomFraction();
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_N20V"].ActualVoltage = num.ToString("0.00");
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_N20V"].ExpectedVoltage = "20.0";
|
|
||||||
Thread.Sleep(200);
|
|
||||||
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_ON];
|
|
||||||
|
|
||||||
num = 5.0f + GenerateRandomFraction();
|
_powerModuleToPowerDataModelDict["UUT_N20V"].ActualVoltage = data._voltage.ToString("0.00");
|
||||||
_powerModuleToPowerDataModelDict["UUT_N20V"].ActualCurrent = num.ToString("0.00");
|
_powerModuleToPowerDataModelDict["UUT_N20V"].ExpectedVoltage = data._powerSupplyModuleInfo.voltageSetpoint_.ToString("0.00");
|
||||||
|
_powerModuleToPowerDataModelDict["UUT_N20V"].ActualCurrent = data._current.ToString("0.00");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
@@ -168,21 +162,5 @@ namespace ProgramLib
|
|||||||
|
|
||||||
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
|
||||||
}
|
}
|
||||||
|
|
||||||
static float GenerateRandomFraction()
|
|
||||||
{
|
|
||||||
Random rnd = new Random();
|
|
||||||
int randNum = 0;
|
|
||||||
const int minimum = 1;
|
|
||||||
|
|
||||||
randNum = rnd.Next(20);
|
|
||||||
|
|
||||||
if (randNum <= minimum)
|
|
||||||
{
|
|
||||||
randNum += minimum;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (float)(1.0 / (float)randNum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user