MagFluxMeter: - Added functions for measurement
This commit is contained in:
@@ -16,11 +16,9 @@ using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.MeasurementRecords;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxConfig;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxConfig.Const;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol;
|
||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts;
|
||||
using Xylem.Common.Logic.SoftwareAccessHelper;
|
||||
using Xylem.Common.Metrology.Measurements;
|
||||
using Xylem.Common.Metrology.Measurements.Consts;
|
||||
using Xylem.Common.Utils.Logging;
|
||||
@@ -36,50 +34,20 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
/// </summary>
|
||||
public class MagFluxMeter : IMeter, IMeterEvents
|
||||
{
|
||||
#region class handling
|
||||
#region Variables and Properties
|
||||
|
||||
/// <summary>
|
||||
/// Ctor - default
|
||||
/// Enable raw record logging, if set every incoming package will be logged
|
||||
/// </summary>
|
||||
/// <remarks date="2023-Apr-20" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public MagFluxMeter()
|
||||
{
|
||||
SetLogger();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
private Boolean _enableRawDataLogging;
|
||||
|
||||
/// <summary>
|
||||
/// Ctor
|
||||
/// to reduce the IrdA communication in test bench, preparation will be done once (when SkipPreparationForTestBench is true)
|
||||
/// </summary>
|
||||
/// <param name="slot">Slot number for test-bench </param>
|
||||
/// <param name="requestPort"><see cref="PortConfig" /> for request Port</param>
|
||||
/// <param name="streamingPort"><see cref="PortConfig" /> for streaming Port</param>
|
||||
/// <param name="ignoreCorruptedData">don´t send CRC error or telegrams with error flag to caller</param>
|
||||
/// <param name="password">
|
||||
/// If you have a password for highest access level you need, if you don't want to access the meter
|
||||
/// (just read led record) than you can leave it null
|
||||
/// </param>
|
||||
/// <remarks date="2023-Apr-20" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public MagFluxMeter(Int32 slot, PortConfig? requestPort, PortConfig? streamingPort,
|
||||
Boolean ignoreCorruptedData = true, String password = null)
|
||||
public Boolean SkipPreparationForTestBench
|
||||
{
|
||||
_logger = NLogHelper.CreateOrGetMultiLogger($"Slot:{slot}", "Slot", "Meter", "MeterBase", "MeterBase");
|
||||
SetupMagFluxMeter(slot, requestPort, streamingPort, ignoreCorruptedData, password);
|
||||
get; set;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region variables and properties
|
||||
|
||||
/// <summary>
|
||||
/// List of ongoing measurements, base- and calibration-measurements
|
||||
/// </summary>
|
||||
@@ -251,107 +219,211 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
|
||||
#endregion
|
||||
|
||||
#region events
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeter.OnProcessStatusChanged
|
||||
#region Events
|
||||
|
||||
event EventHandler IMeter.OnDisposeCompleted
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
add
|
||||
{
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
|
||||
remove
|
||||
{
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
//public event EventHandler<StringEventArgs> HasInformationForCaller;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnCalibCompleted;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnErrorStatusChanged;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnProcessStatusChanged;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnCalibInitCompleted;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnInitCompleted;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnMeasurementInitCompleted;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnMeasurementCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// Response received after request for record
|
||||
/// </summary>
|
||||
public event EventHandler<RequestResponseDataEventArgs> OnRequestRecordReceived;
|
||||
|
||||
/// <summary>
|
||||
/// call this if session is expired and you need an re-authorization
|
||||
/// </summary>
|
||||
//public EventHandler<AuthorizationRequiredEventArgs> AuthorizationRequired;
|
||||
|
||||
/// <summary>
|
||||
/// A helper to invoke events only if someone is listening, otherwise nothing will happen
|
||||
/// </summary>
|
||||
/// <param name="handler">Event handler to call</param>
|
||||
/// <param name="sender">Sender (can be null)</param>
|
||||
/// <param name="e">Event arguments (can be null)</param>
|
||||
private void Invoker(EventHandler handler, Object sender = null, EventArgs e = null)
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
if (sender == null)
|
||||
{
|
||||
sender = this;
|
||||
}
|
||||
|
||||
if (e == null)
|
||||
{
|
||||
e = new EventArgs();
|
||||
}
|
||||
|
||||
handler.Invoke(sender, e);
|
||||
}
|
||||
// ReSharper disable once RedundantIfElseBlock
|
||||
else
|
||||
{
|
||||
//nobody is listening
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Track all incoming led record packages (Calibration and Flow)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e">
|
||||
/// I should be <see cref="FlowTestRecord" /> or <see cref="CalibDataEventArgs" />
|
||||
/// otherwise this method does nothing
|
||||
/// </param>
|
||||
private void StreamingProtocol_ApplyDecodedRecord(Object sender, BaseDataEventArgs e)
|
||||
{
|
||||
var result = e.GetEventData();
|
||||
if (result is IMeasurementRecord)
|
||||
{
|
||||
if (result is MagFluxRecord)
|
||||
{
|
||||
if (!((MagFluxRecord)result).IsValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AddData(((IMeasurementRecord)result));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// tracking request record processing
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void RequestProtocol_ApplyDecodedRecord(Object sender, BaseDataEventArgs e)
|
||||
{
|
||||
if (e is RequestResponseDataEventArgs)
|
||||
{
|
||||
OnRequestRecordReceived?.Invoke(sender, (RequestResponseDataEventArgs)e);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region class handling
|
||||
|
||||
/// <summary>
|
||||
/// Ctor - default
|
||||
/// </summary>
|
||||
/// <remarks date="2023-Apr-20" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public MagFluxMeter()
|
||||
{
|
||||
SetLogger();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeterEvents.OnErrorStatusChanged
|
||||
public void Dispose()
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
_logger.Trace($"Slot:{Slot} - Start to dispose");
|
||||
|
||||
LogRawData(false);
|
||||
LogManager.Flush();
|
||||
//isPart of Logout
|
||||
//StopKeepSession();
|
||||
|
||||
//Cancel receive tokens
|
||||
_keepSessionToken?.Cancel();
|
||||
|
||||
try
|
||||
{
|
||||
Logout();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeterEvents.OnInitCompleted
|
||||
|
||||
//Run thread again to notice CancellationToken has changed
|
||||
_onSyncKeepSessionThread?.Set();
|
||||
|
||||
//this timeout counter is being used for dispose only
|
||||
var timeoutCounter = 100;
|
||||
if (_keepSessionThread != null)
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
while (_keepSessionThread.ThreadState != ThreadState.Stopped && timeoutCounter > 0)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
timeoutCounter -= 1;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeterEvents.OnMeasurementInitCompleted
|
||||
if (_keepSessionThread.ThreadState != ThreadState.Stopped)
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
//if thread is still running try to abort
|
||||
// try to avoid abort (takes age to run and is not safe)
|
||||
_keepSessionThread.Abort();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeterEvents.OnMeasurementCompleted
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
_keepSessionThread = null;
|
||||
|
||||
RequestPort?.Dispose();
|
||||
StreamingPort?.Dispose();
|
||||
|
||||
RequestProtocol?.Dispose();
|
||||
StreamingProtocol?.Dispose();
|
||||
_logger.Trace($"Slot:{Slot} - Dispose is finished");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeterEvents.OnCalibInitCompleted
|
||||
|
||||
/// <summary>
|
||||
/// Ctor
|
||||
/// </summary>
|
||||
/// <param name="slot">Slot number for test-bench </param>
|
||||
/// <param name="requestPort"><see cref="PortConfig" /> for request Port</param>
|
||||
/// <param name="streamingPort"><see cref="PortConfig" /> for streaming Port</param>
|
||||
/// <param name="ignoreCorruptedData">don´t send CRC error or telegrams with error flag to caller</param>
|
||||
/// <param name="password">
|
||||
/// If you have a password for highest access level you need, if you don't want to access the meter
|
||||
/// (just read led record) than you can leave it null
|
||||
/// </param>
|
||||
/// <remarks date="2023-Apr-20" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public MagFluxMeter(Int32 slot, PortConfig? requestPort, PortConfig? streamingPort,
|
||||
Boolean ignoreCorruptedData = true, String password = null)
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
_logger = NLogHelper.CreateOrGetMultiLogger($"Slot:{slot}", "Slot", "Meter", "MeterBase", "MeterBase");
|
||||
SetupMagFluxMeter(slot, requestPort, streamingPort, ignoreCorruptedData, password);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeterEvents.OnCalibCompleted
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeterEvents.OnProcessStatusChanged
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeter.OnErrorStatusChanged
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeter.OnInitCompleted
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeter.OnMeasurementInitCompleted
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeter.OnMeasurementCompleted
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeter.OnCalibInitCompleted
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
event EventHandler IMeter.OnCalibCompleted
|
||||
{
|
||||
add => throw new NotImplementedException();
|
||||
remove => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler OnDisposeCompleted;
|
||||
#endregion
|
||||
|
||||
#region MagFlux handling
|
||||
@@ -402,9 +474,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
_logger.Debug($"Slot:{Slot} - Setup done");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Start Event listening, has to be called after <see cref="SetupMagFluxMeter" />
|
||||
@@ -565,7 +634,21 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
/// <inheritdoc />
|
||||
public void InitMeasurement()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_logger.Info($"Slot:{Slot} - Init measurement");
|
||||
PreMeasurement();
|
||||
}
|
||||
|
||||
private void PreMeasurement()
|
||||
{
|
||||
if (!SkipPreparationForTestBench)
|
||||
{
|
||||
SkipPreparationForTestBench = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLog($"wait for measurement is starting");
|
||||
}
|
||||
ProcessStatus = ProcessState.WaitForMeasurement;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -606,50 +689,132 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
public MeasurementResults GetMainMeasurementResult(Double? refVolume, Double? refTimeS,
|
||||
Boolean intermediateMeasurement = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (!intermediateMeasurement && GetMeasurementState(0) != MeasurementStates.IsCompleted)
|
||||
{
|
||||
throw new ApplicationException("Measurement is not completed");
|
||||
}
|
||||
return GetAllMeasurementResults(refVolume, refTimeS, intermediateMeasurement, 0).First();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<MeasurementResults> GetAllMeasurementResults(Double? refVolume, Double? refTimeS, Boolean intermediateMeasurement = false,
|
||||
Int32? channel = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (!intermediateMeasurement && GetMeasurementState(channel) != MeasurementStates.IsCompleted)
|
||||
{
|
||||
throw new ApplicationException("Measurement is not completed");
|
||||
}
|
||||
var mainMeasurement = _listOfIMeasurement.FirstOrDefault(m => m.GetType() == typeof(MagFluxRecord));
|
||||
|
||||
if (mainMeasurement == null)
|
||||
{
|
||||
throw new ApplicationException("Can not find an ongoing measurement");
|
||||
}
|
||||
|
||||
var results = new List<MeasurementResults>();
|
||||
var mainResult = intermediateMeasurement
|
||||
? mainMeasurement.GetIntermediateMeasurementResult(refVolume, refTimeS)
|
||||
: mainMeasurement.GetFinalMeasurementResult(refVolume, refTimeS);
|
||||
results.Add(mainResult);
|
||||
_logger.Info($"Slot:{Slot}, Channel:{mainMeasurement.GetChannel()} - MeasuredTime({mainResult.DutTimeS}s), " +
|
||||
$"MeasuredVolume({mainResult.DutVolumeCm}Qm)");
|
||||
|
||||
foreach (var otherMeasurement in _listOfIMeasurement.Where(m => m.GetType() != typeof(MagFluxRecord)))
|
||||
{
|
||||
try
|
||||
{
|
||||
var otherResults = intermediateMeasurement
|
||||
? otherMeasurement.GetIntermediateMeasurementResult(refVolume, refTimeS)
|
||||
: otherMeasurement.GetFinalMeasurementResult(refVolume, refTimeS);
|
||||
_logger.Info($"Slot:{Slot}, Channel:{otherMeasurement.GetChannel()} - ChannelTime({otherResults.DutTimeS}s), " +
|
||||
$"ChannelVolume({otherResults.DutVolumeCm}Qm)");
|
||||
results.Add(otherResults);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn($"Slot:{Slot}, No Results for channel:{otherMeasurement.GetChannel()} Ex: {ex.Message}");
|
||||
if (channel == null)
|
||||
{
|
||||
throw new ApplicationException($"Can not read result from channel:{otherMeasurement.GetChannel() } Ex: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public MeasurementStates GetMeasurementState(Int32? onlyChannelNr = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_logger.Trace($"Slot:{Slot} - Get measurement state");
|
||||
if (!_listOfIMeasurement.Any())
|
||||
{
|
||||
return MeasurementStates.NotStarted;
|
||||
}
|
||||
|
||||
if (onlyChannelNr.HasValue)
|
||||
{
|
||||
var measurement = _listOfIMeasurement.First(f => f.GetChannel() == onlyChannelNr.Value);
|
||||
return measurement.GetMeasurementState();
|
||||
}
|
||||
return _listOfIMeasurement.Min(m => m.MeasurementState);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Boolean RequestIntermediateMeasurementState(Int32? onlyChannelNr = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_logger.Trace($"Slot:{Slot} - Get measurement state");
|
||||
if (!_listOfIMeasurement.Any())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Boolean? ret = null;
|
||||
foreach (var item in _listOfIMeasurement)
|
||||
{
|
||||
if (!onlyChannelNr.HasValue || item.GetChannel() == onlyChannelNr.Value)
|
||||
{
|
||||
var measurement = _listOfIMeasurement.First(f => onlyChannelNr != null && f.GetChannel() == onlyChannelNr.Value);
|
||||
if ((measurement.MeasurementState == MeasurementStates.IsRunning
|
||||
|| measurement.MeasurementState == MeasurementStates.IsWaitingForIntermediateData))
|
||||
{
|
||||
measurement.RequestIntermediateRecord();
|
||||
if (!ret.HasValue)
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret.HasValue ? ret.Value : false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void InitCalibration()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_logger.Info($"Slot:{Slot} - Init calibration and set calibration values of all channels to default");
|
||||
PreMeasurement();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void StartCalibration()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
StartMeasurement();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void StopCalibration()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
StopMeasurement();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public MeasurementStates GetCalibrationState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return GetMeasurementState();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -686,13 +851,27 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
/// <inheritdoc />
|
||||
public void WriteLog(String text)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_logger.Info($"Slot:{Slot} - {text}");
|
||||
//if (_enableRawDataLogging)
|
||||
//{
|
||||
// if (_loggerRawData == null)
|
||||
// {
|
||||
// _loggerRawData = NLogHelper.CreateOrGetMultiLogger(
|
||||
// StreamingPort.GetPortName(), "", "LedRawData", "TargetLedRawDataBase", "LedRawDataBase");
|
||||
|
||||
// }
|
||||
// _loggerRawData.Info($"{text}");
|
||||
//}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogRawData(Boolean on)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_enableRawDataLogging = on;
|
||||
if (StreamingPort is LedSerialPort port)
|
||||
{
|
||||
port.RecordStreamingRawData = _enableRawDataLogging;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -733,109 +912,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
//public event EventHandler<StringEventArgs> HasInformationForCaller;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnCalibCompleted;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnErrorStatusChanged;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnProcessStatusChanged;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnCalibInitCompleted;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnInitCompleted;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnMeasurementInitCompleted;
|
||||
|
||||
/// <inheritdoc cref="IMeter" />
|
||||
public event EventHandler OnMeasurementCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// Response received after request for record
|
||||
/// </summary>
|
||||
public event EventHandler<RequestResponseDataEventArgs> OnRequestRecordReceived;
|
||||
|
||||
/// <summary>
|
||||
/// call this if session is expired and you need an re-authorization
|
||||
/// </summary>
|
||||
//public EventHandler<AuthorizationRequiredEventArgs> AuthorizationRequired;
|
||||
|
||||
/// <summary>
|
||||
/// A helper to invoke events only if someone is listening, otherwise nothing will happen
|
||||
/// </summary>
|
||||
/// <param name="handler">Event handler to call</param>
|
||||
/// <param name="sender">Sender (can be null)</param>
|
||||
/// <param name="e">Event arguments (can be null)</param>
|
||||
private void Invoker(EventHandler handler, Object sender = null, EventArgs e = null)
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
if (sender == null)
|
||||
{
|
||||
sender = this;
|
||||
}
|
||||
|
||||
if (e == null)
|
||||
{
|
||||
e = new EventArgs();
|
||||
}
|
||||
|
||||
handler.Invoke(sender, e);
|
||||
}
|
||||
// ReSharper disable once RedundantIfElseBlock
|
||||
else
|
||||
{
|
||||
//nobody is listening
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Track all incoming led record packages (Calibration and Flow)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e">
|
||||
/// I should be <see cref="FlowTestRecord" /> or <see cref="CalibDataEventArgs" />
|
||||
/// otherwise this method does nothing
|
||||
/// </param>
|
||||
private void StreamingProtocol_ApplyDecodedRecord(Object sender, BaseDataEventArgs e)
|
||||
{
|
||||
var result = e.GetEventData();
|
||||
if (result is IMeasurementRecord)
|
||||
{
|
||||
if (result is MagFluxRecord)
|
||||
{
|
||||
if (!((MagFluxRecord)result).IsValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AddData(((IMeasurementRecord)result));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// tracking request record processing
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void RequestProtocol_ApplyDecodedRecord(Object sender, BaseDataEventArgs e)
|
||||
{
|
||||
if (e is RequestResponseDataEventArgs)
|
||||
{
|
||||
OnRequestRecordReceived?.Invoke(sender, (RequestResponseDataEventArgs)e);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region logging
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol
|
||||
_logger = NLogHelper.CreateOrGetMultiLogger(ident, "", "RequestProtocol", "MeterBase", "MeterBase");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <inheritdoc />
|
||||
public override event EventHandler<BasePortDataEventArgs> OnRecordReadyToSend;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user