/* Test.Module.AnalogInputChannel.cs Copyright © 2008 Diversified Technical Systems, Inc. All Rights Reserved */ using System; using System.Linq; using System.Xml; using DTS.Common.Classes.Sensors; using DTS.Common.DAS.Concepts; using DTS.Common.Enums; using DTS.Common.Enums.Sensors; using DTS.Common.Utilities; using DTS.Common.Utilities.DotNetProgrammingConstructs; using DTS.Common.Utilities.Logging; using DTS.Common.Utilities.Xml; namespace DTS.Serialization { // *** see Test.cs *** public partial class Test { // *** see Test.Module.cs *** public partial class Module { /// /// Representation of an analog channel. /// [XmlSerializationTag("AnalogInputChanel")] public class AnalogInputChannel : Channel, Common.DAS.Concepts.DAS.Channel.IEngineeringUnitAware, Common.DAS.Concepts.DAS.Channel.IInversionAware, Common.DAS.Concepts.DAS.Channel.ISerialNumberAware, Common.DAS.Concepts.DAS.Channel.IIsoCodeAware, Common.DAS.Concepts.DAS.Channel.IShuntAware, Common.DAS.Concepts.DAS.Channel.ICalSignalAware, Common.DAS.Concepts.DAS.Channel.IVoltageInsertionAware, Common.DAS.Concepts.DAS.Channel.ILinearized { /// /// Initialize an instance of the class. /// /// /// /// The that contains this object. /// /// public AnalogInputChannel(Module parentModule) : base(parentModule) { } /// /// Get/set the bridge configuration of this channel. /// [XmlSerializationTag("Bridge")] public SensorConstants.BridgeType Bridge { get => _Bridge.Value; set => _Bridge.Value = value; } private readonly Property _Bridge = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.BridgeType", SensorConstants.BridgeType.FullBridge, false ); [XmlSerializationTag("ZeroPoint")] public double ZeroPoint { get { if (_ZeroPoint.IsValueInitialized) { return _ZeroPoint.Value; } return 0D; } set => _ZeroPoint.Value = value; } private readonly Property _ZeroPoint = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.ZeroPoint", 0D, false); /// /// Get/set the bridge resistance for this channel. /// [XmlSerializationTag("BridgeResistanceOhms")] public double BridgeResistanceOhms { get => _BridgeResistanceOhms.Value; set => _BridgeResistanceOhms.Value = value; } private readonly Property _BridgeResistanceOhms = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.BridgeResistanceOhms", 0.0, false ); /// /// Get/set the unit conversion for this channel. /// [XmlSerializationTag("UnitConversion")] public double UnitConversion { get => _UnitConversion.Value; set => _UnitConversion.Value = value; } private readonly Property _UnitConversion = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.UnitConversion", 1.0, false ); /// /// Get/set the multiplier for this channel. /// [XmlSerializationTag("Multiplier")] public double Multiplier { get => _Multiplier.Value; set => _Multiplier.Value = value; } private readonly Property _Multiplier = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.Multiplier", 1.0, false ); /// /// Get/set the modified offset for this channel. /// [XmlSerializationTag("UserOffsetEU")] public double UserOffsetEU { get => _UserOffsetEU.Value; set => _UserOffsetEU.Value = value; } private readonly Property _UserOffsetEU = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.UserOffsetEU", 0.0, false ); /// /// Get/set the description for this channel. /// [XmlSerializationTag("Description")] public string Description { get => _Description.Value ?? ""; set => _Description.Value = value; } private readonly Property _Description = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.Description", "", true ); /// /// Get/set the manufacture for this channel's sensor. /// [XmlSerializationTag("Manufacturer")] public string Manufacturer { get => _Manufacturer.Value ?? ""; set => _Manufacturer.Value = value; } private readonly Property _Manufacturer = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.Manufacturer", "", true ); /// /// Get/set the model for this channel's sensor. /// [XmlSerializationTag("Model")] public string Model { get => _Model.Value ?? ""; set => _Model.Value = value; } private readonly Property _Model = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.Model", "", true ); /// /// Get/set the model for this channel's sensor. /// [XmlSerializationTag("UserCode")] public string UserCode { get => _UserCode.Value ?? ""; set => _UserCode.Value = value; } private readonly Property _UserCode = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.UserCode", "", true ); /// /// Get/set the model for this channel's sensor. /// [XmlSerializationTag("UserChannelName")] public string UserChannelName { get => _UserChannelName.Value ?? ""; set => _UserChannelName.Value = value; } private readonly Property _UserChannelName = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.UserChannelName", "", true ); /// /// Get/set the model for this channel's sensor. /// [XmlSerializationTag("IsoChannelName")] public string IsoChannelName { get => _IsoChannelName.Value ?? ""; set => _IsoChannelName.Value = value; } private readonly Property _IsoChannelName = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.IsoChannelName", "", true ); /// /// Get/set the desired range for this channel. /// [XmlSerializationTag("DesiredRange")] public double DesiredRange { get => _DesiredRange.Value; set => _DesiredRange.Value = value; } private readonly Property _DesiredRange = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.DesiredRange", 0.0, false ); /// /// Get/set the sensitivity for this channel. /// [XmlSerializationTag("Sensitivity")] public double Sensitivity { get => _Sensitivity.Value; set => _Sensitivity.Value = value; } private readonly Property _Sensitivity = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.Sensitivity", 0.0, false ); /// /// Get/set the descriptor indiciating whether or not this channel is /// based on output at capacity. /// [XmlSerializationTag("AtCapacity")] public bool AtCapacity { get => _AtCapacity.Value; set => _AtCapacity.Value = value; } private readonly Property _AtCapacity = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.AtCapacity", false, true ); /// /// Get/set the capacity output is based on value for this channel. /// [XmlSerializationTag("CapacityOutputIsBasedOn")] public double CapacityOutputIsBasedOn { get => _CapacityOutputIsBasedOn.Value; set => _CapacityOutputIsBasedOn.Value = value; } private readonly Property _CapacityOutputIsBasedOn = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.CapacityOutputIsBasedOn", 1.000, true ); /// /// Get/set the Sensitivity Units for this channel. /// [XmlSerializationTag("SensitivityUnits")] public SensorConstants.SensUnits SensitivityUnits { get => _SensitivityUnits.Value; set => _SensitivityUnits.Value = value; } private readonly Property _SensitivityUnits = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.SensitivityUnits", SensorConstants.SensUnits.NONE, true ); /// /// Get/set the descriptor indiciating whether or not this channel is /// proportional to excitation. /// [XmlSerializationTag("ProportionalToExcitation")] public bool ProportionalToExcitation { get => _ProportionalToExcitation.Value; set => _ProportionalToExcitation.Value = value; } private readonly Property _ProportionalToExcitation = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.ProportionalToExcitation", false, false ); /// /// Get/set the excitation voltage for this channel. /// [XmlSerializationTag("ExcitationVoltage")] public ExcitationVoltageOptions.ExcitationVoltageOption ExcitationVoltage { get => _ExcitationVoltage.Value; set => _ExcitationVoltage.Value = value; } private readonly Property _ExcitationVoltage = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.ExcitationVoltage", ExcitationVoltageOptions.ExcitationVoltageOption.Volt5, false ); public bool MeasuredExcitationVoltageValid => _MeasuredExcitationVoltage.IsInitialized; /// /// Get/set the measured excitation value for this channel. /// [XmlSerializationTag("MeasuredExcitationVoltage")] public double MeasuredExcitationVoltage { get => _MeasuredExcitationVoltage.Value; set => _MeasuredExcitationVoltage.Value = value; } private readonly Property _MeasuredExcitationVoltage = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.MeasuredExcitationVoltage", 0.0, false ); public bool FactoryExcitationVoltageValid => _FactoryExcitationVoltage.IsInitialized; /// /// Get/set the factory excitation value for this channel. /// [XmlSerializationTag("FactoryExcitationVoltage")] public double FactoryExcitationVoltage { get => _FactoryExcitationVoltage.Value; set => _FactoryExcitationVoltage.Value = value; } private readonly Property _FactoryExcitationVoltage = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.FactoryExcitationVoltage", 0.0, false ); /// /// Get/set the engineering units for this channel. /// [XmlSerializationTag("Eu")] public string EngineeringUnits { get => _EngineeringUnits.Value; set => _EngineeringUnits.Value = value; } private readonly Property _EngineeringUnits = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.EngineeringUnits", null, false ); /// /// Get/set the ISO code for this channel's data source. /// [XmlSerializationTag("IsoCode")] public string IsoCode { get => _IsoCode.Value; set => _IsoCode.Value = value; } private readonly Property _IsoCode = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.IsoCode", null, false ); public bool IsIsoCodeValid => _IsoCode.IsInitialized; public bool MeasureShuntDeflectionMvValid => _MeasuredShuntDeflectionMv.IsInitialized; /// /// Get/set the measured shunt deflection value for this channel. /// [XmlSerializationTag("MeasuredShuntDeflectionMv")] public double MeasuredShuntDeflectionMv { get => _MeasuredShuntDeflectionMv.Value; set => _MeasuredShuntDeflectionMv.Value = value; } private readonly Property _MeasuredShuntDeflectionMv = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.MeasuredShuntDeflectionMv", 0.0, false ); public bool TargetShuntDeflectionMvValid => _TargetShuntDeflectionMv.IsInitialized; /// /// Get/set the measured gain value for this channel. /// [XmlSerializationTag("MeasuredGain")] public double MeasuredGain { get => _MeasuredGain.Value; set => _MeasuredGain.Value = value; } private readonly Property _MeasuredGain = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.MeasuredGain", 0.0, false ); public bool MeasuredGainValid => _MeasuredGain.IsInitialized; /// /// Get/set the expected gain value for this channel. /// [XmlSerializationTag("ExpectedGain")] public double ExpectedGain { get => _ExpectedGain.Value; set => _ExpectedGain.Value = value; } private readonly Property _ExpectedGain = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.ExpectedGain", 0.0, false ); public bool ExpectedGainValid => _ExpectedGain.IsInitialized; /// /// Get/set the target shunt deflection value for this channel. /// [XmlSerializationTag("TargetShuntDeflectionMv")] public double TargetShuntDeflectionMv { get => _TargetShuntDeflectionMv.Value; set => _TargetShuntDeflectionMv.Value = value; } private readonly Property _TargetShuntDeflectionMv = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.TargetShuntDeflectionMv", 0.0, false ); public bool IsDigital() { return Bridge == SensorConstants.BridgeType.DigitalInput; } public bool IsSquib() { return ParentModule.SerialNumber.StartsWith("TOM") || ParentModule.SerialNumber.StartsWith("SPT") || ParentModule.SerialNumber.StartsWith("SLT"); } /// /// Get the whether or not this is really a Squib channel. /// [XmlSerializationTag("IsSquibChannel")] public bool IsSquibChannel { get => IsSquib(); set => _isSquibChannel.Value = value; } private readonly Property _isSquibChannel = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.IsSquibChannel", false, false ); public bool IsSquibVoltage() { return IsSquib() && EngineeringUnits.Trim().Equals("V") && (ParentModule.SerialNumber.StartsWith("TOM") || ParentModule.SerialNumber.StartsWith("DR") || ParentModule.SerialNumber.StartsWith("SPT") || ParentModule.SerialNumber.StartsWith("SLT")); } public bool MeasuredCalSignalMvValid => _MeasuredCalSignalMv.IsInitialized; /// /// Get/set the measured shunt deflection value for this channel. /// [XmlSerializationTag("MeasuredCalSignalMv")] public double MeasuredCalSignalMv { get => _MeasuredCalSignalMv.Value; set => _MeasuredCalSignalMv.Value = value; } private readonly Property _MeasuredCalSignalMv = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.MeasuredCalSignalMv", 0.0, false ); public bool TargetCalSignalMvValid => _TargetCalSignalMv.IsInitialized; /// /// Get/set the target shunt deflection value for this channel. /// [XmlSerializationTag("TargetCalSignalMv")] public double TargetCalSignalMv { get => _TargetCalSignalMv.Value; set => _TargetCalSignalMv.Value = value; } private readonly Property _TargetCalSignalMv = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.TargetShuntCalSignalMv", 0.0, false ); public bool TriggerBelowThresholdValid => _TriggerBelowThresholdEu.IsInitialized; /// /// Get/set the "trigger below" threshold. Set to "null" to deactivate. /// [XmlSerializationTag("TriggerBelowThresholdEu")] public double? TriggerBelowThresholdEu { get => _TriggerBelowThresholdEu.Value; set => _TriggerBelowThresholdEu.Value = value; } private readonly Property _TriggerBelowThresholdEu = new Property( typeof(AnalogInputChannel).FullName + ".TriggerBelowThresholdEu", null, false ); public bool TriggerAboveThresholdValid => _TriggerAboveThresholdEu.IsInitialized; /// /// Get/set the "trigger above" threshold. Set to "null" to deactivate. /// [XmlSerializationTag("TriggerAboveThresholdEu")] public double? TriggerAboveThresholdEu { get => _TriggerAboveThresholdEu.Value; set => _TriggerAboveThresholdEu.Value = value; } private readonly Property _TriggerAboveThresholdEu = new Property( typeof(AnalogInputChannel).FullName + ".TriggerAboveThresholdEu", null, false ); [XmlSerializationTag("LevelTriggerType")] public Common.DAS.Concepts.DAS.Channel.LevelTriggerTypes LevelTriggerType { get => _levelTriggerType.Value; set => _levelTriggerType.Value = value; } public bool LevelTriggerTypeValid => _levelTriggerType.IsValueInitialized; private readonly Property _levelTriggerType = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.LevelTriggerType", Common.DAS.Concepts.DAS.Channel.LevelTriggerTypes.NONE, true); /// /// Get/set the serial number for this channel's data source. /// [XmlSerializationTag("SerialNumber")] public string SerialNumber { get => _SerialNumber.Value; set => _SerialNumber.Value = value; } private readonly Property _SerialNumber = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.SerialNumber", null, false ); /// /// Get/set the shunt enable indicator for this channel. /// [XmlSerializationTag("ShuntEnabled")] public bool ShuntEnabled { get => _ShuntEnabled.Value; set => _ShuntEnabled.Value = value; } private readonly Property _ShuntEnabled = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.ShuntEnabled", false, false ); /// /// Get/set the shunt enable indicator for this channel. /// [XmlSerializationTag("VoltageInsertionCheckEnabled")] public bool VoltageInsertionCheckEnabled { get => _VoltageInsertionCheckEnabled.Value; set => _VoltageInsertionCheckEnabled.Value = value; } private readonly Property _VoltageInsertionCheckEnabled = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.VoltageInsertionCheckEnabled", false, false ); /// /// Get/set the shunt enable indicator for this channel. /// [XmlSerializationTag("CalSignalEnabled")] public bool CalSignalEnabled { get => _CalSignalEnabled.Value; set => _CalSignalEnabled.Value = value; } private readonly Property _CalSignalEnabled = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.CalSignalEnabled", false, false ); /// /// Get/set the software filter for this channel's data source. /// [XmlSerializationTag("SoftwareFilter")] public string SoftwareFilter { get => _SoftwareFilter.Value; set => _SoftwareFilter.Value = value; } private readonly Property _SoftwareFilter = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.SoftwareFilter", null, false ); /// /// Get/set the remove offset option for this channel. /// [XmlSerializationTag("RemoveOffset")] public bool RemoveOffset { get => _RemoveOffset.Value; set => _RemoveOffset.Value = value; } private readonly Property _RemoveOffset = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.RemoveOffset", false, false ); /// /// Get/set the zero method option for this channel. /// [XmlSerializationTag("ZeroMethod")] public ZeroMethodType ZeroMethod { get { try { if (null != LinearizationFormula && LinearizationFormula.IsValid()) { switch (LinearizationFormula.NonLinearStyle) { case NonLinearStyles.IRTraccDiagnosticsZero: _ZeroMethod.Value = ZeroMethodType.UsePreEventDiagnosticsZero; break; case NonLinearStyles.IRTraccAverageOverTime: _ZeroMethod.Value = ZeroMethodType.AverageOverTime; break; } } } catch (System.Exception) { } return _ZeroMethod.Value; } set => _ZeroMethod.Value = value; } private readonly Property _ZeroMethod = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.ZeroMethod", SensorConstants.DefaultZeroMethodType, // FB12764: Default in SensorConstants false ); /// /// Get/set zero average window definition. /// [XmlSerializationTag("ZeroAverageWindow")] public IntervalSec ZeroAverageWindow { get => _ZeroAverageWindow.Value; set => _ZeroAverageWindow.Value = value; } private readonly Property _ZeroAverageWindow = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.ZeroAverageWindow", null, false ); /// /// Sets DataZeroLevelADC to PreTestADC, logs a message (if not null or empty) and returns value as short /// originally added for MS 30446 - Unexpected-DataZeroLevelADC-15292-when-scheduled-recording-with-TSR-AIR-at-100sps /// /// /// private short SetDataZeroToPretestADC(string errorMessage) { if (!string.IsNullOrWhiteSpace(errorMessage)) { APILogger.Log(errorMessage); } _DataZeroLevelAdc = PreTestZeroLevelAdc; return (short)_DataZeroLevelAdc; } private const int InvalidWindowAverage = short.MinValue; /// /// Get data zero level counts. /// public override short DataZeroLevelAdc { get { if (null == _DataZeroLevelAdc) { switch (ZeroMethod) { case ZeroMethodType.AverageOverTime: if (WindowAverageADC != InvalidWindowAverage) { _DataZeroLevelAdc = WindowAverageADC; } else { try { double preTriggerSeconds = 0; try { if (null != ParentModule.TriggerSampleNumbers && ParentModule.TriggerSampleNumbers.Count > 0) { preTriggerSeconds = ParentModule.TriggerSampleNumbers[0] - (double)ParentModule.StartRecordSampleNumber; preTriggerSeconds /= ParentModule.SampleRateHz; } } catch { } //figure out the average window, get the average in raw adc. //per TJK and MB these values are okay in unfiltered ADC as the averaging mechanism is itself an filter mechanism //and most serious users will have their own zeroing tools var preTriggerTime = 0D; if (null != ParentModule.TriggerSampleNumbers) { preTriggerTime = (ParentModule.TriggerSampleNumbers[0] - (double)ParentModule.StartRecordSampleNumber) / ParentModule.SampleRateHz; } if (preTriggerTime < 0) { preTriggerTime = 0; } try { var numSamples = (ulong)((ZeroAverageWindow.End - ZeroAverageWindow.Begin) * ParentModule.SampleRateHz) + 1; var windowSamples = new double[numSamples]; if (preTriggerTime == 0 && ZeroAverageWindow.Begin < 0) { //starting index will be invalid, don't use Average over time return SetDataZeroToPretestADC($"{FileName} Average over time window is not available, using PreTestZeroLevelADC"); } var startingIndex = ((ulong)((preTriggerTime + ZeroAverageWindow.Begin) * ParentModule.SampleRateHz)); if (startingIndex >= long.MaxValue) { //starting index is invalid here too, don't use Average over time return SetDataZeroToPretestADC($"{FileName} Average over time window is not available, using PreTestZeroLevelADC"); ; } var pc = PersistentChannelInfo; //18966 Data incorrect when performing multiple ROI downloads with dual-sensitivity sensor //if PersistentChannelInfo is not memorymapped before //this process, then unmap it when we are done, otherwise //we may hold onto a file handle var deleteWhenDone = !pc.IsMemoryMapped; var insertPoint = 0; for (var i = startingIndex; i < startingIndex + numSamples; i++) { //don't try to access any indicies that are out of range if (i >= 0 && (long)i < pc.Length) { windowSamples[insertPoint++] = Convert.ToDouble(pc[i]); } } _DataZeroLevelAdc = Convert.ToInt16(windowSamples.Average()); if (deleteWhenDone) { pc.Dispose(); } } catch (System.Exception ex) { return SetDataZeroToPretestADC($"DataZeroLevelADC exception: {ex.Message} {ex.StackTrace}"); } } catch (System.Exception ex) { return SetDataZeroToPretestADC($"DataZeroLevelADC exception: {ex.Message} {ex.StackTrace}"); } } break; case ZeroMethodType.UsePreEventDiagnosticsZero: return SetDataZeroToPretestADC(null); case ZeroMethodType.None: if (null != LinearizationFormula && LinearizationFormula.IsValid()) { _DataZeroLevelAdc = 0; } else { _DataZeroLevelAdc = ZeroMvInADC; } break; default: throw new NotSupportedException("Test::Module::AnalogInputChannel DataZeroLevelAdc zeromethod not supported, " + ZeroMethod.ToString()); } } return (short)_DataZeroLevelAdc; } } private short? _DataZeroLevelAdc = null; /// /// Get/set the average value of all ADC so far added to this channel's data set. /// public AverageShortValueOverTime AverageAdcOverTime { get => _AverageAdcOverTime.Value; set => _AverageAdcOverTime.Value = value; } private readonly Property _AverageAdcOverTime = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.AverageAdcOverTime", null, false ); /// /// Get/set the initial EU value. /// [XmlSerializationTag("InitialEu")] public double InitialEu { get => _InitialEu.Value; set => _InitialEu.Value = value; } private readonly Property _InitialEu = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.InitialEu", 0.0, false ); [XmlSerializationTag("InitialOffset")] public string InitialOffset { get => _initialOffset.Value; set => _initialOffset.Value = value; } private readonly Property _initialOffset = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.InitialOffset", "", true); private const string BeginTagModifier = "Begin"; private const string EndTagModifier = "End"; /// /// Get/set the inversion status of this channel. /// [XmlSerializationTag("IsInverted")] public bool IsInverted { get => _IsInverted.Value; set => _IsInverted.Value = value; } private readonly Property _IsInverted = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.IsInverted", false, false ); /// /// Get/set the Linearization Formula of this channel. /// [XmlSerializationTag("LinearizationFormula")] public DTS.Common.Classes.Sensors.LinearizationFormula LinearizationFormula { get { if (!_LinearizationFormula.IsInitialized) { return new DTS.Common.Classes.Sensors.LinearizationFormula(); } return _LinearizationFormula.Value; } set => _LinearizationFormula.Value = value; } private readonly Property _LinearizationFormula = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.LinearizationFormula", null, false ); [XmlSerializationTag("DigitalMultiplier")] public DigitalInputScaleMultiplier DigitalMultiplier { get { if (!_DigitalMultiplier.IsInitialized || null == _DigitalMultiplier.Value) { _DigitalMultiplier.Value = new DigitalInputScaleMultiplier(); } return _DigitalMultiplier.Value; } set => _DigitalMultiplier.Value = value; } private readonly Property _DigitalMultiplier = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.DigitalMultiplier", null, false); [XmlSerializationTag("DigitalMode")] public DigitalInputModes DigitalMode { get { if (!_digitalMode.IsInitialized) { return DigitalInputModes.CCNC; } return _digitalMode.Value; } set => _digitalMode.Value = value; } private readonly Property _digitalMode = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.DigitalMode", DigitalInputModes.CCNC, true ); /// /// The original sensor capacity from the sensor database. /// [XmlSerializationTag("SensorCapacity")] public double SensorCapacity { get => _sensorCapacity.Value; set => _sensorCapacity.Value = value; } private readonly Property _sensorCapacity = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.SensorCapacity", 0.0, false ); /// /// The original sensor polarity from the sensor database. /// [XmlSerializationTag("SensorPolarity")] public string SensorPolarity { get => _sensorPolarity.Value; set => _sensorPolarity.Value = value; } private readonly Property _sensorPolarity = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.SensorPolarity", "", false ); /// /// The name of the .chn file in the Binary folder that corresponds to this channel. /// [XmlSerializationTag("FileName")] public string FileName { get => _fileName.Value; set => _fileName.Value = value; } private readonly Property _fileName = new Property( typeof(AnalogInputChannel).Namespace + ".Test.Module.AnalogInputChannel.FileName", "", false ); /// /// Write XML serialization for this object to the specified writer. /// /// /// /// The to which this object's XML serialization /// will be written. /// /// public override void WriteXml(XmlWriter writer) { var attributeExtractor = new AttributeExtractor(); writer.WriteStartElement(attributeExtractor.ExtractAttachedAttributeFromObject(this).Value); writeXmlAttributes(writer); writer.WriteEndElement(); } protected void writeXmlAttributes(XmlWriter writer) { var line = 0; try { var cult = System.Globalization.CultureInfo.InvariantCulture; var attributeExtractor = new AttributeExtractor(); line = 2; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ChannelType").Value, ChannelType.ToString(cult)); line = 3; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Number").Value, Number.ToString(cult)); line = 4; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "DigitalMultiplier").Value, DigitalMultiplier.ToSerializeDbString()); } catch (System.Exception) { } line = 5; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "DigitalMode").Value, DigitalMode.ToString()); line = 6; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Start").Value, Start.ToString(cult)); line = 7; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Bridge").Value, Bridge.ToString()); line = 8; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BridgeResistanceOhms").Value, BridgeResistanceOhms.ToString(cult)); writer.WriteAttributeString( attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ZeroPoint").Value, ZeroPoint.ToString(cult)); line = 9; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ChannelDescriptionString").Value, ChannelDescriptionString.ToString(cult)); } catch { } line = 10; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ChannelName2").Value, ChannelName2.ToString()); } catch { } try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ChannelId").Value, ChannelId); } catch (System.Exception) { } line = 11; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "HardwareChannelName").Value, HardwareChannelName.ToString()); } catch { } line = 12; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Description").Value, Description.ToString(cult)); line = 13; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "DesiredRange").Value, DesiredRange.ToString(cult)); line = 14; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Sensitivity").Value, Sensitivity.ToString(cult)); line = 15; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SoftwareFilter").Value, SoftwareFilter.ToString(cult)); line = 16; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ProportionalToExcitation").Value, ProportionalToExcitation.ToString(cult)); line = 17; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "IsInverted").Value, IsInverted.ToString(cult)); line = 18; if (null == LinearizationFormula) { LinearizationFormula = new DTS.Common.Classes.Sensors.LinearizationFormula(); } line = 19; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "LinearizationFormula").Value, LinearizationFormula.ToSerializeString()); line = 20; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "IsSubsampled").Value, IsSubsampled.ToString(cult)); line = 21; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "AbsoluteDisplayOrder").Value, AbsoluteDisplayOrder.ToString(cult)); line = 22; if (IsLastCalibrationDateValid) { line = 23; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "LastCalibrationDate").Value, LastCalibrationDate.ToString(cult)); } catch { } } if (IsCalDueDateValid) { line = 24; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "CalDueDate").Value, CalDueDate.ToString(cult)); } catch { } } if (null == SensorID) { SensorID = ""; } if (IsSensorIDValid) { line = 25; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SensorID").Value, SensorID.ToString()); } catch { } } if (IsOffsetToleranceLowMvValid) { line = 26; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "OffsetToleranceLowMv").Value, OffsetToleranceLowMv.ToString(cult)); } catch { } } if (IsOffsetToleranceHighMvValid) { line = 27; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "OffsetToleranceHighMv").Value, OffsetToleranceHighMv.ToString(cult)); } catch { } } if (IsDataFlagValid) { try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "DataFlag").Value, DataFlag.ToString(cult)); } catch { } } line = 28; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ExcitationVoltage").Value, ExcitationVoltage.ToString()); line = 29; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "EngineeringUnits").Value, EngineeringUnits.ToString(cult)); line = 30; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SerialNumber").Value, SerialNumber.ToString(cult)); line = 31; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "CalSignalEnabled").Value, CalSignalEnabled.ToString(cult)); line = 32; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ShuntEnabled").Value, ShuntEnabled.ToString(cult)); line = 33; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "VoltageInsertionCheckEnabled").Value, VoltageInsertionCheckEnabled.ToString(cult)); line = 34; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "RemoveOffset").Value, RemoveOffset.ToString(cult)); //writer.WriteAttributeString( attributeExtractor.ExtractAttachedAttributeFromProperty( this, "ZeroMethod" ).Value, this.ZeroMethod .ToString( ) ); line = 35; switch (ZeroMethod) { case ZeroMethodType.UsePreEventDiagnosticsZero: writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ZeroMethod").Value, "UsePreCalZero"); break; default: writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ZeroMethod").Value, ZeroMethod.ToString()); break; } line = 36; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ZeroAverageWindow").Value + BeginTagModifier, ZeroAverageWindow.Begin.ToString(cult)); line = 37; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ZeroAverageWindow").Value + EndTagModifier, ZeroAverageWindow.End.ToString(cult)); line = 38; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "InitialEu").Value, InitialEu.ToString(cult)); line = 39; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "InitialOffset").Value, InitialOffset); line = 40; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UnsubsampledSampleRateHz").Value, UnsubsampledSampleRateHz.ToString(cult)); line = 41; if (!string.IsNullOrEmpty(UserValue1)) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UserValue1").Value, UserValue1); } line = 42; if (!string.IsNullOrEmpty(UserValue2)) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UserValue2").Value, UserValue2); } line = 43; if (!string.IsNullOrEmpty(UserValue3)) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UserValue3").Value, UserValue3); } if (!string.IsNullOrEmpty(SetupEID)) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SetupEID").Value, SetupEID); } if (!string.IsNullOrEmpty(DataCollectionEID)) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "DataCollectionEID").Value, DataCollectionEID); } line = 44; // Potentially valid "uninitialized" values need special handling. if (_MeasuredShuntDeflectionMv.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "MeasuredShuntDeflectionMv").Value, MeasuredShuntDeflectionMv.ToString(cult)); line = 45; if (_MeasuredGain.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "MeasuredGain").Value, MeasuredGain.ToString(cult)); line = 46; if (_ExpectedGain.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ExpectedGain").Value, ExpectedGain.ToString(cult)); line = 47; if (_TargetShuntDeflectionMv.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetShuntDeflectionMv").Value, TargetShuntDeflectionMv.ToString(cult)); line = 48; if (_MeasuredCalSignalMv.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "MeasuredCalSignalMv").Value, MeasuredCalSignalMv.ToString(cult)); line = 49; if (_TargetCalSignalMv.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetCalSignalMv").Value, TargetCalSignalMv.ToString(cult)); line = 50; if (_MeasuredExcitationVoltage.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "MeasuredExcitationVoltage").Value, MeasuredExcitationVoltage.ToString(cult)); line = 51; if (_FactoryExcitationVoltage.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "FactoryExcitationVoltage").Value, FactoryExcitationVoltage.ToString(cult)); line = 52; if (_TimeOfFirstSampleSec.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TimeOfFirstSampleSec").Value, TimeOfFirstSampleSec.ToString(cult)); line = 53; // Potentially valid "uninitialized" and/or nullable values need special handling. if (_TriggerAboveThresholdEu.IsInitialized && null != TriggerAboveThresholdEu) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerAboveThresholdEu").Value, ((double)TriggerAboveThresholdEu).ToString(cult)); line = 54; if (_TriggerBelowThresholdEu.IsInitialized && null != TriggerBelowThresholdEu) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerBelowThresholdEu").Value, ((double)TriggerBelowThresholdEu).ToString(cult)); line = 55; if (_Multiplier.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Multiplier").Value, Multiplier.ToString(cult)); line = 56; if (_UserOffsetEU.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UserOffsetEU").Value, UserOffsetEU.ToString(cult)); line = 57; if (_UnitConversion.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UnitConversion").Value, UnitConversion.ToString(cult)); line = 58; if (_AtCapacity.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "AtCapacity").Value, AtCapacity.ToString(cult)); line = 59; if (_CapacityOutputIsBasedOn.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "CapacityOutputIsBasedOn").Value, CapacityOutputIsBasedOn.ToString(cult)); line = 60; if (_SensitivityUnits.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SensitivityUnits").Value, SensitivityUnits.ToString()); line = 61; if (_isSquibChannel.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "IsSquibChannel").Value, IsSquibChannel.ToString(cult)); line = 62; if (_sensorCapacity.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SensorCapacity").Value, SensorCapacity.ToString(cult)); line = 63; if (_sensorCapacity.IsInitialized) writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "SensorPolarity").Value, SensorPolarity); line = 64; if (ExpressDataInlineOnXmlSerialization) Data.WriteXml(writer); line = 65; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ChannelGroupName").Value, ChannelGroupName); } catch (System.Exception) { } line = 66; if (_Manufacturer.IsInitialized) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Manufacturer").Value, Manufacturer.ToString(cult)); } line = 67; if (_Model.IsInitialized) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Model").Value, Model.ToString(cult)); } line = 68; try { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "OriginalChannelName").Value, OriginalChannelName?.ToString() ?? "UNKNOWN"); } catch { } line = 69; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "IsSupersampled").Value, IsSupersampled.ToString(cult)); line = 70; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UnsupersampledSampleRateHz").Value, UnsupersampledSampleRateHz.ToString(cult)); line = 71; if (_UserChannelName.IsInitialized) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UserChannelName").Value, UserChannelName.ToString()); } if (_UserCode.IsInitialized) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UserCode").Value, UserCode.ToString()); } if (_IsoCode.IsInitialized) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "IsoCode").Value, IsoCode.ToString()); } if (_IsoChannelName.IsInitialized) { writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "IsoChannelName").Value, IsoChannelName.ToString()); } //Since ExtractAttachedAttributeFromProperty fails when passing this.Data, put the value in this. UseEUScaler = Data.UseEUScaleFactors; writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UseEUScaler").Value, UseEUScaler.ToString(cult)); writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ScaleFactorEU").Value, Data.ScaleFactorEU.ToString(cult)); } catch (System.Exception ex) { throw new Exception("encountered problem converting " + GetType().FullName + " object to XML, Line: " + line.ToString(), ex); } } /// /// Read XML serialization for this object from the specified reader. /// /// /// /// The from which this object's XML serialization /// will be read. /// /// //Note: This does not read in the parent (Channel) xml public override void ReadXml(XmlReader reader) { try { var cult = new System.Globalization.CultureInfo(""); var attributeExtractor = new AttributeExtractor(); var xmlAttributeDecoder = new PropertyAttributeDecoder(this); if (null != reader.GetAttribute("AbsoluteDisplayOrder")) { try { AbsoluteDisplayOrder = xmlAttributeDecoder.ExtractIntProperty("AbsoluteDisplayOrder", reader); } catch (System.Exception) { } } if (null != reader.GetAttribute("Multiplier")) { try { Data.Multiplier = xmlAttributeDecoder.ExtractDoubleProperty("Multiplier", reader); Multiplier = xmlAttributeDecoder.ExtractDoubleProperty("Multiplier", reader); } catch (System.Exception ex) { var temp2 = ex.Message; } } if (null != reader.GetAttribute("UnitConversion")) { try { Data.UnitConversion = xmlAttributeDecoder.ExtractDoubleProperty("UnitConversion", reader); UnitConversion = xmlAttributeDecoder.ExtractDoubleProperty("UnitConversion", reader); } catch (System.Exception ex) { var temp2 = ex.Message; } } if (null != reader.GetAttribute("UserOffsetEU")) { try { Data.UserOffsetEU = xmlAttributeDecoder.ExtractDoubleProperty("UserOffsetEU", reader); UserOffsetEU = xmlAttributeDecoder.ExtractDoubleProperty("UserOffsetEU", reader); } catch (System.Exception ex) { var temp2 = ex.Message; } } if (null != reader.GetAttribute("AtCapacity")) { try { AtCapacity = xmlAttributeDecoder.ExtractBoolProperty("AtCapacity", reader, false); } catch (System.Exception ex) { var temp2 = ex.Message; } } if (null != reader.GetAttribute("CapacityOutputIsBasedOn")) { try { CapacityOutputIsBasedOn = xmlAttributeDecoder.ExtractDoubleProperty("CapacityOutputIsBasedOn", reader); } catch (System.Exception ex) { var temp2 = ex.Message; } } if (null != reader.GetAttribute("SensitivityUnits")) { try { SensitivityUnits = (SensorConstants.SensUnits)xmlAttributeDecoder.ExtractEnumProperty("SensitivityUnits", typeof(Common.DAS.Concepts.Test.Module.Channel.Sensor.SensUnits), reader); } catch (System.Exception ex) { var temp2 = ex.Message; } } Number = xmlAttributeDecoder.ExtractIntProperty("Number", reader); BridgeResistanceOhms = xmlAttributeDecoder.ExtractDoubleProperty("BridgeResistanceOhms", reader); try { if (null != reader.GetAttribute("ZeroPoint")) { ZeroPoint = xmlAttributeDecoder.ExtractDoubleProperty("ZeroPoint", reader); } } catch (System.Exception) { } ChannelDescriptionString = xmlAttributeDecoder.ExtractStringProperty("ChannelDescriptionString", reader); try { OriginalChannelName = xmlAttributeDecoder.ExtractStringProperty("OriginalChannelName", reader); } catch (System.Exception) { } try { ChannelName2 = xmlAttributeDecoder.ExtractStringProperty("ChannelName2", reader); } catch (System.Exception) { } try { HardwareChannelName = xmlAttributeDecoder.ExtractStringProperty("HardwareChannelName", reader); } catch (System.Exception) { } try { ChannelId = xmlAttributeDecoder.ExtractStringProperty("ChannelId", reader); } catch (System.Exception) { } try { ChannelGroupName = xmlAttributeDecoder.ExtractStringProperty("ChannelGroupName", reader); } catch (System.Exception) { } DesiredRange = xmlAttributeDecoder.ExtractDoubleProperty("DesiredRange", reader); Description = xmlAttributeDecoder.ExtractStringProperty("Description", reader); Manufacturer = xmlAttributeDecoder.ExtractStringProperty("Manufacturer", reader); Model = xmlAttributeDecoder.ExtractStringProperty("Model", reader); EngineeringUnits = xmlAttributeDecoder.ExtractStringProperty("EngineeringUnits", reader); try { InitialOffset = xmlAttributeDecoder.ExtractStringProperty("InitialOffset", reader); } catch (System.Exception) { } InitialEu = xmlAttributeDecoder.ExtractDoubleProperty("InitialEu", reader); ProportionalToExcitation = xmlAttributeDecoder.ExtractBoolProperty("ProportionalToExcitation", reader); RemoveOffset = xmlAttributeDecoder.ExtractBoolProperty("RemoveOffset", reader); Sensitivity = xmlAttributeDecoder.ExtractDoubleProperty("Sensitivity", reader); try { if (DateTime.TryParse(xmlAttributeDecoder.ExtractStringProperty("LastCalibrationDate", reader), cult, System.Globalization.DateTimeStyles.None, out DateTime dt)) { LastCalibrationDate = dt; } } catch { } try { if (DateTime.TryParse(xmlAttributeDecoder.ExtractStringProperty("CalDueDate", reader), cult, System.Globalization.DateTimeStyles.None, out DateTime dt)) { CalDueDate = dt; } } catch { } SerialNumber = xmlAttributeDecoder.ExtractStringProperty("SerialNumber", reader); try { CalSignalEnabled = xmlAttributeDecoder.ExtractBoolProperty("CalSignalEnabled", reader, false); } catch { CalSignalEnabled = false; } ShuntEnabled = xmlAttributeDecoder.ExtractBoolProperty("ShuntEnabled", reader); try { VoltageInsertionCheckEnabled = xmlAttributeDecoder.ExtractBoolProperty("VoltageInsertionCheckEnabled", reader, false); } catch { VoltageInsertionCheckEnabled = false; } SoftwareFilter = xmlAttributeDecoder.ExtractStringProperty("SoftwareFilter", reader); Bridge = (SensorConstants.BridgeType)xmlAttributeDecoder.ExtractEnumProperty("Bridge", typeof(SensorConstants.BridgeType), reader); ExcitationVoltage = (ExcitationVoltageOptions.ExcitationVoltageOption)xmlAttributeDecoder.ExtractEnumProperty("ExcitationVoltage", typeof(ExcitationVoltageOptions.ExcitationVoltageOption), reader); var sZeroMethod = xmlAttributeDecoder.ExtractStringProperty("ZeroMethod", reader); try { if (null != sZeroMethod && "UsePreCalZero" == sZeroMethod) { ZeroMethod = ZeroMethodType.UsePreEventDiagnosticsZero; } else { ZeroMethod = (ZeroMethodType)Enum.Parse(typeof(ZeroMethodType), sZeroMethod); } } catch { var originalZeroMethodType = (OriginalZeroMethodType)xmlAttributeDecoder.ExtractEnumProperty("ZeroMethod", typeof(OriginalZeroMethodType), reader); switch (originalZeroMethodType) { case OriginalZeroMethodType.AverageOverTime: ZeroMethod = ZeroMethodType.AverageOverTime; break; case OriginalZeroMethodType.UsePreCalZero: ZeroMethod = ZeroMethodType.UsePreEventDiagnosticsZero; break; case OriginalZeroMethodType.None: ZeroMethod = ZeroMethodType.None; break; default:// // If we've gotten here, we've changed the enum and forgotten to put in // a corresponding conversion. // ZeroMethod = ZeroMethodType.None; break; } } try { UnsubsampledSampleRateHz = float.Parse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UnsubsampledSampleRateHz").Value), cult); } catch (System.Exception) { UnsubsampledSampleRateHz = ParentModule.SampleRateHz; } try { UserValue1 = xmlAttributeDecoder.ExtractStringProperty("UserValue1", reader); } catch (System.Exception) { } try { UserValue2 = xmlAttributeDecoder.ExtractStringProperty("UserValue2", reader); } catch (System.Exception) { } try { UserValue3 = xmlAttributeDecoder.ExtractStringProperty("UserValue3", reader); } catch (System.Exception) { } var attribute = reader.GetAttribute("SetupEID"); if (null != attribute) { try { SetupEID = xmlAttributeDecoder.ExtractStringProperty("SetupEID", reader); } catch( System.Exception ex) { APILogger.Log(ex); } } attribute = reader.GetAttribute("DataCollectionEID"); if (null != attribute) { try { DataCollectionEID = xmlAttributeDecoder.ExtractStringProperty("DataCollectionEID", reader); } catch (System.Exception ex) { APILogger.Log(ex); } } double temp; //try { this.MeasuredShuntDeflectionMv = double.Parse( reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty ( this, "MeasuredShuntDeflectionMv" ).Value ), cult ); } //catch ( System.Exception ) { /*this.MeasuredShuntDeflectionMv = 0.0;*/ } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "MeasuredShuntDeflectionMv").Value), System.Globalization.NumberStyles.Any, cult, out temp)) { MeasuredShuntDeflectionMv = temp; } } catch (System.Exception) { } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "MeasuredGain").Value), System.Globalization.NumberStyles.Any, cult, out temp)) { MeasuredGain = temp; } } catch (System.Exception) { } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ExpectedGain").Value), System.Globalization.NumberStyles.Any, cult, out temp)) { ExpectedGain = temp; } } catch (System.Exception) { } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetShuntDeflectionMv").Value), System.Globalization.NumberStyles.Any, cult, out temp)) { TargetShuntDeflectionMv = temp; } } catch (System.Exception) { } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "MeasuredCalSignalMv").Value), System.Globalization.NumberStyles.Any, cult, out temp)) { MeasuredCalSignalMv = temp; } } catch (System.Exception) { } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TargetCalSignalMv").Value), System.Globalization.NumberStyles.Any, cult, out temp)) { TargetCalSignalMv = temp; } } catch (System.Exception) { } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerAboveThresholdEu").Value), System.Globalization.NumberStyles.Any, cult, out temp)) { TriggerAboveThresholdEu = temp; } } catch (System.Exception) { } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TriggerBelowThresholdEu").Value), System.Globalization.NumberStyles.Any, cult, out temp)) { TriggerBelowThresholdEu = temp; } } catch { } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "MeasuredExcitationVoltage").Value), System.Globalization.NumberStyles.Float, cult, out temp)) { MeasuredExcitationVoltage = temp; } } catch (System.Exception) { /* leave it uninitialized */ } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "FactoryExcitationVoltage").Value), System.Globalization.NumberStyles.Float, cult, out temp)) { FactoryExcitationVoltage = temp; } } catch (System.Exception) { /* leave it uninitialized */ } try { if (double.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "TimeOfFirstSampleSec").Value), System.Globalization.NumberStyles.Float, cult, out temp)) { TimeOfFirstSampleSec = temp; } } catch (System.Exception) { } try { IsInverted = xmlAttributeDecoder.ExtractBoolProperty("IsInverted", reader, false); } catch (System.Exception) { IsInverted = false; } try { IsSubsampled = xmlAttributeDecoder.ExtractBoolProperty("IsSubsampled", reader, false); } catch (System.Exception) { IsSubsampled = false; } try { LinearizationFormula = new DTS.Common.Classes.Sensors.LinearizationFormula(); LinearizationFormula.FromSerializeString(xmlAttributeDecoder.ExtractStringProperty("LinearizationFormula", reader)); } catch (System.Exception) { LinearizationFormula = null; } try { DigitalMultiplier = new DigitalInputScaleMultiplier(); DigitalMultiplier.FromDbSerializeString(xmlAttributeDecoder.ExtractStringProperty("DigitalMultiplier", reader)); } catch (System.Exception) { DigitalMultiplier = new DigitalInputScaleMultiplier(); } try { var mode = DigitalInputModes.CCNC; Enum.TryParse(xmlAttributeDecoder.ExtractStringProperty("DigitalMode", reader), out mode); DigitalMode = mode; } catch (System.Exception) { } try { if (DateTime.TryParse(reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "LastCalibrationDate").Value), cult, System.Globalization.DateTimeStyles.None, out DateTime calDate)) { LastCalibrationDate = calDate; } else { LastCalibrationDate = DateTime.MinValue; } } catch { LastCalibrationDate = DateTime.MinValue; } try { SensorID = xmlAttributeDecoder.ExtractStringProperty("SensorID", reader); } catch (System.Exception) { SensorID = ""; } try { OffsetToleranceLowMv = xmlAttributeDecoder.ExtractDoubleProperty("OffsetToleranceLowMv", reader); } catch (System.Exception) { OffsetToleranceLowMv = 0; } try { OffsetToleranceHighMv = xmlAttributeDecoder.ExtractDoubleProperty("OffsetToleranceHighMv", reader); } catch (System.Exception) { OffsetToleranceHighMv = 0; } try { DataFlag = xmlAttributeDecoder.ExtractIntProperty("DataFlag", reader); } catch (System.Exception) { DataFlag = new DataFlagAttributeCoder().DecodeAttributeValue(Common.Utilities.DataFlag.Normal); } try { // // Extract and parse start time value. // string startTimeString; try { startTimeString = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "Start").Value); } catch (System.Exception ex) { throw new Exception("encountered problem extracting start time value string", ex); } try { Start = DateTime.Parse(startTimeString, cult); } catch (System.Exception) { Start = DateTime.Now; // throw new Test.Module.AnalogInputChannel.Exception( "encountered problem parsing DateTime value " + ( null != startTimeString ? ( "\"" + startTimeString + "\"" ) : "<>" ), ex ); } } catch (System.Exception ex) { throw new Exception("encountered problem extracting start time property", ex); } try { // // Extract and parse zero average window begin value. // string zeroAverageWindowBeginString; try { zeroAverageWindowBeginString = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ZeroAverageWindow").Value + BeginTagModifier); } catch (System.Exception ex) { throw new Exception("encountered problem extracting ZeroAverageWindow begin value string", ex); } double zeroAverageWindowBeginValue; try { zeroAverageWindowBeginValue = double.Parse(zeroAverageWindowBeginString, cult); } catch (System.Exception ex) { throw new Exception("encountered problem parsing double value " + (null != zeroAverageWindowBeginString ? ("\"" + zeroAverageWindowBeginString + "\"") : "<"), ex); } // // Extract and parse zero average window end value. // string zeroAverageWindowEndString; try { zeroAverageWindowEndString = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "ZeroAverageWindow").Value + EndTagModifier); } catch (System.Exception ex) { throw new Exception("encountered problem extacting ZeroAverageWindow end value string", ex); } double zeroAverageWindowEndValue; try { zeroAverageWindowEndValue = double.Parse(zeroAverageWindowEndString, cult); } catch (System.Exception ex) { throw new Exception("encountered problem parsing double value " + (null != zeroAverageWindowEndString ? ("\"" + zeroAverageWindowEndString + "\"") : "<"), ex); } try { // // Synthesize new zero average window value. // ZeroAverageWindow = new IntervalSec(zeroAverageWindowBeginValue, zeroAverageWindowEndValue); } catch (System.Exception ex) { throw new Exception("encountered problem synthesizing zero average window from begin: " + zeroAverageWindowBeginValue.ToString() + ", end: " + zeroAverageWindowEndValue.ToString(), ex); } } catch (System.Exception ex) { throw new Exception("encountered problem extracting zero average window property", ex); } if (ExpressDataInlineOnXmlSerialization) { reader.Read(); short[] dummyValues = { 0 }; Data = new DataArray(dummyValues); Data.ReadXml(reader); } try { IsSquibChannel = xmlAttributeDecoder.ExtractBoolProperty("IsSquibChannel", reader, false); } catch (System.Exception) { IsSquibChannel = false; } try { if (xmlAttributeDecoder.ExtractDoubleProperty("SensorCapacity", reader, out double d)) { SensorCapacity = d; } else { SensorCapacity = 0D; } } catch (System.Exception) { SensorCapacity = 0; } try { SensorPolarity = xmlAttributeDecoder.ExtractStringProperty("SensorPolarity", reader); } catch (System.Exception) { SensorPolarity = ""; } var userCode = reader.GetAttribute("UserCode"); if (null != userCode) { UserCode = userCode; } var userChannelName = reader.GetAttribute("UserChannelName"); if (null != userChannelName) { UserChannelName = userChannelName; } var isoCode = reader.GetAttribute("IsoCode"); if (null != isoCode) { IsoCode = isoCode; } var isoChannelName = reader.GetAttribute("IsoChannelName"); if (null != isoChannelName) { IsoChannelName = isoChannelName; } try { IsSupersampled = xmlAttributeDecoder.ExtractBoolProperty("IsSupersampled", reader, false); } catch (System.Exception) { IsSupersampled = false; } try { if (!string.IsNullOrWhiteSpace(reader.GetAttribute("UseEUScaler"))) { Data.UseEUScaleFactors = xmlAttributeDecoder.ExtractBoolProperty("UseEUScaler", reader, false); } } catch (System.Exception) { Data.UseEUScaleFactors = false; } try { if (!string.IsNullOrWhiteSpace(reader.GetAttribute("ScaleFactorEU"))) { Data.ScaleFactorEU = xmlAttributeDecoder.ExtractDoubleProperty("ScaleFactorEU", reader); } } catch (System.Exception) { Data.ScaleFactorEU = 0; } try { var val = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "UnsupersampledSampleRateHz").Value); if (string.IsNullOrWhiteSpace(val)) { UnsupersampledSampleRateHz = 0F; } else { UnsupersampledSampleRateHz = float.Parse(val, cult); } } catch (System.Exception) { UnsupersampledSampleRateHz = 0F; } } catch (System.Exception ex) { throw new Exception("encountered problem converting XML to " + GetType().FullName + " object", ex); } } /// /// Test the specified object for equality with this object. /// /// /// /// The to be tested for equality. /// /// /// /// true if the specified object has memeberwise equality with /// this object; false otherwise. /// /// public override bool Equals(object obj) { try { var that = obj as AnalogInputChannel; return null != obj // Must-be-initialized properties. && ChannelId.Equals(that.ChannelId) && ChannelGroupName.Equals(that.ChannelGroupName) && Data.Equals(that.Data) && ExpressDataInlineOnXmlSerialization.Equals(that.ExpressDataInlineOnXmlSerialization) && Number.Equals(that.Number) && Bridge.Equals(that.Bridge) && BridgeResistanceOhms.Equals(that.BridgeResistanceOhms) && ZeroPoint.Equals(that.ZeroPoint) && Description.Equals(that.Description, StringComparison.OrdinalIgnoreCase) && DesiredRange.Equals(that.DesiredRange) && EngineeringUnits.Equals(that.EngineeringUnits, StringComparison.OrdinalIgnoreCase) && ExcitationVoltage.Equals(that.ExcitationVoltage) && InitialEu.Equals(that.InitialEu) && InitialOffset.Equals(that.InitialOffset) && ProportionalToExcitation.Equals(that.ProportionalToExcitation) && IsInverted.Equals(that.IsInverted) && IsSubsampled.Equals(that.IsSubsampled) //handle nullable && IsLastCalibrationDateValid && that.IsLastCalibrationDateValid ? LastCalibrationDate.Equals(that.LastCalibrationDate) : that.IsLastCalibrationDateValid ? false : true && IsCalDueDateValid && that.IsCalDueDateValid ? CalDueDate.Equals(that.CalDueDate) : that.IsCalDueDateValid ? false : true && IsSensorIDValid && that.IsSensorIDValid ? SensorID.Equals(that.SensorID) : that.IsSensorIDValid ? false : true && IsOffsetToleranceLowMvValid && that.IsOffsetToleranceLowMvValid ? OffsetToleranceLowMv.Equals(that.OffsetToleranceLowMv) : that.IsOffsetToleranceLowMvValid ? false : true && IsOffsetToleranceHighMvValid && that.IsOffsetToleranceHighMvValid ? OffsetToleranceHighMv.Equals(that.OffsetToleranceHighMv) : that.IsOffsetToleranceHighMvValid ? false : true && ( (null == LinearizationFormula && null == that.LinearizationFormula) || (null != LinearizationFormula && LinearizationFormula.Equals(that.LinearizationFormula)) ) && IsoCode.Equals(that.IsoCode, StringComparison.OrdinalIgnoreCase) && RemoveOffset.Equals(that.RemoveOffset) && Sensitivity.Equals(that.Sensitivity) && SerialNumber.Equals(that.SerialNumber, StringComparison.OrdinalIgnoreCase) && ShuntEnabled.Equals(that.ShuntEnabled) && VoltageInsertionCheckEnabled.Equals(that.VoltageInsertionCheckEnabled) && CalSignalEnabled.Equals(that.CalSignalEnabled) && SoftwareFilter.Equals(that.SoftwareFilter) && UnsubsampledSampleRateHz.Equals(that.UnsubsampledSampleRateHz) && ZeroAverageWindow.Equals(that.ZeroAverageWindow) && ZeroMethod.Equals(that.ZeroMethod) && Start.ToString().Equals(that.Start.ToString()) && AbsoluteDisplayOrder.Equals(that.AbsoluteDisplayOrder) // Potentially valid-as-uninitialized and/or nullable properties. && _MeasuredShuntDeflectionMv.IsInitialized ? MeasuredShuntDeflectionMv.Equals(that.MeasuredShuntDeflectionMv) : _MeasuredShuntDeflectionMv.IsInitialized == that._MeasuredShuntDeflectionMv.IsInitialized && _TargetShuntDeflectionMv.IsInitialized ? TargetShuntDeflectionMv.Equals(that.TargetShuntDeflectionMv) : _TargetShuntDeflectionMv.IsInitialized == that._TargetShuntDeflectionMv.IsInitialized && _TriggerAboveThresholdEu.IsInitialized ? TriggerAboveThresholdEu.Equals(that.TriggerAboveThresholdEu) : _TriggerAboveThresholdEu.IsInitialized == that._TriggerAboveThresholdEu.IsInitialized && _TriggerBelowThresholdEu.IsInitialized ? TriggerBelowThresholdEu.Equals(that.TriggerBelowThresholdEu) : _TriggerBelowThresholdEu.IsInitialized == that._TriggerBelowThresholdEu.IsInitialized && _MeasuredGain.IsInitialized ? MeasuredGain.Equals(that.MeasuredGain) : _MeasuredGain.IsInitialized == that._MeasuredGain.IsInitialized && UserValue1 == that.UserValue1 && UserValue2 == that.UserValue2 && UserValue3 == that.UserValue3 && IsSupersampled.Equals(that.IsSupersampled) && UnsupersampledSampleRateHz.Equals(that.UnsupersampledSampleRateHz) && DigitalMultiplier.ToSerializeDbString() == that.DigitalMultiplier.ToSerializeDbString() && DigitalMode == that.DigitalMode && DataFlag.Equals(that.DataFlag) && _ExpectedGain.IsInitialized ? ExpectedGain.Equals(that.ExpectedGain) : _ExpectedGain.IsInitialized == that._ExpectedGain.IsInitialized && UnitConversion.Equals(that.UnitConversion) && AtCapacity.Equals(that.AtCapacity) && CapacityOutputIsBasedOn.Equals(that.CapacityOutputIsBasedOn) && SensitivityUnits.Equals(that.SensitivityUnits) && SetupEID.Equals(that.SetupEID) && DataCollectionEID.Equals(that.DataCollectionEID); } catch (System.Exception ex) { throw new Exception("encountered problem equality-testing the object " + (null != obj ? "\"" + obj.ToString() + "\"" : "<>"), ex); } } /// /// Return the hash code for this object. /// /// /// /// The hash code for this object. /// /// public override int GetHashCode() { return base.GetHashCode(); } } } } }