MagFluxToolBox: - Manually calibration supported
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Serialization;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
||||
using Xylem.Common.Utils.ProcessExec.EventArguments;
|
||||
using XYLEM.Device;
|
||||
|
||||
|
||||
namespace Xylem.Common.Ui.MagFluxToolBox
|
||||
@@ -19,6 +24,24 @@ namespace Xylem.Common.Ui.MagFluxToolBox
|
||||
public partial class FrmTest : Form
|
||||
{
|
||||
#region Variables
|
||||
|
||||
struct Calibration
|
||||
{
|
||||
public Single refFlowRate;
|
||||
public Single dutFlowRate;
|
||||
}
|
||||
|
||||
const String headerRef = @"Ref FlowRate [m³/h]";
|
||||
const String headerDut = @"DUT FlowRate [m³/h]";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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";
|
||||
@@ -74,6 +97,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox
|
||||
{
|
||||
ProcessViewControl(false);
|
||||
_magFluxMeter?.StopStreamingCatcher();
|
||||
_calibPointsCmPerH = new List<Calibration>();
|
||||
lblSensorNo.Text = StrNotConnected;
|
||||
lblSensorNo.ForeColor = Color.Red;
|
||||
lblWaitingForMeterResponse.Visible = false;
|
||||
@@ -105,6 +129,8 @@ namespace Xylem.Common.Ui.MagFluxToolBox
|
||||
|
||||
private void FrmTest_FormClosing(Object sender, FormClosingEventArgs e)
|
||||
{
|
||||
_calibPointsCmPerH.Clear();
|
||||
_calibPointsCmPerH = null;
|
||||
if (_magFluxMeter != null)
|
||||
{
|
||||
_magFluxMeter.OnStreamingRecordDecoded -= StreamingCatcher_OnStreamingRecordDecoded;
|
||||
@@ -124,6 +150,92 @@ namespace Xylem.Common.Ui.MagFluxToolBox
|
||||
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.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 == headerRef)
|
||||
array[index].refFlowRate = (Single)cellContent;
|
||||
|
||||
if (gridViewCalib.Columns[e.ColumnIndex].Name == headerDut)
|
||||
array[index].dutFlowRate = (Single)cellContent;
|
||||
|
||||
var ordered = array.OrderBy(x => x.refFlowRate);
|
||||
foreach (var a in ordered)
|
||||
{
|
||||
_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(headerRef, typeof(Single));
|
||||
_dataTableCalibPoints.Columns.Add(headerDut, typeof(Single));
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var cb in _calibPointsCmPerH)
|
||||
{
|
||||
var row = _dataTableCalibPoints.NewRow();
|
||||
row[headerRef] = cb.refFlowRate;
|
||||
row[headerDut] = cb.dutFlowRate;
|
||||
|
||||
_dataTableCalibPoints.Rows.Add(row);
|
||||
}
|
||||
|
||||
gridViewCalib.DataSource = _dataTableCalibPoints;
|
||||
|
||||
foreach (DataGridViewColumn column in gridViewCalib.Columns)
|
||||
{
|
||||
column.SortMode = DataGridViewColumnSortMode.NotSortable;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//not implemented
|
||||
}
|
||||
}
|
||||
#endregion --------------------------------------- Data Grid Calibration --------------------------------------
|
||||
|
||||
#region ActivationControls
|
||||
|
||||
private void SetControlDownloadsLocked()
|
||||
@@ -228,7 +340,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox
|
||||
tbxFwVersion.Text = _magFluxMeter.FwVersion;
|
||||
tbxFwBuildDate.Text = _magFluxMeter.FwBuildDate;
|
||||
tbxFwGitHash.Text = _magFluxMeter.FwGitHash;
|
||||
tbxMeterSize.Text = _magFluxMeter.MeterSize_mm.ToString();
|
||||
tbxMeterSize.Text = _magFluxMeter.MeterSizeMm.ToString();
|
||||
lblSensorNo.ForeColor = Color.Green;
|
||||
CheckUpdateEnabled();
|
||||
_magFluxMeter.StartStreamingCatcher();
|
||||
@@ -331,7 +443,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox
|
||||
|
||||
//// update the display of the meter size, LUT CRC and region
|
||||
//tbxMeterFw.Text = _magFluxMeter.FwVersion;
|
||||
//tbxMeterMeterSize.Text = _magFluxMeter.MeterSize_mm;
|
||||
//tbxMeterMeterSize.Text = _magFluxMeter.MeterSizeMm;
|
||||
//tbxMeterLutCrc.Text = _magFluxMeter.LutCrc;
|
||||
//tbxRegion.Text = _magFluxMeter.Region;
|
||||
|
||||
@@ -531,16 +643,45 @@ namespace Xylem.Common.Ui.MagFluxToolBox
|
||||
{
|
||||
_magFluxMeter?.InitCalibration();
|
||||
btnAbortCalibration.Enabled = true;
|
||||
btnReadCalibration_Click(this, null);
|
||||
}
|
||||
|
||||
private void btnReadCalibration_Click(Object sender, EventArgs e)
|
||||
{
|
||||
_magFluxMeter?.ReadCalibration();
|
||||
var calibPoints = new List<CalibrationPoint>();
|
||||
_magFluxMeter?.ReadCalibration(out calibPoints);
|
||||
if (calibPoints == null) return;
|
||||
var calibConverter = new Calibration();
|
||||
_calibPointsCmPerH?.Clear();
|
||||
foreach (var cp in calibPoints)
|
||||
{
|
||||
// convert flow rate from liters per second to cubic meters per hour
|
||||
calibConverter.refFlowRate = cp.ReferenceFlowRate_lps * 3.6f;
|
||||
calibConverter.dutFlowRate = cp.ReportedFlowRate_lps * 3.6f;
|
||||
_calibPointsCmPerH?.Add(calibConverter);
|
||||
}
|
||||
|
||||
_dataTableCalibPoints?.Clear();
|
||||
FillDataGridWithCalibInfos();
|
||||
}
|
||||
|
||||
private void btnWriteCalibration_Click(Object sender, EventArgs e)
|
||||
{
|
||||
_magFluxMeter?.WriteCalibration();
|
||||
if (_calibPointsCmPerH == null)
|
||||
return;
|
||||
var calibPoints = new List<CalibrationPoint>();
|
||||
foreach (var cp in _calibPointsCmPerH)
|
||||
{
|
||||
// convert flow rate to liters per second from cubic meters per hour
|
||||
var calibConverter = new CalibrationPoint
|
||||
{
|
||||
ReferenceFlowRate_lps = cp.refFlowRate / 3.6f,
|
||||
ReportedFlowRate_lps = cp.dutFlowRate / 3.6f
|
||||
};
|
||||
calibPoints.Add(calibConverter);
|
||||
}
|
||||
|
||||
_magFluxMeter?.WriteCalibration(calibPoints);
|
||||
}
|
||||
|
||||
private void btnAbortCalibration_Click(Object sender, EventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user