Files
DP44/DataPRO/IService/Classes/Diagnostics/DiagnosticsResult.cs
2026-04-17 14:55:32 -04:00

195 lines
9.4 KiB
C#

using DTS.Common.Enums.Sensors;
using DTS.Common.Interface.DASFactory.Diagnostics;
namespace DTS.DASLib.Service
{
/// <summary>
/// This class holds the results from one channel's diagnostics. These results are arbitrary on
/// thier own but can be checked against the hardware specifications or settings for the sensor on the
/// corresponding channel to provide pre-recording checks or diagnostic feedback about how the channel is
/// set up. For example this DiagnosticsResult will provide the acutal voltage that is being applied to
/// sensor for excitation, and this can be verified correct or incorrect based on what the sensor
/// actually needs for excitation. The sensor specific values can be found in the corresponding DASChannel
/// (<see cref="AnalogInputDASChannel" />) object in the ConfigData object for the IDASCommunication where this channel lives,
/// but they must be put there by a call to ConfigureService.Configure(...).
/// </summary>
public class DiagnosticsResult : IDiagnosticResult
{
/// <summary>
/// Which DASChannel from which this diagnostics is returning.
/// </summary>
public int DASChannelNumber { get; set; }
/// <summary>
/// The event number that this diagnostics is relevant for.
/// </summary>
public int EventNumber { get; set; }
/// <summary>
/// The firmware calculates a scale factory for the channel's input. The hardware will
/// deliver raw, unprocessed data upon download, but to diagnos this data to
/// reflect real world votages it must be scaled based on the DAS unit's factory
/// diagnostics as well as results from this diagnose. The samples that
/// will be downloaded will be straight from the A to D Converter so this scale
/// factor is MANDATORY and must be used at the software level to scale the data
/// to the real sensed voltages and engineering units.
/// </summary>
public double ScalefactorMilliVoltsPerADC { get; set; } = 1;
public double ScalefactorEngineeringUnitsPerADC { get; set; } = 1;
/// <summary>
/// The factory excitation value (mandatory)
/// </summary>
public double ExpectedExcitationMilliVolts { get; set; }
/// <summary>
/// gets what will probably be the datazerolevel adc for the channel
/// </summary>
/// <param name="zeroMethod"></param>
/// <returns></returns>
public short GetExpectedDataZeroLevelADC(ZeroMethodType zeroMethod)
{
switch (zeroMethod)
{
case ZeroMethodType.None:
return ZeroMVInADC;
default:
// if FinalOffsetADC is NOT null, offset has been measured after calibration
// and that's the amount is what we should use
if (FinalOffsetADC != null)
{
return (short)FinalOffsetADC;
}
// OK, FinalOffsetADC was null so we need to check MeasuredOffsetMilliVolts
// if it's NOT null, that's what we'll use
if (MeasuredOffsetMilliVolts != null)
{
return (short)((double)MeasuredOffsetMilliVolts / ScalefactorMilliVoltsPerADC);
}
// both of them are null so the only thing we can do is return 0
return 0;
}
}
/// <summary>
/// Excitation voltage provided to sensor as measured by the firmware during
/// calibration. When read from event attributes, a value of 0.0 might actually
/// mean null (i.e. was not measured).
/// </summary>
public double? MeasuredExcitationMilliVolts { get; set; }
/// <summary>
/// flag to indicate whether MeasuredExcitationMilliVolts was negative when it was initially read
/// 14233 Negative Excitation Reported by TDAS hardware not showing in Diagnostics
/// this was created to relate to legacy TDC/TDAS broken sensor/wire warnings carried through
/// the excitation reading
/// </summary>
public bool NegativeExcitation { get; set; }
/// <summary>
/// What is the sensor's offset reading from the 0 level? This is measured by firmware
/// during the calibration. When read from event attributes, a value of 0.0 might actually
/// mean null (i.e. was not measured).
/// </summary>
public double? MeasuredOffsetMilliVolts { get; set; }
public double? MeasuredInternalOffsetMilliVolts { get; set; }
/// <summary>
/// What is the sensor's offset reading from the 0 level? This is measured by firmware
/// during the calibration. When read from event attributes, a value of 0.0 might actually
/// mean null (i.e. was not measured).
/// </summary>
public double? MeasuredOffsetEngineeringUnits { get; set; }
/// <summary>
/// when a channel is autozero'd (remove offset)
/// this is the devation from 0 (from RW Auto zero is checking for +/- 5% from 0 in counts.)
/// </summary>
private double? _autoZeroPercentDeviation;
public double? AutoZeroPercentDeviation
{
get => _autoZeroPercentDeviation;
set => _autoZeroPercentDeviation = null != value ? (double?)System.Math.Abs((double)value) : null;
}
/// <summary>
/// If the <see cref="DTS.DASLib.Service.DiagnosticsService" />.Calibrate method was called with the "RemoveOffset" boolean variable set
/// to TRUE then the firmware will attempt to remove the offset of the sensor, moving it's base
/// reading back to 0. This value is how much offset is present after removing the offset. While the
/// offset my not be compeletely removed it may have been reduced to fall within the high and low
/// limits for acceptable offsets for the sensor. See <see cref="AnalogInputDASChannel" /> to find
/// these sensor specific values. When read from event attributes, a value of 0.0 might actually
/// mean null (i.e. was not measured).
/// </summary>
public short? FinalOffsetADC { get; set; }
public int? RemovedOffsetADC { get; set; }
public int? RemovedInternalOffsetADC { get; set; }
/// <summary>
/// FullScaleSignal to Noise ratio as a percentage. When read from event attributes, a value of 0.0 might actually
/// mean null (i.e. was not measured).
/// </summary>
public double? NoisePercentFullScale { get; set; }
public bool ShuntDeflectionFailed { get; set; }
public bool CalSignalCheckFailed { get; set; }
/// <summary>
/// If an emulated shunt test is performed the measured shunt deflection in mV detected
/// during the test will be here.
/// <see cref="DTS.DASLib.Service.DiagnosticsActions" />.PerformShuntCheck
/// When read from event attributes, a value of 0.0 might actually mean null
/// (i.e. was not measured).
/// </summary>
public double? MeasuredShuntDeflectionMv { get; set; }
public double? MeasuredCalSignalMv { get; set; }
public double? TargetCalSignalMv { get; set; }
public double? MeasuredDurationMS { get; set; }
public double? MeasuredDelayMS { get; set; }
public bool? SquibFirePassed { get; set; }
public bool? SquibDurationPassed { get; set; }
public bool? SquibDelayPassed { get; set; }
public double[] SquibFireCurrentData { get; set; }
public double[] SquibFireVoltageData { get; set; }
public double[] SquibFireTimeAxis { get; set; }
public double SquibThreshold { get; set; }
public double SquibVoltageScaler { get; set; }
public double SquibCurrentScaler { get; set; }
public double? TargetGain { get; set; }
public double? MeasuredGain { get; set; }
public double? QueriedGain { get; set; }
/// <summary>
/// If an emulated shunt test is performed the target shunt deflection in mV will be here.
/// CalibrateActions.PerformShuntCheck When read from event attributes, a value of 0.0 might actually
/// mean null (i.e. was not measured).
/// </summary>
public double? TargetShuntDeflectionMv { get; set; }
/// <summary>
/// If the bridge resistance of the sensor was measured, the measured resistance in
/// ohms will be here. <see cref="DiagnosticsActions.MeasureBridgeResistance" />
/// When read from event attributes, a value of 0.0 might actually mean null
/// (i.e. was not measured).
/// </summary>
public double? BridgeResistance { get; set; }
public short ZeroMVInADC { get; set; } = 0;
/// <summary>
/// WindowAverageADC is the average ADC over the averaging window specified for the channel
/// short.MinValue indicates an unitialized or invalid value
/// </summary>
public short WindowAverageADC { get; set; } = short.MinValue;
public bool DigitalInputActiveState { get; set; }
}
}