MagFlux: - api 1.0.2.49

This commit is contained in:
Thomas Wiedebusch
2024-09-19 15:06:41 +02:00
parent bcc19ac7b9
commit a4e62405d3
13 changed files with 267 additions and 132 deletions
@@ -56,12 +56,6 @@ namespace XYLEM
/// <param name="baudRate">Like 9600 (default on RS485)</param>
/// <param name="parity">Like Parity.Even (default on RS485)</param>
/// <returns></returns>
Boolean Connect(string comport, UInt16 id, UInt32 baudRate, Parity parity);
/// <summary>
/// Close communication connection to Meter
/// </summary>
/// <returns>true on okay or false on error</returns>
Boolean CloseConnection();
Boolean Connect(string comport, UInt16 id, UInt32 baudRate, Parity parity);
}
}
@@ -1,11 +1,11 @@
using System.IO.Ports;
using System;
using System.IO.Ports;
using XYLEM.Device;
namespace XYLEM
{
public interface IMagFluxAPI
{
/// <summary>
/// Make communication connection to Meter
///
@@ -36,5 +36,12 @@ namespace XYLEM
/// <returns>Return a MagFlux device or "null" if failing connect</returns>
/// <exception cref="InvalidDataException"> if the configuration is not valid</exception>
IMagFluxRequestProtocol Connect(string comport, ushort id, uint baudRate, Parity parity, string log_path = null, RUN_TYPE runAs = RUN_TYPE.Normal);
/// <summary>
/// Close communication connection to all Meters and clean up for a fresh connection of all devices.
/// Note to continue, all devices needs initialized to be reconnected with Connect(...)
/// </summary>
/// <returns>true on okay or false on error</returns>
Boolean CloseConnections();
}
}
@@ -16,6 +16,20 @@ namespace XYLEM
/// <returns>true if yes</returns>
Boolean IsConnected();
/// <summary>
/// Close communication connection to Meter
/// </summary>
/// <returns>true on okay or false on error</returns>
Boolean CloseConnection();
/// <summary>
/// Try reconnect communication to a Meter that already had a communication connection
/// Note: will reuse already used communication settings and CloseConnection() is not already closed before call.
/// Used for reestablished communication to Meter when fail to respond during normal operation
/// </summary>
/// <returns>true on okay or false on error</returns>
Boolean Reconnect();
/// <summary>
/// Get current device Modbus ID / Device Address
/// </summary>
@@ -147,6 +161,22 @@ namespace XYLEM
/// <returns>true on okay or false on error</returns>
Boolean GetFlowRate_lps(out Single value_out);
/// <summary>
/// Average Electrode measurement used for Device calibration verification
/// </summary>
/// <param name="value_out"> Average Electrode [mV] </param>
/// <returns>true on okay or false on error</returns>
Boolean GetAverage_Electrode_mV(out Single value_out);
/// <summary>
/// Standard deviation electrode measurement used for Device calibration verification
/// Note: update will only happen after x seconds, depending on filter config in device
/// </summary>
/// <param name="value_out"> Average Electrode [mV] </param>
/// <returns>true on okay or false on error</returns>
Boolean GetStdDev_Electrode_mV(out Single value_out);
/// <summary>
/// !!! Warning make sure to turn off simulation, when calibration off sensor is done !!!
/// ----
@@ -37,6 +37,14 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
{
#region Variables and Properties
///// <summary>
///// Reminder for ignore empty pipe detection
///// </summary>
//private Boolean _lastIgnoreEmptyPipeDetection;
///// <summary>
///// Reminder for simulated flow
///// </summary>
//private Boolean _lastSimulatedFlowActive;
/// <summary>
/// Reminder for status bits
/// </summary>
@@ -51,6 +59,20 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
/// </summary>
private Boolean _enableRawDataLogging;
/// <summary>
/// Simulated flow activity
/// </summary>
public Boolean SimulatedFlowIsActive
{
get; set;
}
/// <summary>
/// Empty pipe ignore
/// </summary>
public Boolean IgnoreEmptyPipeDetection
{
get; set;
}
/// <summary>
/// to reduce the IrdA communication in test bench, preparation will be done once (when SkipPreparationForTestBench is true)
/// </summary>
@@ -123,6 +145,22 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
get; private set;
}
/// <summary>
/// Average of the electrode in milli Volts
/// </summary>
public Single AverageElectrode_mV
{
get; private set;
}
/// <summary>
/// Standard deviation of the electrode in milli Volts
/// </summary>
public Single StandardDeviationElectrode_mV
{
get; private set;
}
/// <summary>
/// Represents Empty Pipe Detection control bits
/// Bit0="EPD disabled", 1="Enabled w. Flags only", 2="EPD enabled full"
@@ -300,6 +338,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
private readonly CancellationTokenSource _keepSessionToken = new CancellationTokenSource();
private ILogger _logger;
//private ILogger _loggerRawData;
#endregion
@@ -859,9 +898,21 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
{
EpdControlBits = epd_cntl_bits;
}
RequestProtocol?.GetCalibrationPoints(out _);
StreamingProtocol?.SetDecodingMask(SensorSerialNo, uniqueId);
if (RequestProtocol.GetStdDev_Electrode_mV(out var u_mV))
{
StandardDeviationElectrode_mV = u_mV;
}
if (RequestProtocol.GetAverage_Electrode_mV(out u_mV))
{
AverageElectrode_mV = u_mV;
}
SimulatedFlowIsActive = RequestProtocol.IsSimulatedFlowActive();
IgnoreEmptyPipeDetection = RequestProtocol.GetIgnoreFailOnEmptyPipeOnHealthy();
RequestProtocol.GetCalibrationPoints(out _);
StreamingProtocol.SetDecodingMask(SensorSerialNo, uniqueId);
return IsLoggedOn;
}
@@ -886,7 +937,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
}
else
{
WriteLog("Wait on measurement start");
WriteLog($"Slot:{Slot} - Wait on measurement start");
}
ProcessStatus = ProcessState.WaitForMeasurement;
}
@@ -937,7 +988,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
}
/// <inheritdoc />
///
public List<MeasurementResults> GetAllMeasurementResults(Double? refVolume, Double? refTimeS, Boolean intermediateMeasurement = false,
Int32? channel = null, MeasurementDirection dir = MeasurementDirection.TakeBoth)
{
@@ -1052,7 +1102,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
/// </summary>
public void WriteCalibration(List<Calibration> calibrationsCmPerH)
{
_logger.Info($"Slot:{Slot} - Write calibration values to MagFlux");
RequestProtocol?.SetCalibrationPoints(calibrationsCmPerH);
RequestProtocol?.CloseConnection();
}
@@ -1062,40 +1111,58 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
public void ReadCalibration(out List<Calibration> calibrationsCmPerH)
{
calibrationsCmPerH = null;
_logger.Info($"Slot:{Slot} - Read calibration values from MagFlux");
RequestProtocol?.GetCalibrationPoints(out calibrationsCmPerH);
RequestProtocol?.CloseConnection();
}
///// <summary>
///// Turn on/off fixed test flow output from MagFlux
///// Used for getting a fixed simulated flow from MagFlux
///// </summary>
///// <param name="testFlowOn"></param>
///// <returns>true on okay or false on error</returns>
//public Boolean SetSimulatedFlowActive(Boolean testFlowOn)
//{
// _logger.Info($"Slot:{Slot} - Set test flow");
// return RequestProtocol.SetSimulatedFlowActive(on);
//}
/// <summary>
/// Average Electrode measurement used for Device calibration verification
/// </summary>
/// <param name="u_mV"> Average Electrode [mV] </param>
/// <returns>true on okay or false on error</returns>
public Boolean GetAverage_Electrode_mV(out Single u_mV)
{
u_mV = 0;
var retVal = RequestProtocol.GetAverage_Electrode_mV(out u_mV);
AverageElectrode_mV = u_mV;
return retVal;
}
///// <summary>
///// Is the fixed test flow active
///// Used for getting a fixed simulated flow from MagFlux
///// </summary>
///// <returns>true if ON</returns>
//public Boolean IsSimulatedFlowActive()
//{
// _logger.Info($"Slot:{Slot} - Get test flow setting");
// return RequestProtocol.IsSimulatedFlowActive();
//};
/// <summary>
/// Standard deviation electrode measurement used for Device calibration verification
/// Note: update will only happen after x seconds, depending on filter config in device
/// </summary>
/// <param name="u_mV"> Average Electrode [mV] </param>
/// <returns>true on okay or false on error</returns>
public Boolean GetStdDev_Electrode_mV(out Single u_mV)
{
u_mV = 0;
//_logger.Info($"Slot:{Slot} - Read standard deviation of electrode voltage");
var retVal = RequestProtocol.GetStdDev_Electrode_mV(out u_mV);
StandardDeviationElectrode_mV = u_mV;
return retVal;
}
/// <summary>
/// Ignore Empty pipe flag on Healthy, because it is not yet working correct
/// Note: Not 100% secure all test is working during empty pipe, metrology board firmware may not allow running during detection of empty pipe
/// </summary>
/// <param name="ignoreEmptyPipeStatus"></param>
/// <returns>true on okay or false on error</returns>
public Boolean SetIgnoreFailOnEmptyPipeOnHealthy(Boolean ignoreEmptyPipeStatus)
{
//_logger.Info($"Slot:{Slot} - Set ignore empty pipe status");
var retVal = RequestProtocol.SetIgnoreFailOnEmptyPipeOnHealthy(ignoreEmptyPipeStatus);
if (retVal)
IgnoreEmptyPipeDetection = ignoreEmptyPipeStatus;
return retVal;
}
/// <summary>
/// Set PCB settings and PCB calibrations to default.
/// </summary>
public Boolean SetPCBToDemoDefaults()
{
_logger.Info($"Slot:{Slot} - Set PCB settings and PCB calibrations to default");
if (RequestProtocol == null)
return false;
var retVal = RequestProtocol.SetPCBToDemoDefaults();
@@ -1108,7 +1175,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
/// </summary>
public Boolean SetMeterSizeMm(UInt16 meterSize_mm)
{
_logger.Info($"Slot:{Slot} - Set meter size in mm");
if (RequestProtocol == null)
return false;
var retVal = RequestProtocol.SetMeterSizeMm(meterSize_mm);
@@ -1121,7 +1187,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
/// </summary>
public Boolean SetSensorSerialNo(UInt32 sensorSerialNo)
{
_logger.Info($"Slot:{Slot} - Set sensor serial no.");
if (RequestProtocol == null)
return false;
var retVal = RequestProtocol.SetSensorSerialNo(sensorSerialNo);
@@ -1132,7 +1197,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
/// <inheritdoc />
public void InitCalibration()
{
_logger.Info($"Slot:{Slot} - Init calibration and set calibration values of all channels to default");
if (RequestProtocol == null)
return;
if (RequestProtocol.PrepareDeviceForCalibration())
@@ -1194,6 +1258,12 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
public void WriteLog(String text)
{
_logger.Info($"Slot:{Slot} - {text}");
}
/// <inheritdoc />
public void LogRawData(Boolean on)
{
_enableRawDataLogging = on;
//if (_enableRawDataLogging)
//{
// if (_loggerRawData == null)
@@ -1202,14 +1272,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
// StreamingPort.GetPortName(), "", "LedRawData", "TargetLedRawDataBase", "LedRawDataBase");
// }
// _loggerRawData.Info($"{text}");
//}
}
/// <inheritdoc />
public void LogRawData(Boolean on)
{
_enableRawDataLogging = on;
if (StreamingPort is LedSerialPort port)
{
port.RecordStreamingRawData = _enableRawDataLogging;
@@ -137,21 +137,21 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol
return retVal;
}
///// <summary>
///// Wrapper to get the simulated flow setting
///// </summary>
///// <returns></returns>
///// <remarks date="2024-Aug-23" author="T.Wiedebusch">
///// - Initial
///// </remarks>
//public Boolean GetSimulatedFlowOn()
//{
// if (_magFluxRequestProtocol == null) return false;
// var retVal = _magFluxRequestProtocol.IsSimulatedFlowActive();
// _logger.Debug(retVal ? $"{_ident} Simulated flow active read back returns: true" :
// $"{_ident} Read back simulated flow status failed!");
// return retVal;
//}
/// <summary>
/// Wrapper to get the simulated flow setting
/// </summary>
/// <returns></returns>
/// <remarks date="2024-Aug-23" author="T.Wiedebusch">
/// - Initial
/// </remarks>
public Boolean IsSimulatedFlowActive()
{
if (_magFluxRequestProtocol == null)
return false;
var retVal = _magFluxRequestProtocol.IsSimulatedFlowActive();
_logger.Debug($"{_ident} Simulated flow active read back returns: {retVal}");
return retVal;
}
///// <summary>
///// Wrapper to set the simulated flow setting
@@ -163,45 +163,48 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol
///// </remarks>
//public Boolean SetSimulatedFlowActive(Boolean on)
//{
// if (_magFluxRequestProtocol == null) return false;
// if (_magFluxRequestProtocol == null)
// return false;
// var retVal = _magFluxRequestProtocol.SetSimulatedFlowActive(on);
// _logger.Debug(retVal ? $"{_ident} Simulated flow active set to: {on}" :
// _logger.Debug(retVal ? $"{_ident} Simulated flow active set to: {on}" :
// $"{_ident} Simulated flow active setup failed!");
// return retVal;
//}
///// <summary>
///// Wrapper to get the ignore empty pipe mode status
///// </summary>
///// <returns></returns>
///// <remarks date="2024-Aug-23" author="T.Wiedebusch">
///// - Initial
///// </remarks>
//public Boolean GetIgnoreEmptyPipeStatus()
//{
// if (_magFluxRequestProtocol == null) return false;
// var retVal = _magFluxRequestProtocol.IgnoreFailOnEmptyPipeOnHealthy();
// _logger.Debug(retVal ? $"{_ident} Ignore empty pipe status read back returns: {retVal}" :
// $"{_ident} Read back empty pipe status failed!");
// return retVal;
//}
/// <summary>
/// Wrapper to get the ignore empty pipe mode status
/// </summary>
/// <returns></returns>
/// <remarks date="2024-Aug-23" author="T.Wiedebusch">
/// - Initial
/// </remarks>
public Boolean GetIgnoreFailOnEmptyPipeOnHealthy()
{
if (_magFluxRequestProtocol == null)
return false;
var retVal = _magFluxRequestProtocol.GetIgnoreFailOnEmptyPipeOnHealthy();
_logger.Debug($"{_ident} Ignore empty pipe status read back returns: {retVal}");
return retVal;
}
///// <summary>
///// Wrapper to set the ignore empty pipe mode
///// </summary>
///// <param name="on">true to ignore state</param>
///// <returns></returns>
///// <remarks date="2024-Aug-23" author="T.Wiedebusch">
///// - Initial
///// </remarks>
//public Boolean SetIgnoreEmptyPipeStatus(Boolean on)
//{
// if (_magFluxRequestProtocol == null) return false;
// var retVal = _magFluxRequestProtocol.IgnoreFailOnEmptyPipeOnHealthy(on);
// _logger.Debug(retVal ? $"{_ident} Ignore empty pipe status adjusted to: {on}" :
// $"{_ident} Setup empty pipe status request failed!");
// return retVal;
//}
/// <summary>
/// Wrapper to set the ignore empty pipe mode
/// </summary>
/// <param name="on">true to ignore state</param>
/// <returns></returns>
/// <remarks date="2024-Aug-23" author="T.Wiedebusch">
/// - Initial
/// </remarks>
public Boolean SetIgnoreFailOnEmptyPipeOnHealthy(Boolean on)
{
if (_magFluxRequestProtocol == null)
return false;
_magFluxRequestProtocol.SetIgnoreFailOnEmptyPipeOnHealthy(on);
var retVal = _magFluxRequestProtocol.GetIgnoreFailOnEmptyPipeOnHealthy();
_logger.Debug(retVal == on ? $"{_ident} Ignore empty pipe status adjusted to: {on}" :
$"{_ident} Ignore empty pipe status setup failed!");
return retVal == on;
}
/// <summary>
/// Wrapper to get the empty pipe bits
@@ -221,6 +224,41 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol
return retVal;
}
/// <summary>
/// Wrapper to get the standard deviation value of the electrode in milli Volts
/// </summary>
/// <param name="u_mV"></param>
/// <returns></returns>
/// <remarks date="2024-Sep-19" author="T.Wiedebusch">
/// - Initial
/// </remarks>
public Boolean GetStdDev_Electrode_mV(out Single u_mV)
{
u_mV = 0;
if (_magFluxRequestProtocol == null) return false;
var retVal = _magFluxRequestProtocol.GetStdDev_Electrode_mV(out u_mV);
_logger.Debug(retVal ? $"{_ident} Standard deviation of electrode: {u_mV:F6} mV" :
$"{_ident} Standard deviation of electrode request failed!");
return retVal;
}
/// <summary>
/// Wrapper to get the standard deviation value of the electrode in milli Volts
/// </summary>
/// <param name="u_mV"></param>
/// <returns></returns>
/// <remarks date="2024-Sep-19" author="T.Wiedebusch">
/// - Initial
/// </remarks>
public Boolean GetAverage_Electrode_mV(out Single u_mV)
{
u_mV = 0;
if (_magFluxRequestProtocol == null) return false;
var retVal = _magFluxRequestProtocol.GetAverage_Electrode_mV(out u_mV);
_logger.Debug(retVal ? $"{_ident} Average of electrode: {u_mV:F6} mV" :
$"{_ident} Average of electrode request failed!");
return retVal;
}
/// <summary>
/// Wrapper to get the board calibration value
/// </summary>
@@ -1 +1 @@
89102b0142e574de38a9f47d370f3334e5e6c268
8fbe991b217e7692af4817ad205b768685aa5a72