858 lines
31 KiB
C#
858 lines
31 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.DataTypes;
|
|
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments;
|
|
using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore;
|
|
using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore.Consts;
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
|
using Xylem.Common.Utils.ProcessExec.EventArguments;
|
|
|
|
|
|
namespace Xylem.Common.Ui.MagFluxToolBox
|
|
{
|
|
/// <summary>
|
|
/// Test form for MagFlux operation
|
|
/// </summary>
|
|
public partial class FrmTest : Form
|
|
{
|
|
#region Variables
|
|
|
|
private const String HeaderRefFlow = @"Ref Flow [m³/h]";
|
|
private const String HeaderDutFlow = @"DUT Flow [m³/h]";
|
|
|
|
private const String StrBtnChange = "Change";
|
|
private const String StrBtnSet = "Set";
|
|
|
|
/// <summary>
|
|
/// Reference to list of calibration points in cubic meters per hour.
|
|
/// </summary>
|
|
private List<Calibration> _calibPointsCmPerH;
|
|
|
|
private DataTable _dataTableCalibPoints;
|
|
|
|
private readonly MeterBatch _meterBatch = new MeterBatch();
|
|
private MagFluxMeter _magFluxMeter;
|
|
private const String StrConnecting = "Connecting to PCB";
|
|
private const String StrNotConnected = "NOT CONNECTED";
|
|
private const String StrOverallProcess = "Overall Process";
|
|
|
|
private UInt32 _lastState;
|
|
private DateTimeOffset _startTime;
|
|
private Boolean _resetTimeMeasurement;
|
|
private readonly Boolean _updateGui = true;
|
|
|
|
private Boolean _tryConnectPcb;
|
|
|
|
// external update remarks form
|
|
// private readonly FrmHistory _frmHistory = new FrmHistory();
|
|
|
|
private readonly Version _version;
|
|
|
|
// status information
|
|
private static readonly Color ColorDefault = Color.Black;
|
|
private static readonly Color ColorSuccess = Color.Green;
|
|
private static readonly Color ColorProcessFailed = Color.Red;
|
|
//private static readonly Color ColorOngoingProcess = Color.Blue;
|
|
//private static readonly Color ColorUnknownStatus = Color.Gray;
|
|
//private const String SuccessSign = @"✔";
|
|
//private const String FailedSign = @"✘";
|
|
|
|
private const String StrSeparator = "-----------------------------------------------------" +
|
|
"-----------------------------------------------------";
|
|
#endregion
|
|
|
|
#region FormControls
|
|
/// <summary>
|
|
/// Ctor FW update
|
|
/// </summary>
|
|
public FrmTest()
|
|
{
|
|
InitializeComponent();
|
|
var cultureInfo = new CultureInfo("en-GB");
|
|
Thread.CurrentThread.CurrentUICulture = cultureInfo;
|
|
Thread.CurrentThread.CurrentCulture = cultureInfo;
|
|
_version = Assembly.GetExecutingAssembly().GetName().Version;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clear data table and set genesis to not connected
|
|
/// </summary>
|
|
private void Init()
|
|
{
|
|
ProcessViewControl(false);
|
|
_magFluxMeter?.StopStreamingCatcher();
|
|
lblSensorNo.Text = StrNotConnected;
|
|
lblSensorNo.ForeColor = Color.Red;
|
|
lblWaitingForMeterResponse.Visible = false;
|
|
btnConnect.Enabled = true;
|
|
SetControlDownloadsLocked();
|
|
tbxUniqueId.Text = "";
|
|
tbxSensorNo.Text = "";
|
|
tbxFwVersion.Text = "";
|
|
tbxFwBuildDate.Text = "";
|
|
tbxFwGitHash.Text = "";
|
|
tbxMeterSize.Text = "";
|
|
tbxFlowRate.Text = "";
|
|
tbxStatus.Text = "";
|
|
tbxVolume.Text = "";
|
|
tbxFwdVolume.Text = "";
|
|
tbxRevVolume.Text = "";
|
|
tbxMeterSize.ReadOnly = true;
|
|
tbxSensorNo.ReadOnly = true;
|
|
btnChangeSensorNo.Text = StrBtnChange;
|
|
btnChangeMeterSize.Text = StrBtnChange;
|
|
gridViewCalib.Visible = false;
|
|
|
|
var errorStateInfos = StateDef.GetInfoOfAllErrorStates();
|
|
if (errorStateInfos.Count >= 10)
|
|
{
|
|
cbxStatus0.Text = errorStateInfos[0];
|
|
cbxStatus1.Text = errorStateInfos[1];
|
|
cbxStatus2.Text = errorStateInfos[2];
|
|
cbxStatus3.Text = errorStateInfos[3];
|
|
cbxStatus4.Text = errorStateInfos[4];
|
|
cbxStatus5.Text = errorStateInfos[5];
|
|
cbxStatus6.Text = errorStateInfos[6];
|
|
cbxStatus7.Text = errorStateInfos[7];
|
|
cbxStatus8.Text = errorStateInfos[8];
|
|
cbxStatus9.Text = errorStateInfos[9];
|
|
}
|
|
}
|
|
|
|
private void FrmTest_Load(Object sender, EventArgs e)
|
|
{
|
|
var version = Assembly.GetExecutingAssembly().GetName().Version;
|
|
lblFwUpdateInfo.Text = $@"Version: {version.Major}.{version.Minor}.{version.Build}";
|
|
_resetTimeMeasurement = true;
|
|
Init();
|
|
|
|
LogText($"MagFluxToolBox: {_version.Major}.{_version.Minor}.{_version.Build}");
|
|
LogText(StrSeparator);
|
|
}
|
|
|
|
private void FrmTest_FormClosing(Object sender, FormClosingEventArgs e)
|
|
{
|
|
if (_magFluxMeter != null)
|
|
{
|
|
_magFluxMeter.OnStreamingRecordDecoded -= StreamingCatcher_OnStreamingRecordDecoded;
|
|
_magFluxMeter.Logout();
|
|
_magFluxMeter.StopStreamingCatcher();
|
|
|
|
}
|
|
_meterBatch?.RemoveAllMeters();
|
|
_meterBatch?.Dispose();
|
|
|
|
Dispose();
|
|
}
|
|
|
|
private void cbComSlot_SelectedIndexChanged(Object sender, EventArgs e)
|
|
{
|
|
_resetTimeMeasurement = true;
|
|
Init();
|
|
}
|
|
#endregion
|
|
#region Data Grid Calibration
|
|
/// <summary>
|
|
/// Edit calibrations and fill the data back to calibration data field
|
|
/// </summary>
|
|
/// <remarks date="2023-Mai-31" author="Thomas Wiedebusch">
|
|
/// - Initial.
|
|
/// </remarks>
|
|
private void gridViewCalib_CellEndEdit(Object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0 || _dataTableCalibPoints == null
|
|
|| _calibPointsCmPerH == null || _calibPointsCmPerH.Count < e.RowIndex)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var array = _calibPointsCmPerH.ToArray();
|
|
var index = e.RowIndex;
|
|
_calibPointsCmPerH.Clear();
|
|
var cellContent = gridViewCalib.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
|
|
|
|
if (gridViewCalib.Columns[e.ColumnIndex].Name == HeaderRefFlow)
|
|
array[index].refFlowRate = (Single)cellContent;
|
|
|
|
if (gridViewCalib.Columns[e.ColumnIndex].Name == HeaderDutFlow)
|
|
array[index].dutFlowRate = (Single)cellContent;
|
|
|
|
foreach (var a in array)
|
|
{
|
|
_calibPointsCmPerH.Add(a);
|
|
}
|
|
|
|
FillDataGridWithCalibInfos();
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Build data grid for calibrations
|
|
/// </summary>
|
|
/// <remarks date="2023-Mai-31" author="Thomas Wiedebusch">
|
|
/// - Initial.
|
|
/// </remarks>
|
|
private void FillDataGridWithCalibInfos()
|
|
{
|
|
|
|
if (_calibPointsCmPerH == null)
|
|
return;
|
|
|
|
_dataTableCalibPoints?.Dispose();
|
|
_dataTableCalibPoints = new DataTable();
|
|
|
|
_dataTableCalibPoints.Columns.Add(HeaderRefFlow, typeof(Single));
|
|
_dataTableCalibPoints.Columns.Add(HeaderDutFlow, typeof(Single));
|
|
|
|
try
|
|
{
|
|
foreach (var cb in _calibPointsCmPerH)
|
|
{
|
|
var row = _dataTableCalibPoints.NewRow();
|
|
row[HeaderRefFlow] = (Single)Math.Round(cb.refFlowRate, 6);
|
|
row[HeaderDutFlow] = (Single)Math.Round(cb.dutFlowRate, 6);
|
|
|
|
_dataTableCalibPoints.Rows.Add(row);
|
|
}
|
|
|
|
gridViewCalib.DataSource = _dataTableCalibPoints;
|
|
|
|
foreach (DataGridViewColumn column in gridViewCalib.Columns)
|
|
{
|
|
column.SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
}
|
|
gridViewCalib.Visible = true;
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//not implemented
|
|
}
|
|
}
|
|
#endregion --------------------------------------- Data Grid Calibration --------------------------------------
|
|
|
|
#region ActivationControls
|
|
|
|
private void SetControlDownloadsLocked()
|
|
{
|
|
btnConnect.Enabled = true;
|
|
btnAbortCalibration.Enabled = false;
|
|
btnPrepareCalibration.Enabled = false;
|
|
btnReadCalibration.Enabled = false;
|
|
btnWriteCalibration.Enabled = false;
|
|
btnChangeSensorNo.Enabled = false;
|
|
btnChangeMeterSize.Enabled = false;
|
|
}
|
|
|
|
private void SetControlsDownloadIsOngoing()
|
|
{
|
|
btnConnect.Enabled = false;
|
|
btnAbortCalibration.Enabled = false;
|
|
btnPrepareCalibration.Enabled = false;
|
|
btnReadCalibration.Enabled = false;
|
|
btnWriteCalibration.Enabled = false;
|
|
btnChangeSensorNo.Enabled = false;
|
|
btnChangeMeterSize.Enabled = false;
|
|
}
|
|
|
|
private void SetControlsDownloadIsFinished()
|
|
{
|
|
btnConnect.Enabled = true;
|
|
btnAbortCalibration.Enabled = false;
|
|
btnPrepareCalibration.Enabled = true;
|
|
btnReadCalibration.Enabled = true;
|
|
btnWriteCalibration.Enabled = true;
|
|
btnChangeSensorNo.Enabled = true;
|
|
btnChangeMeterSize.Enabled = true;
|
|
}
|
|
private void SetControlsDownloadEnabled()
|
|
{
|
|
btnConnect.Enabled = true;
|
|
btnAbortCalibration.Enabled = false;
|
|
btnPrepareCalibration.Enabled = true;
|
|
btnReadCalibration.Enabled = true;
|
|
btnWriteCalibration.Enabled = true;
|
|
btnChangeSensorNo.Enabled = true;
|
|
btnChangeMeterSize.Enabled = true;
|
|
}
|
|
#endregion
|
|
|
|
#region BoardControls
|
|
|
|
/// <summary>
|
|
/// Cyclic execution of catcher on incoming events.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void StreamingCatcher_OnStreamingRecordDecoded(Object sender, MagFluxFlowDataEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
tbxVolume.Text = $@"{e.NewData.VolumeCm:F3}";
|
|
tbxFwdVolume.Text = $@"{e.NewData.ForwardVolumeCm:F3}";
|
|
tbxRevVolume.Text = $@"{e.NewData.NegativeReverseVolumeCm:F3}";
|
|
tbxFlowRate.Text = $@"{e.NewData.FlowRateCmPh:F3}";
|
|
tbxStatus.Text = $@"0x{e.NewData.StatusBits:X8}";
|
|
tbxTime.Text = $@"{e.NewData.TimeS:F3}";
|
|
if (_lastState != e.NewData.StatusBits)
|
|
{
|
|
// remind states for next run
|
|
_lastState = e.NewData.StatusBits;
|
|
UpdateStateDisplay();
|
|
}
|
|
}));
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update state display on GUI
|
|
/// </summary>
|
|
private void UpdateStateDisplay()
|
|
{
|
|
cbxStatus0.Checked = StateDef.CheckStateMask(_lastState, 0);
|
|
cbxStatus1.Checked = StateDef.CheckStateMask(_lastState, 1);
|
|
cbxStatus2.Checked = StateDef.CheckStateMask(_lastState, 2);
|
|
cbxStatus3.Checked = StateDef.CheckStateMask(_lastState, 3);
|
|
cbxStatus4.Checked = StateDef.CheckStateMask(_lastState, 4);
|
|
cbxStatus5.Checked = StateDef.CheckStateMask(_lastState, 5);
|
|
cbxStatus6.Checked = StateDef.CheckStateMask(_lastState, 6);
|
|
cbxStatus7.Checked = StateDef.CheckStateMask(_lastState, 7);
|
|
cbxStatus8.Checked = StateDef.CheckStateMask(_lastState, 8);
|
|
cbxStatus9.Checked = StateDef.CheckStateMask(_lastState, 9);
|
|
|
|
}
|
|
|
|
private void Connect()
|
|
{
|
|
try
|
|
{
|
|
Init();
|
|
|
|
if (string.IsNullOrEmpty(cbComSlot.SelectedItem.ToString()) ||
|
|
!int.TryParse(cbComSlot.SelectedItem.ToString(), out var slotNr))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//lblOverall.Text = @"Establish data base connection..";
|
|
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
ViewProgressPcb(true);
|
|
|
|
//dispose old meter
|
|
_meterBatch.RemoveAllMeters();
|
|
_magFluxMeter = null;
|
|
Thread.Sleep(200);
|
|
|
|
//assign new meter and assign meter to FW update file if this exists
|
|
_magFluxMeter = new MagFluxMeter();
|
|
|
|
_magFluxMeter.SetupFromConfigFile(slotNr);
|
|
_meterBatch.AddMeter(_magFluxMeter);
|
|
|
|
_magFluxMeter.Configuration.UseRegisterWatchService = false;
|
|
_magFluxMeter.Configuration.UseMinMaxCheck = false;
|
|
_magFluxMeter.OnStreamingRecordDecoded += StreamingCatcher_OnStreamingRecordDecoded;
|
|
|
|
_meterBatch.MetersLogin();
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
if (_magFluxMeter != null && _magFluxMeter.IsLoggedOn)
|
|
{
|
|
lblSensorNo.Text = "";
|
|
tbxUniqueId.Text = _magFluxMeter.UniqueId;
|
|
tbxSensorNo.Text = _magFluxMeter.PcbId;
|
|
tbxFwVersion.Text = _magFluxMeter.FwVersion;
|
|
tbxFwBuildDate.Text = _magFluxMeter.FwBuildDate;
|
|
tbxFwGitHash.Text = _magFluxMeter.FwGitHash;
|
|
tbxMeterSize.Text = _magFluxMeter.MeterSizeMm.ToString();
|
|
lblSensorNo.ForeColor = Color.Green;
|
|
CheckUpdateEnabled();
|
|
_magFluxMeter.StartStreamingCatcher();
|
|
_magFluxMeter.Logout();
|
|
LogInstalledMeterFw();
|
|
}
|
|
}));
|
|
}).ContinueWith(delegate
|
|
{
|
|
ViewProgressPcb(false);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
LogErrorText(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region ProcessControls
|
|
private void ViewProgressPcb(Boolean isActive)
|
|
{
|
|
if (_updateGui)
|
|
{
|
|
if (isActive)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
_tryConnectPcb = true;
|
|
ProcessViewControl(true);
|
|
lblActualProcess.Text = StrConnecting;
|
|
lblOverall.Text = StrOverallProcess;
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
_tryConnectPcb = false;
|
|
ProcessViewControl(false);
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// View all process bars and labels
|
|
/// </summary>
|
|
private void ProcessViewControl(Boolean view)
|
|
{
|
|
if (view)
|
|
{
|
|
lblActualProcess.Visible = true;
|
|
lblOverall.Visible = true;
|
|
barOverallProgressUpdate.Visible = true;
|
|
barSingleProgressUpdate.Visible = true;
|
|
_lastState = (UInt32)State.Okay;
|
|
tmrProgressUpdate.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
lblActualProcess.Visible = false;
|
|
lblOverall.Visible = false;
|
|
barOverallProgressUpdate.Visible = false;
|
|
barSingleProgressUpdate.Visible = false;
|
|
tmrProgressUpdate.Enabled = false;
|
|
_lastState = (UInt32)State.Okay;
|
|
lblWaitingForMeterResponse.Visible = false;
|
|
lblActualProcess.Text = "";
|
|
lblOverall.Text = "";
|
|
}
|
|
|
|
//common actions and settings
|
|
lblActualProcess.Update();
|
|
lblOverall.Update();
|
|
barOverallProgressUpdate.Value = 0;
|
|
barOverallProgressUpdate.Update();
|
|
barSingleProgressUpdate.Value = 0;
|
|
barSingleProgressUpdate.Update();
|
|
Update();
|
|
}
|
|
|
|
private void StartStopDownload(Boolean isActive)
|
|
{
|
|
if (isActive)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
ProcessViewControl(true);
|
|
tmrProgressUpdate.Enabled = true;
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
ProcessViewControl(false);
|
|
SetControlsDownloadIsFinished();
|
|
|
|
//// update the display of the meter size, LUT CRC and region
|
|
//tbxMeterFw.Text = _magFluxMeter.FwVersion;
|
|
//tbxMeterMeterSize.Text = _magFluxMeter.MeterSizeMm;
|
|
//tbxMeterLutCrc.Text = _magFluxMeter.LutCrc;
|
|
//tbxRegion.Text = _magFluxMeter.Region;
|
|
|
|
//if (!_lutFileSuccessfulWritten)
|
|
//{
|
|
// lblLutFileLoadedInfo.ForeColor = Color.Red;
|
|
// lblLutFileLoadedInfo.Text = StrUpdateErrorMessage;
|
|
// var txt = StrUpdateErrorMessage;
|
|
// if (!string.IsNullOrEmpty(_meterLutUpdate?.ErrorMessage))
|
|
// {
|
|
// txt += "\n";
|
|
// txt += _meterLutUpdate?.ErrorMessage;
|
|
// }
|
|
|
|
// LogErrorText(txt);
|
|
// MessageBoxShow(txt, @"FAILED",
|
|
// MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
//}
|
|
//else
|
|
//{
|
|
// LogSuccessText(StrUpdateSuccessMessage);
|
|
// MessageBoxShow(StrUpdateSuccessMessage, @"SUCCESS",
|
|
// MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
//}
|
|
}));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Display installed meter FW.
|
|
/// </summary>
|
|
/// <remarks date="2022-Mar-25" author="Thomas Wiedebusch">
|
|
/// - Init.
|
|
/// </remarks>
|
|
private void LogInstalledMeterFw()
|
|
{
|
|
//if (_magFluxMeter == null)
|
|
// return;
|
|
//LogText(StrSeparator);
|
|
//LogText($"PCB ID: {_magFluxMeter.PcbId}");
|
|
//LogText($"Core Version: {GenesisMeter.BuildFwVersionString(_magFluxMeter.CoreRevision)}");
|
|
//LogText("");
|
|
//LogText("Installed Applications:");
|
|
|
|
//foreach (var app in _magFluxMeter.MeterAppListVersion)
|
|
//{
|
|
// var versionString = app.IsInstalled ? $"V: {app.StrVersion} - CRC: 0x{app.Crc:X4}" :
|
|
// "App NOT Installed";
|
|
// LogText($"AppId: 0x{app.AppId:X2} - {versionString} - " + $"AppName: {app.AppName}");
|
|
|
|
// if (app.IsInstalled)
|
|
// {
|
|
// var appVersion = new CordonelAppVersion(app.AppId, app.StrVersion);
|
|
|
|
// // Copy metrology update permission
|
|
// if (app.AppName == MeterFwUpdateCapability.MetrologyName &&
|
|
// _magFluxMeter.MetrologyUpgradePermission != MeterFwUpdateCapability.MetrologyUpgradePermitted)
|
|
// {
|
|
// appVersion.IsUpdateable = false;
|
|
// }
|
|
// }
|
|
//}
|
|
//LogText(StrSeparator);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Output exclusively to user update remarks text window.
|
|
/// </summary>
|
|
/// <remarks date="2021-Apr-26" author="Thomas Wiedebusch">
|
|
/// - Color added.
|
|
/// </remarks>
|
|
private void LogText(String txtHistory)
|
|
{
|
|
InfoWindowColoredText(txtHistory, ColorDefault);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Output exclusively to user update remarks text window.
|
|
/// </summary>
|
|
private void LogErrorText(String txtHistory)
|
|
{
|
|
InfoWindowColoredText(txtHistory, ColorProcessFailed);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Output exclusively to user update remarks text window.
|
|
/// </summary>
|
|
private void LogSuccessText(String txtHistory)
|
|
{
|
|
InfoWindowColoredText(txtHistory, ColorSuccess);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Output exclusively to user update remarks text window.
|
|
/// </summary>
|
|
private void InfoWindowColoredText(String txtHistory, Color color)
|
|
{
|
|
//if (_frmHistory?.rtbHistory == null)
|
|
// return;
|
|
//Invoke(new Action(() =>
|
|
//{
|
|
// _frmHistory.rtbHistory.SuspendLayout();
|
|
// _frmHistory.rtbHistory.SelectionStart = _frmHistory.rtbHistory.Text.Length;
|
|
// _frmHistory.rtbHistory.SelectionLength = 0;
|
|
// _frmHistory.rtbHistory.SelectionColor = color;
|
|
// _frmHistory.rtbHistory.AppendText($"{txtHistory}{Environment.NewLine}");
|
|
// _frmHistory.rtbHistory.SelectionColor = _frmHistory.rtbHistory.ForeColor;
|
|
// _frmHistory.rtbHistory.ScrollToCaret();
|
|
// _frmHistory.rtbHistory.ResumeLayout();
|
|
//}));
|
|
}
|
|
#endregion
|
|
|
|
#region Checks
|
|
private void CheckUpdateEnabled()
|
|
{
|
|
//this check has been placed here to force display update
|
|
if (_magFluxMeter != null)
|
|
{
|
|
SetControlsDownloadEnabled();
|
|
return;
|
|
}
|
|
SetControlDownloadsLocked();
|
|
}
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
/// <summary>
|
|
/// Process update event for displaying messages in history window
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <remarks date="2020-Dec-10" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public virtual void ProcessUpdate_Event(Object sender, ProcessExecEventArgs e)
|
|
{
|
|
LogText(e.OverallProcessMessage);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region TimerControls
|
|
private void tmrProgressUpdate_Tick(Object sender, EventArgs e)
|
|
{
|
|
//cbxManualControl.Visible = true;
|
|
if (_tryConnectPcb)
|
|
{
|
|
barOverallProgressUpdate.Value = barOverallProgressUpdate.Value + 1 > 100 ? 0 :
|
|
barOverallProgressUpdate.Value + 1;
|
|
barSingleProgressUpdate.Value = barSingleProgressUpdate.Value + 4 > 100 ? 0 :
|
|
barSingleProgressUpdate.Value + 4;
|
|
lblOverall.Text = StrOverallProcess;
|
|
}
|
|
else
|
|
{
|
|
//lblOverall.Text = _meterLutUpdate?.GetLutUpdateStateOperation();
|
|
//lblActualProcess.Text = _meterLutUpdate?.GetActualOperation();
|
|
|
|
//var overallProgress = (Int32)(_meterLutUpdate?.OverallProcessCtrPercent ?? 0);
|
|
//if (overallProgress < 0)
|
|
// overallProgress = 0;
|
|
//barOverallProgressUpdate.Value = overallProgress > 100 ? 100 : overallProgress;
|
|
//barOverallProgressUpdate.Update();
|
|
|
|
//var singleProgress = (Int32)(_meterLutUpdate?.SingleFileProcessCtrPercent ?? 0);
|
|
//if (_meterLutUpdate?.GetActualOperation() != _lastState)
|
|
//{
|
|
// _lastState = _meterLutUpdate?.GetActualOperation();
|
|
// lblWaitingForMeterResponse.Visible = false;
|
|
//}
|
|
//else
|
|
//{
|
|
// //if the communication gets frozen
|
|
// lblWaitingForMeterResponse.Visible = _lastSingleProgress == singleProgress;
|
|
//}
|
|
|
|
//barSingleProgressUpdate.Value = singleProgress > 100 ? 100 : singleProgress;
|
|
//_lastSingleProgress = singleProgress;
|
|
//barSingleProgressUpdate.Update();
|
|
}
|
|
SetTimeDisplay();
|
|
Update();
|
|
}
|
|
|
|
private void SetTimeDisplay()
|
|
{
|
|
var time = DateTimeOffset.UtcNow;
|
|
var timeSpan = time - _startTime;
|
|
lblUpdateTime.Text = $@"{(UInt32)timeSpan.TotalMinutes}:{timeSpan.Seconds:00}";
|
|
}
|
|
#endregion
|
|
#region Buttons
|
|
private void btnChangeSensorNo_Click(Object sender, EventArgs e)
|
|
{
|
|
// enable edit and change text to button text to "Set"
|
|
if (string.Equals(StrBtnChange, btnChangeSensorNo.Text))
|
|
{
|
|
btnChangeSensorNo.Text = StrBtnSet;
|
|
tbxSensorNo.ReadOnly = false;
|
|
}
|
|
else
|
|
{
|
|
btnChangeSensorNo.Text = StrBtnChange;
|
|
tbxSensorNo.ReadOnly = true;
|
|
if (UInt32.TryParse(tbxSensorNo.Text, out var pcbId))
|
|
{
|
|
if (_magFluxMeter != null && _magFluxMeter.SetPcbId(pcbId))
|
|
{
|
|
// reconnect to publish the new serial number to the streaming protocol
|
|
Connect();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnChangeMeterSize_Click(Object sender, EventArgs e)
|
|
{
|
|
// enable edit and change text to button text to "Set"
|
|
if (string.Equals(StrBtnChange, btnChangeMeterSize.Text))
|
|
{
|
|
btnChangeMeterSize.Text = StrBtnSet;
|
|
tbxMeterSize.ReadOnly = false;
|
|
}
|
|
else
|
|
{
|
|
btnChangeMeterSize.Text = StrBtnChange;
|
|
tbxMeterSize.ReadOnly = true;
|
|
if (UInt16.TryParse(tbxMeterSize.Text, out var meterSize_mm))
|
|
{
|
|
_magFluxMeter?.SetMeterSizeMm(meterSize_mm);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnPrepareCalibration_Click(Object sender, EventArgs e)
|
|
{
|
|
SetControlsDownloadIsOngoing();
|
|
_magFluxMeter?.InitCalibration();
|
|
btnAbortCalibration.Enabled = true;
|
|
btnReadCalibration_Click(this, null);
|
|
SetControlsDownloadIsFinished();
|
|
}
|
|
|
|
private void btnReadCalibration_Click(Object sender, EventArgs e)
|
|
{
|
|
SetControlsDownloadIsOngoing();
|
|
_magFluxMeter?.ReadCalibration(out _calibPointsCmPerH);
|
|
if (_calibPointsCmPerH == null) return;
|
|
|
|
_dataTableCalibPoints?.Clear();
|
|
FillDataGridWithCalibInfos();
|
|
SetControlsDownloadIsFinished();
|
|
}
|
|
|
|
private void btnWriteCalibration_Click(Object sender, EventArgs e)
|
|
{
|
|
SetControlsDownloadIsOngoing();
|
|
if (_calibPointsCmPerH == null)
|
|
return;
|
|
|
|
//TOD O THW test start to increase calibrations above 6
|
|
//var calib = new Calibration();
|
|
//calib.dutFlowRate = 2;
|
|
//calib.refFlowRate = 2;
|
|
//_calibPointsCmPerH.Add(calib);
|
|
//calib.dutFlowRate = 15;
|
|
//calib.refFlowRate = 15;
|
|
//_calibPointsCmPerH.Add(calib);
|
|
//TOD O THW test stop
|
|
_magFluxMeter?.WriteCalibration(_calibPointsCmPerH);
|
|
btnReadCalibration_Click(this, null);
|
|
}
|
|
|
|
private void btnAbortCalibration_Click(Object sender, EventArgs e)
|
|
{
|
|
_magFluxMeter?.StopCalibration();
|
|
}
|
|
|
|
private void btnConnect_Click(Object sender, EventArgs e)
|
|
{
|
|
////TOD O THW test start
|
|
//_magFluxMeter = new MagFluxMeter();
|
|
//_magFluxMeter.SetupFromConfigFile(1);
|
|
//_meterBatch.AddMeter(_magFluxMeter);
|
|
|
|
//_meterBatch.MetersLogin();
|
|
//var calibPointsCmPerH = new List<Calibration>();
|
|
//var calibPoint = new Calibration[6];
|
|
//calibPoint[0].dutFlowRate = 0.01f;
|
|
//calibPoint[0].refFlowRate = 0;
|
|
//calibPoint[1].dutFlowRate = 100;
|
|
//calibPoint[1].refFlowRate = 99.9f;
|
|
//calibPoint[2].dutFlowRate = 0;
|
|
//calibPoint[2].refFlowRate = 0;
|
|
//calibPoint[3].dutFlowRate = 10.0f;
|
|
//calibPoint[3].refFlowRate = 9.9f;
|
|
//calibPoint[4].dutFlowRate = 0;
|
|
//calibPoint[4].refFlowRate = 0;
|
|
//calibPoint[5].dutFlowRate = 69.3f;
|
|
//calibPoint[5].refFlowRate = 70.2f;
|
|
//calibPointsCmPerH.AddRange(calibPoint);
|
|
//_magFluxMeter?.WriteCalibration(calibPointsCmPerH);
|
|
////TOD O THW test end
|
|
|
|
if (_resetTimeMeasurement)
|
|
{
|
|
_startTime = DateTimeOffset.UtcNow;
|
|
_resetTimeMeasurement = false;
|
|
}
|
|
Connect();
|
|
}
|
|
#endregion
|
|
#region ExternalCalls
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public MsgEventArgs LastMsgEvent;
|
|
|
|
/// <inheritdoc />
|
|
public class MsgEventArgs : EventArgs
|
|
{
|
|
/// <summary>
|
|
/// Text to display
|
|
/// </summary>
|
|
public String Text;
|
|
/// <summary>
|
|
/// Headline
|
|
/// </summary>
|
|
public String Caption;
|
|
/// <summary>
|
|
/// Buttons
|
|
/// </summary>
|
|
public MessageBoxButtons Buttons;
|
|
/// <summary>
|
|
/// Icon
|
|
/// </summary>
|
|
public MessageBoxIcon Icon;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Message pop up event handler
|
|
/// </summary>
|
|
public event EventHandler<MsgEventArgs> OnMsgPopUp;
|
|
private void MessageBoxShow(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon)
|
|
{
|
|
if (_updateGui)
|
|
{
|
|
MessageBox.Show(text, caption, buttons, icon);
|
|
}
|
|
else
|
|
{
|
|
LastMsgEvent = new MsgEventArgs() { Text = text, Caption = caption, Buttons = buttons, Icon = icon };
|
|
OnMsgPopUp?.Invoke(this, LastMsgEvent);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|