80 lines
3.7 KiB
C#
80 lines
3.7 KiB
C#
using System;
|
|
|
|
namespace Xylem.Common.Metrology.Measurements
|
|
{
|
|
/// <inheritdoc />
|
|
/// <summary>
|
|
/// Holds all stuff for calibration of a Genesis Meter
|
|
/// </summary>
|
|
public class CalibrationMeasurement : BaseMeasurement
|
|
{
|
|
/// <summary>
|
|
/// Calibration default value used to reset meter calibration
|
|
/// </summary>
|
|
private const Double CalibFactorRelativeDefault = 1.0;
|
|
|
|
/// <summary>
|
|
/// relative value (e.g. 0.05)
|
|
/// </summary>
|
|
private Double _calibFactorToleranceRelative = 0.05;
|
|
|
|
/// <summary>
|
|
/// Setup the required tolerance in percent for check (e.g. 5 = +/-5%)
|
|
/// </summary>
|
|
public Double CalibFactorTolerancePercent
|
|
{
|
|
get { return _calibFactorToleranceRelative * 100; }
|
|
set { _calibFactorToleranceRelative = value / 100; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check the tolerance of the calibration factor (e.g. 0.95 to 1.05 at 0.05 tolerance)
|
|
/// </summary>
|
|
/// <param name="calibFactorToCheck"></param>
|
|
/// <returns>true if the calibration factor is inside the tolerance </returns>
|
|
public Boolean IsCalibFactorInTolerance(Double calibFactorToCheck)
|
|
{
|
|
return (calibFactorToCheck <= _calibFactorToleranceRelative + CalibFactorRelativeDefault
|
|
&& calibFactorToCheck >= _calibFactorToleranceRelative - CalibFactorRelativeDefault);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
/// <summary>
|
|
/// Remind the calibration factor for the register write access
|
|
/// </summary>
|
|
/// <param name="slot"></param>
|
|
/// <param name="measurementRecordType">FlowTestRecord or CalibrationRecord</param>
|
|
/// <param name="intermediateUpdateTimeS">Update time needed for overflow detection in seconds</param>
|
|
/// <param name="channel"></param>
|
|
public CalibrationMeasurement(Int32 slot, Type measurementRecordType, Int32 intermediateUpdateTimeS, Int32 channel)
|
|
: base(slot, measurementRecordType, intermediateUpdateTimeS, channel)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calculate calibration factor from reference volume and reference time if set.
|
|
/// The deviation can adjust the factor to a required offset, it may be useful not to calibrate to 0.0).
|
|
/// The Result is NOT being stored to the meter.
|
|
/// CAN BE USED FOR STATIC START/STOP AND FLYING START/STOP PROCEDURE
|
|
/// </summary>
|
|
/// <param name="refVolumeCm">reference volume in m³</param>
|
|
/// <param name="refTimeS">reference time in seconds</param>
|
|
/// <param name="reqDeviationPercent">the deviation to set the calibration in %</param>
|
|
/// <returns> calibration factor as relative value or null if calibration factor cannot be calculated</returns>
|
|
/// <history date="06-Dec-2018" author="Thomas Wiedebusch">
|
|
/// - The scale factor for calibration is going to adjusted here to keep the measurement result accurate.
|
|
/// </history>
|
|
public Double? CalculateCalibFactorRel(Double refVolumeCm, Double? refTimeS = null, Double reqDeviationPercent = 0.0)
|
|
{
|
|
//the deviation can be positive or negative
|
|
var reqDeviationRel = 1.0 + reqDeviationPercent / 100;
|
|
|
|
//for calibration the RefVolumeCm is essential, the refTimeS is needed for flying start/stop
|
|
var measurementResult = GetFinalMeasurementResult(refVolumeCm, refTimeS);
|
|
//todo recalcualted
|
|
//adjust the calibration scale factor to the required deviation
|
|
return measurementResult.ScaleFactorRefToDut * reqDeviationRel;
|
|
}
|
|
}
|
|
}
|