MagFlux: - Calibration changed: Internally all values are handled in cm/h but in MagFlux.RequestProtocol changed to calibPoints in liters per second

This commit is contained in:
Thomas Wiedebusch
2023-06-01 14:20:53 +02:00
parent 3bee36749c
commit 97d536d4d5
8 changed files with 101 additions and 66 deletions
+1 -1
View File
@@ -155,7 +155,7 @@
</site>
<site name="MeterProcessState" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\drabesch_ro\Repo\lab\la_operations\laa_production\Common\Service\MeterProcessState" />
<virtualDirectory path="/" physicalPath="D:\Projekte\SENSUS_GitLab\laa_production\Common\Service\MeterProcessState" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:56011:localhost" />
@@ -215,6 +215,7 @@
<Compile Include="..\..\..\..\.shared\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="DataTypes\Calibration.cs" />
<Compile Include="EventArguments\MagFluxFlowDataEventArgs.cs" />
<Compile Include="EventArguments\RequestResponseDataEventArgs.cs" />
<Compile Include="MeasurementRecords\MagFluxRecord.cs" />
@@ -250,6 +251,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.DataTypes
{
/// <summary>
/// Used as structured calibration converter from liters per second to
/// cubic meters per hour and vice versa
/// </summary>
public struct Calibration
{
/// <summary>
/// Reference meter flow rate - unit free for use
/// </summary>
public Single refFlowRate;
/// <summary>
/// DUT meter flow rate - unit free for use
/// </summary>
public Single dutFlowRate;
}
}
@@ -12,6 +12,7 @@ using Xylem.Common.Hardware.Interfaces.Ports.SerialPorts;
using Xylem.Common.Hardware.Interfaces.Protocols.ProtocolCore;
using Xylem.Common.Hardware.Interfaces.Protocols.ProtocolCore.EventArguments;
using Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol;
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.DataTypes;
using Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.StreamingProtocol;
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments;
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.MeasurementRecords;
@@ -36,11 +37,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
{
#region Variables and Properties
/// <summary>
/// Calibration points reference to DUT
/// </summary>
private List<CalibrationPoint> _calibPoints;
/// <summary>
/// Mark the streaming catcher as active
/// </summary>
@@ -960,21 +956,19 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
/// <summary>
/// Write calibration values to MagFlux
/// </summary>
public void WriteCalibration(List<CalibrationPoint> calibPoints)
public void WriteCalibration(List<Calibration> calibrationsCmPerH)
{
_logger.Info($"Slot:{Slot} - Write calibration values to MagFlux");
_calibPoints = calibPoints;
RequestProtocol?.SetCalibrationPoints(_calibPoints);
RequestProtocol?.SetCalibrationPoints(calibrationsCmPerH);
}
/// <summary>
/// Read calibration values to MagFlux
/// </summary>
public void ReadCalibration(out List<CalibrationPoint> calibPoints)
public void ReadCalibration(out List<Calibration> calibrationsCmPerH)
{
calibrationsCmPerH = null;
_logger.Info($"Slot:{Slot} - Read calibration values from MagFlux");
RequestProtocol?.GetCalibrationPoints(out _calibPoints);
calibPoints = _calibPoints;
RequestProtocol?.GetCalibrationPoints(out calibrationsCmPerH);
}
/// <inheritdoc />
@@ -983,8 +977,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
_logger.Info($"Slot:{Slot} - Init calibration and set calibration values of all channels to default");
if (RequestProtocol == null)
return;
// first read out the current calibration points, those are used as container for overwriting
RequestProtocol.GetCalibrationPoints(out _calibPoints);
if (RequestProtocol.PrepareDeviceForCalibration())
PreMeasurement();
}
@@ -6,6 +6,7 @@ using NLog;
using Xylem.Common.Hardware.Interfaces.Ports.PortCore.EventArguments;
using Xylem.Common.Hardware.Interfaces.Protocols.ProtocolCore;
using Xylem.Common.Hardware.Interfaces.Protocols.ProtocolCore.EventArguments;
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.DataTypes;
using Xylem.Common.Utils.Logging;
using XYLEM.Device;
@@ -20,19 +21,22 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol
private readonly ILogger _logger;
private IMagFluxRequestProtocol _magFluxRequestProtocol;
public Int32 CalibrationPointsMax { get; } = 11;
private List<Calibration> _calibPointsCmPerH;
/// <inheritdoc />
public RequestProtocol(String ident) : base(ident)
{
_ident = ident;
_magFluxRequestProtocol = new MagFlux6200();
_calibPointsCmPerH = new List<Calibration>();
_logger = NLogHelper.CreateOrGetMultiLogger(_ident, "", "RequestProtocol", "MeterBase", "MeterBase");
}
/// <inheritdoc/>>
public override void Dispose()
{
_calibPointsCmPerH.Clear();
_calibPointsCmPerH = null;
_magFluxRequestProtocol?.CloseConnection();
_magFluxRequestProtocol = null;
base.Dispose();
@@ -245,36 +249,82 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol
}
/// <summary>
/// Wrapper to get the calibration points from MagFlux
/// Wrapper to get the calibration points from MagFlux:
/// - Here the conversion from to <see cref="CalibrationPoints"/> to <see cref="Calibration"/>
/// will take place.
/// </summary>
/// <param name="calibPoints"></param>
/// <param name="calibPointsCmPerH"></param>
/// <returns></returns>
/// <remarks date="2023-Mai-17" author="T.Wiedebusch">
/// - Initial
/// </remarks>
public Boolean GetCalibrationPoints(out List<CalibrationPoint> calibPoints)
public Boolean GetCalibrationPoints(out List<Calibration> calibPointsCmPerH)
{
calibPoints = new List<CalibrationPoint>();
calibPointsCmPerH = new List<Calibration>();
if (_magFluxRequestProtocol == null) return false;
var retVal = _magFluxRequestProtocol.GetCalibrationPoints(out var calibrations);
calibPoints = calibrations?.calibrations?.ToList();
_logger.Debug(retVal ? $"{_ident} MagFlux calibration successfully read" :
$"{_ident} MagFlux calibration read failed!");
return retVal;
if (!retVal)
return false;
// extract the single calibration points from container as ref and DUT in liters per second
var calibPoints = calibrations?.calibrations?.ToList();
if (calibPoints == null)
return false;
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);
}
calibPointsCmPerH = _calibPointsCmPerH;
return true;
}
/// <summary>
/// Wrapper to set the calibration points from MagFlux:
/// - Calibration points have to be sorted ascending by request from MJK
/// - Here the conversion from <see cref="Calibration"/> to <see cref="CalibrationPoints"/>
/// will take place.
/// </summary>
/// <param name="calibPoints"></param>
/// <param name="calibPointsCmPerH"></param>
/// <returns></returns>
/// <remarks date="2023-Mai-30" author="T.Wiedebusch">
/// - Initial
/// </remarks>
public Boolean SetCalibrationPoints(List<CalibrationPoint> calibPoints)
public Boolean SetCalibrationPoints(List<Calibration> calibPointsCmPerH)
{
if (_magFluxRequestProtocol == null) return false;
if (_magFluxRequestProtocol == null || calibPointsCmPerH == null) return false;
// copy to array for sorting ascending
var array = calibPointsCmPerH.ToArray();
var ordered = array.OrderBy(x => x.refFlowRate);
_calibPointsCmPerH.Clear();
foreach (var a in ordered)
{
_calibPointsCmPerH.Add(a);
}
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);
}
var cbs = new CalibrationPoints(calibPoints, calibPoints.Count);
var retVal = _magFluxRequestProtocol.SetCalibrationPoints(cbs);
_logger.Debug(retVal ? $"{_ident} MagFlux calibration successfully set" :
@@ -1 +1 @@
5ed75d99ee45ff67821090f1b3dbb001dd9e4fe3
1a3d4919c9c702245832d925951f2b7cb72fc333
@@ -1 +1 @@
0d85a5b3a7561b41163c20e5dc7713bcd0d65555
f64d563def603c89cafafa61a3219ba97e1e344c
+6 -38
View File
@@ -8,11 +8,11 @@ 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.WaterMeterCore;
using Xylem.Common.Utils.ProcessExec.EventArguments;
using XYLEM.Device;
namespace Xylem.Common.Ui.MagFluxToolBox
@@ -24,18 +24,11 @@ namespace Xylem.Common.Ui.MagFluxToolBox
{
#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.
/// Reference to list of calibration points in cubic meters per hour.
/// </summary>
private List<Calibration> _calibPointsCmPerH;
@@ -96,7 +89,6 @@ namespace Xylem.Common.Ui.MagFluxToolBox
{
ProcessViewControl(false);
_magFluxMeter?.StopStreamingCatcher();
_calibPointsCmPerH = new List<Calibration>();
lblSensorNo.Text = StrNotConnected;
lblSensorNo.ForeColor = Color.Red;
lblWaitingForMeterResponse.Visible = false;
@@ -128,8 +120,6 @@ namespace Xylem.Common.Ui.MagFluxToolBox
private void FrmTest_FormClosing(Object sender, FormClosingEventArgs e)
{
_calibPointsCmPerH.Clear();
_calibPointsCmPerH = null;
if (_magFluxMeter != null)
{
_magFluxMeter.OnStreamingRecordDecoded -= StreamingCatcher_OnStreamingRecordDecoded;
@@ -161,12 +151,11 @@ namespace Xylem.Common.Ui.MagFluxToolBox
try
{
if (e.ColumnIndex < 0 || e.RowIndex < 0 || _dataTableCalibPoints == null
|| _calibPointsCmPerH.Count < e.RowIndex)
|| _calibPointsCmPerH == null || _calibPointsCmPerH.Count < e.RowIndex)
{
return;
}
var array = _calibPointsCmPerH.ToArray();
var index = e.RowIndex;
_calibPointsCmPerH.Clear();
@@ -650,18 +639,8 @@ namespace Xylem.Common.Ui.MagFluxToolBox
private void btnReadCalibration_Click(Object sender, EventArgs e)
{
SetControlsDownloadIsOngoing();
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);
}
_magFluxMeter?.ReadCalibration(out _calibPointsCmPerH);
if (_calibPointsCmPerH == null) return;
_dataTableCalibPoints?.Clear();
FillDataGridWithCalibInfos();
@@ -673,19 +652,8 @@ namespace Xylem.Common.Ui.MagFluxToolBox
SetControlsDownloadIsOngoing();
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);
_magFluxMeter?.WriteCalibration(_calibPointsCmPerH);
SetControlsDownloadIsFinished();
}