Create threads to update GUI
This commit is contained in:
@@ -43,11 +43,9 @@ namespace ProgramLib
|
||||
}
|
||||
|
||||
private ILogger _logger;
|
||||
private MainWindow _mainWindow;
|
||||
|
||||
private string _powerSupplySystemName;
|
||||
|
||||
private Dictionary<string, PowerModuleDataModel> _powerModuleToPowerDataModelDict = new Dictionary<string, PowerModuleDataModel>();
|
||||
private PassthroughData _passthroughData = null;
|
||||
|
||||
public PowerSupplyReadThread(string powerSupplySystemName)
|
||||
{
|
||||
@@ -55,18 +53,6 @@ namespace ProgramLib
|
||||
|
||||
_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()
|
||||
@@ -129,47 +115,8 @@ namespace ProgramLib
|
||||
|
||||
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
|
||||
break;
|
||||
@@ -183,20 +130,5 @@ namespace ProgramLib
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user