Create threads to update GUI
This commit is contained in:
@@ -70,17 +70,22 @@ namespace ProgramLib
|
|||||||
{
|
{
|
||||||
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method...");
|
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method...");
|
||||||
|
|
||||||
Program.Instance().GetPowerSupplyMeasurementManager()[PowerSupplyConstants.POWER_DEVICE.STE_POWER_SUPPLY_SYSTEM].OutputDisable(ProgramLib.PowerSupplyConstants.POWER_DEVICE.STE_PVM_5V);
|
if (Program.Instance()._isUutPwrOn)
|
||||||
// enable front panel
|
|
||||||
Program.Instance().GetPowerSupplyMeasurementManager()[PowerSupplyConstants.POWER_DEVICE.STE_POWER_SUPPLY_SYSTEM].FrontPanelEnabled = true;
|
|
||||||
|
|
||||||
// signal to PowerSupplyReadThread to stop monitoring power
|
|
||||||
Program.Instance()._eventManager[EventManager.Events.UUT_POWER_OFF].Set();
|
|
||||||
|
|
||||||
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Dispatcher.Invoke((Action)delegate
|
|
||||||
{
|
{
|
||||||
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Hide();
|
Program.Instance().GetPowerSupplyMeasurementManager()[PowerSupplyConstants.POWER_DEVICE.STE_POWER_SUPPLY_SYSTEM].OutputDisable(ProgramLib.PowerSupplyConstants.POWER_DEVICE.STE_PVM_5V);
|
||||||
});
|
// enable front panel
|
||||||
|
Program.Instance().GetPowerSupplyMeasurementManager()[PowerSupplyConstants.POWER_DEVICE.STE_POWER_SUPPLY_SYSTEM].FrontPanelEnabled = true;
|
||||||
|
|
||||||
|
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Dispatcher.Invoke((Action)delegate
|
||||||
|
{
|
||||||
|
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
Program.Instance()._eventManager[EventManager.Events.UUT_POWER_ON].Reset();
|
||||||
|
Program.Instance()._eventManager[EventManager.Events.UUT_POWER_OFF].Set();
|
||||||
|
|
||||||
|
Program.Instance()._isUutPwrOn = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -102,9 +107,7 @@ namespace ProgramLib
|
|||||||
{
|
{
|
||||||
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method...");
|
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method...");
|
||||||
|
|
||||||
Program.Instance().GetPowerSupplyMeasurementManager()[PowerSupplyConstants.POWER_DEVICE.STE_POWER_SUPPLY_SYSTEM].ReadPowerSupplyData(ProgramLib.PowerSupplyConstants.POWER_DEVICE.STE_PVM_5V, out double voltage, out double current, out double voltageSetPoint, out bool isOn, out int faultStatus);
|
if (!Program.Instance()._isUutPwrOn)
|
||||||
|
|
||||||
if (!isOn)
|
|
||||||
{
|
{
|
||||||
Task.Factory.StartNew(() => PerformSttoTask());
|
Task.Factory.StartNew(() => PerformSttoTask());
|
||||||
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.IMPEDANCE_CHECK].Dispatcher.Invoke((Action)delegate
|
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.IMPEDANCE_CHECK].Dispatcher.Invoke((Action)delegate
|
||||||
@@ -126,14 +129,20 @@ namespace ProgramLib
|
|||||||
// disable front panel
|
// disable front panel
|
||||||
Program.Instance().GetPowerSupplyMeasurementManager()[PowerSupplyConstants.POWER_DEVICE.STE_POWER_SUPPLY_SYSTEM].FrontPanelEnabled = false;
|
Program.Instance().GetPowerSupplyMeasurementManager()[PowerSupplyConstants.POWER_DEVICE.STE_POWER_SUPPLY_SYSTEM].FrontPanelEnabled = false;
|
||||||
|
|
||||||
// signal to PowerSupplyReadThread to start monitoring power
|
Program.Instance()._eventManager[EventManager.Events.UUT_POWER_OFF].Reset();
|
||||||
Program.Instance()._eventManager[EventManager.Events.UUT_POWER_ON].Set();
|
Program.Instance()._eventManager[EventManager.Events.UUT_POWER_ON].Set();
|
||||||
|
|
||||||
|
Program.Instance()._isUutPwrOn = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception(fatalErrorMsg);
|
throw new Exception(fatalErrorMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("UUT power is already on.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|||||||
@@ -31,13 +31,6 @@ namespace ProgramLib
|
|||||||
{
|
{
|
||||||
private EventWaitHandle[] _events = new EventWaitHandle[Enum.GetValues(typeof(Events)).Cast<int>().Max() + 1];
|
private EventWaitHandle[] _events = new EventWaitHandle[Enum.GetValues(typeof(Events)).Cast<int>().Max() + 1];
|
||||||
|
|
||||||
// specify which event should have to be manually reset
|
|
||||||
List<Events> _manualEventList = new List<Events>
|
|
||||||
{
|
|
||||||
Events.GLOBAL_QUIT,
|
|
||||||
Events.FATAL_FAILURE
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The private constructor
|
/// The private constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -45,12 +38,7 @@ namespace ProgramLib
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < _events.Count(); i++)
|
for (int i = 0; i < _events.Count(); i++)
|
||||||
{
|
{
|
||||||
if (_manualEventList.Contains((Events)i))
|
_events[i] = new ManualResetEvent(false);
|
||||||
{
|
|
||||||
_events[i] = new ManualResetEvent(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
_events[i] = new AutoResetEvent(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,12 @@ namespace ProgramLib
|
|||||||
_threadList.Add(new PowerSupplyReadThread(ps.Name));
|
_threadList.Add(new PowerSupplyReadThread(ps.Name));
|
||||||
_threadList.Last().Start();
|
_threadList.Last().Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_threadList.Add(new PassthroughDataGuiUpdateThread());
|
||||||
|
_threadList.Last().Start();
|
||||||
|
|
||||||
|
_threadList.Add(new PowerSupplyGuiUpdateThread());
|
||||||
|
_threadList.Last().Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ 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
|
||||||
@@ -261,6 +262,11 @@ namespace ProgramLib
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save error message originated from other threads
|
||||||
|
/// </summary>
|
||||||
|
/// <param name=""></param>
|
||||||
|
/// <returns></returns>
|
||||||
internal void SetFatalErrorMsgFromThread(string errorMsg)
|
internal void SetFatalErrorMsgFromThread(string errorMsg)
|
||||||
{
|
{
|
||||||
lock(_fatalErrorMsgFromThreadSyncObj)
|
lock(_fatalErrorMsgFromThreadSyncObj)
|
||||||
|
|||||||
172
Source/Program/Threads/PassthroughDataGuiUpdateThread.cs
Normal file
172
Source/Program/Threads/PassthroughDataGuiUpdateThread.cs
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
// 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 ProgramGui;
|
||||||
|
using ProgramGui.Model;
|
||||||
|
using ProgramGui.ViewModel;
|
||||||
|
using ProgramLib;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProgramLib
|
||||||
|
{
|
||||||
|
internal class PassthroughDataGuiUpdateThread : BasicThread
|
||||||
|
{
|
||||||
|
private enum Events
|
||||||
|
{
|
||||||
|
GLOBAL_QUIT,
|
||||||
|
UUT_POWER_ON,
|
||||||
|
UUT_POWER_OFF,
|
||||||
|
|
||||||
|
// DO NOT change the name
|
||||||
|
// This must be the last member in the enum
|
||||||
|
EVENT_TIMED_OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
private ILogger _logger;
|
||||||
|
private MainWindow _mainWindow;
|
||||||
|
private PassthroughData _passthroughData = null;
|
||||||
|
|
||||||
|
public PassthroughDataGuiUpdateThread()
|
||||||
|
{
|
||||||
|
_logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
_mainWindow = (MainWindow)ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN];
|
||||||
|
|
||||||
|
_passthroughData = new PassthroughData(_mainWindow.datagridPassthroughData.Columns.Count);
|
||||||
|
|
||||||
|
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Dispatcher.Invoke((Action)delegate
|
||||||
|
{
|
||||||
|
_mainWindow._mainWindowViewModel.AddPassthroughData(_passthroughData.GetPassthroughDataModelDict());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
~PassthroughDataGuiUpdateThread()
|
||||||
|
{
|
||||||
|
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DoWork()
|
||||||
|
{
|
||||||
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<Events, EventWaitHandle> eventDict = new Dictionary<Events, EventWaitHandle>();
|
||||||
|
eventDict[Events.GLOBAL_QUIT] = Program.Instance()._eventManager[EventManager.Events.GLOBAL_QUIT];
|
||||||
|
eventDict[Events.UUT_POWER_ON] = Program.Instance()._eventManager[EventManager.Events.UUT_POWER_ON];
|
||||||
|
eventDict[Events.EVENT_TIMED_OUT] = null;
|
||||||
|
|
||||||
|
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(eventDict);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Events id = eventGroup.WaitAny();
|
||||||
|
|
||||||
|
if (id == Events.UUT_POWER_ON)
|
||||||
|
{
|
||||||
|
UpdatePassthroughDataGui();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger?.Error(ex.Message + "\n" + ex.StackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdatePassthroughDataGui()
|
||||||
|
{
|
||||||
|
int pollRateMs = 1000;
|
||||||
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<Events, EventWaitHandle> eventDict = new Dictionary<Events, EventWaitHandle>();
|
||||||
|
eventDict[Events.GLOBAL_QUIT] = Program.Instance()._eventManager[EventManager.Events.GLOBAL_QUIT];
|
||||||
|
eventDict[Events.UUT_POWER_OFF] = Program.Instance()._eventManager[EventManager.Events.UUT_POWER_OFF];
|
||||||
|
eventDict[Events.EVENT_TIMED_OUT] = null;
|
||||||
|
|
||||||
|
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(eventDict);
|
||||||
|
|
||||||
|
Random rnd = new Random();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Events id = eventGroup.WaitAny(pollRateMs);
|
||||||
|
|
||||||
|
if (id == Events.EVENT_TIMED_OUT)
|
||||||
|
{
|
||||||
|
rnd = new Random();
|
||||||
|
|
||||||
|
float num = 70.0f + GenerateRandomFraction();
|
||||||
|
_passthroughData.SetValue(PassthroughData.Variables.VAR1, num.ToString("0.00"));
|
||||||
|
|
||||||
|
Thread.Sleep(100);
|
||||||
|
num = 30.0f + GenerateRandomFraction();
|
||||||
|
_passthroughData.SetValue(PassthroughData.Variables.VAR2, num.ToString("0.00"));
|
||||||
|
Thread.Sleep(200);
|
||||||
|
num = 40.0f + GenerateRandomFraction();
|
||||||
|
_passthroughData.SetValue(PassthroughData.Variables.VAR3, num.ToString("0.00"));
|
||||||
|
Thread.Sleep(100);
|
||||||
|
num = 50.0f + GenerateRandomFraction();
|
||||||
|
_passthroughData.SetValue(PassthroughData.Variables.VAR4, num.ToString("0.00"));
|
||||||
|
Thread.Sleep(100);
|
||||||
|
num = 60.0f + GenerateRandomFraction();
|
||||||
|
_passthroughData.SetValue(PassthroughData.Variables.VAR5, num.ToString("0.00"));
|
||||||
|
Thread.Sleep(200);
|
||||||
|
num = 10.0f + GenerateRandomFraction();
|
||||||
|
_passthroughData.SetValue(PassthroughData.Variables.VAR6, num.ToString("0.00"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex.Message + "\n" + ex.StackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
172
Source/Program/Threads/PowerSupplyGuiUpdateThread.cs
Normal file
172
Source/Program/Threads/PowerSupplyGuiUpdateThread.cs
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
// 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 ProgramGui;
|
||||||
|
using ProgramGui.Model;
|
||||||
|
using ProgramGui.ViewModel;
|
||||||
|
using ProgramLib;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProgramLib
|
||||||
|
{
|
||||||
|
internal class PowerSupplyGuiUpdateThread : BasicThread
|
||||||
|
{
|
||||||
|
private enum Events
|
||||||
|
{
|
||||||
|
GLOBAL_QUIT,
|
||||||
|
UUT_POWER_ON,
|
||||||
|
UUT_POWER_OFF,
|
||||||
|
|
||||||
|
// DO NOT change the name
|
||||||
|
// This must be the last member in the enum
|
||||||
|
EVENT_TIMED_OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
private ILogger _logger;
|
||||||
|
private MainWindow _mainWindow;
|
||||||
|
|
||||||
|
private Dictionary<string, PowerModuleDataModel> _powerModuleToPowerDataModelDict = new Dictionary<string, PowerModuleDataModel>();
|
||||||
|
|
||||||
|
public PowerSupplyGuiUpdateThread()
|
||||||
|
{
|
||||||
|
_logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
_mainWindow = (MainWindow)ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN];
|
||||||
|
|
||||||
|
_powerModuleToPowerDataModelDict["UUT_P20V"] = new PowerModuleDataModel();
|
||||||
|
_powerModuleToPowerDataModelDict["UUT_N20V"] = new PowerModuleDataModel();
|
||||||
|
|
||||||
|
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Dispatcher.Invoke((Action)delegate
|
||||||
|
{
|
||||||
|
_mainWindow._mainWindowViewModel.AddPowerData(_powerModuleToPowerDataModelDict);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
~PowerSupplyGuiUpdateThread()
|
||||||
|
{
|
||||||
|
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DoWork()
|
||||||
|
{
|
||||||
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<Events, EventWaitHandle> eventDict = new Dictionary<Events, EventWaitHandle>();
|
||||||
|
eventDict[Events.GLOBAL_QUIT] = Program.Instance()._eventManager[EventManager.Events.GLOBAL_QUIT];
|
||||||
|
eventDict[Events.UUT_POWER_ON] = Program.Instance()._eventManager[EventManager.Events.UUT_POWER_ON];
|
||||||
|
eventDict[Events.EVENT_TIMED_OUT] = null;
|
||||||
|
|
||||||
|
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(eventDict);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Events id = eventGroup.WaitAny();
|
||||||
|
|
||||||
|
if (id == Events.UUT_POWER_ON)
|
||||||
|
{
|
||||||
|
UpdatePowerSupplyGui();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger?.Error(ex.Message + "\n" + ex.StackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdatePowerSupplyGui()
|
||||||
|
{
|
||||||
|
int pollRateMs = 1000;
|
||||||
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<Events, EventWaitHandle> eventDict = new Dictionary<Events, EventWaitHandle>();
|
||||||
|
eventDict[Events.GLOBAL_QUIT] = Program.Instance()._eventManager[EventManager.Events.GLOBAL_QUIT];
|
||||||
|
eventDict[Events.UUT_POWER_OFF] = Program.Instance()._eventManager[EventManager.Events.UUT_POWER_OFF];
|
||||||
|
eventDict[Events.EVENT_TIMED_OUT] = null;
|
||||||
|
|
||||||
|
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(eventDict);
|
||||||
|
|
||||||
|
Random rnd = new Random();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Events id = eventGroup.WaitAny(pollRateMs);
|
||||||
|
|
||||||
|
if (id == Events.EVENT_TIMED_OUT)
|
||||||
|
{
|
||||||
|
rnd = new Random();
|
||||||
|
|
||||||
|
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_OFF];
|
||||||
|
float num = 20.0f + GenerateRandomFraction();
|
||||||
|
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualVoltage = num.ToString("0.00");
|
||||||
|
_powerModuleToPowerDataModelDict["UUT_P20V"].ExpectedVoltage = "20.0";
|
||||||
|
Thread.Sleep(100);
|
||||||
|
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"].ActualCurrent = num.ToString("0.00");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex.Message + "\n" + ex.StackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,11 +43,9 @@ namespace ProgramLib
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
private MainWindow _mainWindow;
|
|
||||||
private string _powerSupplySystemName;
|
private string _powerSupplySystemName;
|
||||||
|
|
||||||
private Dictionary<string, PowerModuleDataModel> _powerModuleToPowerDataModelDict = new Dictionary<string, PowerModuleDataModel>();
|
|
||||||
private PassthroughData _passthroughData = null;
|
|
||||||
|
|
||||||
public PowerSupplyReadThread(string powerSupplySystemName)
|
public PowerSupplyReadThread(string powerSupplySystemName)
|
||||||
{
|
{
|
||||||
@@ -55,18 +53,6 @@ namespace ProgramLib
|
|||||||
|
|
||||||
_powerSupplySystemName = powerSupplySystemName;
|
_powerSupplySystemName = powerSupplySystemName;
|
||||||
|
|
||||||
_mainWindow = (MainWindow)ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN];
|
|
||||||
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_P20V"] = new PowerModuleDataModel();
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_N20V"] = new PowerModuleDataModel();
|
|
||||||
|
|
||||||
_passthroughData = new PassthroughData(_mainWindow.datagridPassthroughData.Columns.Count);
|
|
||||||
|
|
||||||
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Dispatcher.Invoke((Action)delegate
|
|
||||||
{
|
|
||||||
_mainWindow._mainWindowViewModel.AddPowerData(_powerModuleToPowerDataModelDict);
|
|
||||||
_mainWindow._mainWindowViewModel.AddPassthroughData(_passthroughData.GetPassthroughDataModelDict());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~PowerSupplyReadThread()
|
~PowerSupplyReadThread()
|
||||||
@@ -129,47 +115,8 @@ namespace ProgramLib
|
|||||||
|
|
||||||
if (id == Events.EVENT_TIMED_OUT)
|
if (id == Events.EVENT_TIMED_OUT)
|
||||||
{
|
{
|
||||||
rnd = new Random();
|
Thread.Sleep(100);
|
||||||
|
|
||||||
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_OFF];
|
|
||||||
float num = 20.0f + GenerateRandomFraction();
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualVoltage = num.ToString("0.00");
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_P20V"].ExpectedVoltage = "20.0";
|
|
||||||
Thread.Sleep(100);
|
|
||||||
num = 1.0f + GenerateRandomFraction();
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualCurrent = num.ToString("0.00");
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_P20V"].ExpectedCurrent = "1.0";
|
|
||||||
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"].ActualCurrent = num.ToString("0.00");
|
|
||||||
_powerModuleToPowerDataModelDict["UUT_N20V"].ExpectedCurrent = "1.0";
|
|
||||||
Thread.Sleep(100);
|
|
||||||
num = 70.0f + GenerateRandomFraction();
|
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR1, num.ToString("0.00"));
|
|
||||||
|
|
||||||
Thread.Sleep(100);
|
|
||||||
num = 30.0f + GenerateRandomFraction();
|
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR2, num.ToString("0.00"));
|
|
||||||
Thread.Sleep(200);
|
|
||||||
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_OFF];
|
|
||||||
num = 40.0f + GenerateRandomFraction();
|
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR3, num.ToString("0.00"));
|
|
||||||
Thread.Sleep(100);
|
|
||||||
num = 50.0f + GenerateRandomFraction();
|
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR4, num.ToString("0.00"));
|
|
||||||
Thread.Sleep(100);
|
|
||||||
num = 60.0f + GenerateRandomFraction();
|
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR5, num.ToString("0.00"));
|
|
||||||
Thread.Sleep(200);
|
|
||||||
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_ON];
|
|
||||||
num = 10.0f + GenerateRandomFraction();
|
|
||||||
_passthroughData.SetValue(PassthroughData.Variables.VAR6, num.ToString("0.00"));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
@@ -183,20 +130,5 @@ namespace ProgramLib
|
|||||||
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {_powerSupplySystemName} is exiting...");
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {_powerSupplySystemName} 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -473,8 +473,7 @@
|
|||||||
<Label Grid.Column="2" Grid.ColumnSpan="2" FontSize="10" FontWeight="Bold" Content="Current (A)" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,1,1,1" BorderBrush="#bdbcbd"/>
|
<Label Grid.Column="2" Grid.ColumnSpan="2" FontSize="10" FontWeight="Bold" Content="Current (A)" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,1,1,1" BorderBrush="#bdbcbd"/>
|
||||||
<Label Grid.Row="1" FontSize="10" FontWeight="Bold" Content="Expected" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,0,1,1" BorderBrush="#bdbcbd"/>
|
<Label Grid.Row="1" FontSize="10" FontWeight="Bold" Content="Expected" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,0,1,1" BorderBrush="#bdbcbd"/>
|
||||||
<Label Grid.Row="1" Grid.Column="1" FontSize="10" FontWeight="Bold" Content="Actual" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,0,1,1" BorderBrush="#bdbcbd"/>
|
<Label Grid.Row="1" Grid.Column="1" FontSize="10" FontWeight="Bold" Content="Actual" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,0,1,1" BorderBrush="#bdbcbd"/>
|
||||||
<Label Grid.Row="1" Grid.Column="2" FontSize="10" FontWeight="Bold" Content="Expected" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,0,1,1" BorderBrush="#bdbcbd"/>
|
<Label Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" FontSize="10" FontWeight="Bold" Content="Actual" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,0,1,1" BorderBrush="#bdbcbd"/>
|
||||||
<Label Grid.Row="1" Grid.Column="3" FontSize="10" FontWeight="Bold" Content="Actual" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0,0,1,1" BorderBrush="#bdbcbd"/>
|
|
||||||
|
|
||||||
<!-- DataGrid for Power Data-->
|
<!-- DataGrid for Power Data-->
|
||||||
<DataGrid Grid.Row="2" Grid.ColumnSpan="4" Name="datagridPowerData" AutoGenerateColumns="False" CanUserAddRows="False" IsReadOnly="True" SelectionMode="Extended" SelectionUnit="FullRow" ItemsSource="{Binding _dataGridPowerDatatems}" Width="auto" HorizontalGridLinesBrush="#e9e9e9" VerticalGridLinesBrush="#e9e9e9" HeadersVisibility="None" BorderThickness="0">
|
<DataGrid Grid.Row="2" Grid.ColumnSpan="4" Name="datagridPowerData" AutoGenerateColumns="False" CanUserAddRows="False" IsReadOnly="True" SelectionMode="Extended" SelectionUnit="FullRow" ItemsSource="{Binding _dataGridPowerDatatems}" Width="auto" HorizontalGridLinesBrush="#e9e9e9" VerticalGridLinesBrush="#e9e9e9" HeadersVisibility="None" BorderThickness="0">
|
||||||
@@ -493,8 +492,7 @@
|
|||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn CellStyle="{StaticResource CellStyle}" Header="expectedVoltage" Width="1*" Binding="{Binding ExpectedVoltage}"/>
|
<DataGridTextColumn CellStyle="{StaticResource CellStyle}" Header="expectedVoltage" Width="1*" Binding="{Binding ExpectedVoltage}"/>
|
||||||
<DataGridTextColumn CellStyle="{StaticResource CellStyle}" Header="actualVoltage" Width="1*" Binding="{Binding ActualVoltage}"/>
|
<DataGridTextColumn CellStyle="{StaticResource CellStyle}" Header="actualVoltage" Width="1*" Binding="{Binding ActualVoltage}"/>
|
||||||
<DataGridTextColumn CellStyle="{StaticResource CellStyle}" Header="expectCurrent" Width="1*" Binding="{Binding ExpectedCurrent}"/>
|
<DataGridTextColumn CellStyle="{StaticResource CellStyle}" Header="actualCurrent" Width="2*" Binding="{Binding ActualCurrent}"/>
|
||||||
<DataGridTextColumn CellStyle="{StaticResource CellStyle}" Header="actualCurrent" Width="1*" Binding="{Binding ActualCurrent}"/>
|
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -698,7 +696,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ namespace ProgramGui.Model
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string actualVoltage;
|
private string actualVoltage;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string expectedCurrent;
|
|
||||||
[ObservableProperty]
|
|
||||||
private string actualCurrent;
|
private string actualCurrent;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user