MagFluxToolbox: - start of test implementation

This commit is contained in:
Thomas Wiedebusch
2023-04-27 06:56:18 +02:00
parent d9c4839a28
commit f4cf815bbc
14 changed files with 611 additions and 724 deletions
+2 -248
View File
@@ -32,11 +32,6 @@ namespace Xylem.Common.Ui.MagFluxToolBox
private readonly Boolean _updateGui = true;
private Boolean _tryConnectPcb;
private Boolean _lutFileSuccessfulWritten;
private const String StrUpdateErrorMessage = "METROLOGY LOOKUP TABLE UPDATE FAILED!";
private const String StrUpdateSuccessMessage = "Metrology lookup table successfulley written!";
private const String StrLutFileInvalid = "LUT FILE INVALID";
private const String StrLutFileValid = "LUT file loaded";
// external update remarks form
// private readonly FrmHistory _frmHistory = new FrmHistory();
@@ -79,12 +74,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox
lblConnectPcb.ForeColor = Color.Red;
lblWaitingForMeterResponse.Visible = false;
btnConnect.Enabled = true;
btnDownloadLutFile.ForeColor = Color.DarkGreen;
btnStopFwUpdate.ForeColor = Color.Red;
SetControlDownloadsLocked();
btnStopFwUpdate.Enabled = false;
btnOpenLutFile.Enabled = true;
btnClearDisplay.Enabled = false;
tbxPcbId.Visible = false;
}
@@ -118,38 +108,21 @@ namespace Xylem.Common.Ui.MagFluxToolBox
private void SetControlDownloadsLocked()
{
btnDownloadLutFile.Enabled = false;
btnStopFwUpdate.Enabled = false;
btnConnect.Enabled = true;
}
private void SetControlsDownloadIsOngoing()
{
btnConnect.Enabled = false;
btnOpenLutFile.Enabled = false;
btnDownloadLutFile.Enabled = false;
btnClearDisplay.Enabled = false;
btnStopFwUpdate.Enabled = true;
}
private void SetControlsDownloadIsFinished()
{
btnConnect.Enabled = true;
btnOpenLutFile.Enabled = true;
btnDownloadLutFile.Enabled = true;
btnStopFwUpdate.Enabled = false;
btnClearDisplay.Enabled = true;
}
private void SetControlsDownloadEnabled()
{
btnConnect.Enabled = true;
btnOpenLutFile.Enabled = true;
btnDownloadLutFile.Enabled = true;
btnStopFwUpdate.Enabled = false;
btnClearDisplay.Enabled = true;
}
#endregion
@@ -166,7 +139,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox
return;
}
lblOverall.Text = @"Establish data base connection..";
//lblOverall.Text = @"Establish data base connection..";
Task.Factory.StartNew(() =>
{
@@ -258,8 +231,6 @@ namespace Xylem.Common.Ui.MagFluxToolBox
{
_tryConnectPcb = false;
ProcessViewControl(false);
btnClearDisplay.Enabled = true;
}));
}
}
@@ -525,69 +496,8 @@ namespace Xylem.Common.Ui.MagFluxToolBox
_resetTimeMeasurement = false;
}
Connect();
}
private void btnOpenLutFile_Click(Object sender, EventArgs e)
{
//if (dlgOpenLuFile.ShowDialog() != DialogResult.OK)
//{
// return;
//}
//var lutFilePathName = dlgOpenLuFile.FileName;
//lblLutFileLoadedInfo.Text = "";
//tbxLutFilePathName.Text = lutFilePathName;
//if (_meterLutUpdate == null)
//{
// _meterLutUpdate = new MeterLutUpdate(_magFluxMeter);
// _meterLutUpdate.OnProcessUpdate += ProcessUpdate_Event;
//}
//if (_meterLutUpdate == null)
//{
// return;
//}
//if (_meterLutUpdate.LoadLutFile(lutFilePathName))
//{
// lblLutFileLoadedInfo.ForeColor = Color.Green;
// lblLutFileLoadedInfo.Text = StrLutFileValid;
// tbxFileCrc.Text = $@"0x{_meterLutUpdate.LutFile.FileCrc:X4}";
// tbxFileMeterSize.Text = MeterSizeConverter.ConvertMeterSizeEnumToSizeName(_meterLutUpdate.LutFile.MeterSize);
// _lutFileValid = true;
// LogText("File Meter Size: " + tbxFileMeterSize.Text);
// LogText("File LUT CRC: " + tbxFileCrc.Text);
// LogText(StrSeparator);
//}
//else
//{
// var txt = "";
// if (!string.IsNullOrEmpty(_meterLutUpdate?.ErrorMessage))
// {
// txt += _meterLutUpdate?.ErrorMessage;
// }
// else
// {
// txt = StrLutFileInvalid;
// }
// LogErrorText(txt);
// lblLutFileLoadedInfo.ForeColor = Color.Red;
// lblLutFileLoadedInfo.Text = txt;
// tbxFileCrc.Text = @" --- ";
// tbxFileMeterSize.Text = @" --- ";
// _lutFileValid = false;
//}
//CheckUpdateEnabled();
//_resetTimeMeasurement = true;
}
/// <summary>
/// Download LUT file
/// </summary>
@@ -600,22 +510,11 @@ namespace Xylem.Common.Ui.MagFluxToolBox
return;
}
lblLutFileLoadedInfo.Text = "";
SetControlsDownloadIsOngoing();
StartStopDownload(true);
_startTime = DateTimeOffset.UtcNow;
_resetTimeMeasurement = false;
}
private void btnStopFwUpdate_Click(Object sender, EventArgs e)
{
// if (_meterLutUpdate != null)
// {
// _meterLutUpdate.StopUpdateProcess = true;
// }
}
#endregion
@@ -646,6 +545,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox
/// </summary>
public MessageBoxIcon Icon;
}
/// <summary>
/// Message pop up event handler
/// </summary>
@@ -667,152 +567,6 @@ namespace Xylem.Common.Ui.MagFluxToolBox
#endregion
private void SwitchView(Object sender, EventArgs e)
{
btnLoadfromDb.Enabled = false;
var file = rbtFile.Checked;
cbxDbLuts.Visible = !file;
lblSelectDb.Visible = !file;
btnLoadfromDb.Visible = !file;
lvlSelechtFile.Visible = file;
tbxLutFilePathName.Visible = file;
btnOpenLutFile.Visible = file;
if (!file)
{
LoadDbLuts(rbtProd.Checked);
}
}
private void LoadDbLuts(Boolean prod)
{
//var sbUrl = new StringBuilder();
//sbUrl.Append("http://10.49.40.25/MeterProcessState/api/FileUpToDate/GetLutFiles");
////sbUrl.Append("http://localhost:56011/api/FileUpToDate/GetLutFiles");
////sbUrl.Append($"?DataLength={_DataLength}");
////sbUrl.Append($"&version={_Version}");
////sbUrl.Append($"&crc={_FileCrc}");
////sbUrl.Append($"&Metersize={_MeterSize.GetHashCode()}");
////sbUrl.Append($"&Region={_StrLutRegion}");
//try
//{
// var ret = LocalWebRequest.GetRequest(sbUrl.ToString(), 80000);
// var a = JsonConvert.DeserializeObject<List<CordonelMetrologyLut>>(ret);
// cbxDbLuts.SelectedIndex = -1;
// cbxDbLuts.Items.Clear();
// foreach (var item in a)
// {
// if (!prod || item.CurrentVersionForProd)
// {
// cbxDbLuts.Items.Add(item);
// }
// }
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
}
private void cbxDbLuts_SelectedIndexChanged(Object sender, EventArgs e)
{
//if (cbxDbLuts.SelectedItem is CordonelMetrologyLut)
//{
// btnLoadfromDb.Enabled = true;
//}
//else
//{
// btnLoadfromDb.Enabled = false;
//}
}
private void btnLoadfromDb_Click(Object sender, EventArgs e)
{
//if (cbxDbLuts.SelectedItem is CordonelMetrologyLut lut)
//{
// lblLutFileLoadedInfo.Text = "";
// tbxLutFilePathName.Text = $"fromDB{lut.FileName}";
// if (_meterLutUpdate == null)
// {
// _meterLutUpdate = new MeterLutUpdate(_magFluxMeter);
// _meterLutUpdate.OnProcessUpdate += ProcessUpdate_Event;
// }
// if (_meterLutUpdate == null)
// {
// return;
// }
// if (_meterLutUpdate.LoadLutFromStream(lut.FileName, lut.FileContent.ToList()))
// {
// lblLutFileLoadedInfo.ForeColor = Color.Green;
// lblLutFileLoadedInfo.Text = StrLutFileValid;
// tbxFileCrc.Text = $@"0x{_meterLutUpdate.LutFile.FileCrc:X4}";
// tbxFileMeterSize.Text = MeterSizeConverter.ConvertMeterSizeEnumToSizeName(_meterLutUpdate.LutFile.MeterSize);
// _lutFileValid = true;
// LogText("File Meter Size: " + tbxFileMeterSize.Text);
// LogText("File LUT CRC: " + tbxFileCrc.Text);
// LogText(StrSeparator);
// }
// else
// {
// var txt = "";
// if (!string.IsNullOrEmpty(_meterLutUpdate?.ErrorMessage))
// {
// txt += _meterLutUpdate?.ErrorMessage;
// }
// else
// {
// txt = StrLutFileInvalid;
// }
// LogErrorText(txt);
// lblLutFileLoadedInfo.ForeColor = Color.Red;
// lblLutFileLoadedInfo.Text = txt;
// tbxFileCrc.Text = @" --- ";
// tbxFileMeterSize.Text = @" --- ";
// _lutFileValid = false;
// }
// CheckUpdateEnabled();
// _resetTimeMeasurement = true;
//}
}
private void rbtProd_CheckedChanged(Object sender, EventArgs e)
{
}
private void btnClearDisplay_Click(Object sender, EventArgs e)
{
// if (_magFluxMeter == null)
// return;
// lblOverall.Text = @"Set display to normal operation";
// lblOverall.Visible = true;
// Update();
// if (!_magFluxMeter.IsLoggedOn)
// {
// _magFluxMeter.ReLogin();
// }
// _magFluxMeter.SetLcdText(true, new Byte[] { 0x00, 0x00, 0x00, 0x00 });
// _magFluxMeter.Logout();
// lblOverall.Visible = false;
}
}
}