/* * DTS.Slice.Control.Event.Module.AnalogInputChannel.cs * * Copyright © 2009 * Diversified Technical Systems, Inc. * All Rights Reserved */ using System; using System.Collections.Generic; using System.Linq; using DTS.Common.DAS.Concepts; using DTS.DASLib.Service; using DTS.Common.Utilities; using DTS.Common.Utilities.DotNetProgrammingConstructs; using DTS.Common.Utilities.Logging; namespace DTS.Slice.Control { // *** see DTS.Slice.Control.Event.cs *** public partial class Event { // *** see DTS.Slice.Control.Event.Module.cs *** public partial class Module { public partial class SquibEventChannel : Channel, Common.DAS.Concepts.DAS.Channel.IEngineeringUnitAware, Common.DAS.Concepts.DAS.Channel.IIsoCodeAware { public OutputSquibChannel.SquibMeasurementType MeasurementType { get; set; } /// /// Initialize an instance of the DTS.Slice.Control.Event.Module.SquibEventChannel class. /// /// /// /// The that contains this channel. /// /// /// /// The unique "absolute" number of the channel with respect to all other channels /// on all other DASes in the system. /// /// protected SquibEventChannel(Module parentModule, int absoluteNumber) : base(parentModule, absoluteNumber) { // // Intended only for constructing implicit conversion instances, hence the // restrictive access modifier. } // /// /// Initialize an instance of the DTS.Slice.Control.Event.Module.SquibEventChannel class. /// /// /// /// The with which to initialize this object. /// /// /// /// The that contains this channel. /// /// /// /// The unique "absolute" number of the channel with respect to all other channels /// on all other DASes in the system. /// /// public SquibEventChannel(DASChannel channel, Module parentModule, int absoluteNumber) : base(channel, parentModule, absoluteNumber) { try { // // Initialize this object's analog input-specific values with whatever we can // squeeze out of the specified channel object. // channel. // MvPerEu = 1.0; ScaleFactorMv = 1.0; SetPropertyValuesFrom(channel); } catch (System.Exception ex) { throw new Exception("encountered problem constructing " + GetType().FullName, ex); } } /// /// Get/set this object's engineering unit description . /// public string EngineeringUnits { get { switch (MeasurementType) { case OutputSquibChannel.SquibMeasurementType.CURRENT: return "A"; case OutputSquibChannel.SquibMeasurementType.INIT_SIGNAL: return "V"; case OutputSquibChannel.SquibMeasurementType.VOLTAGE: return "V"; case OutputSquibChannel.SquibMeasurementType.NONE: return ""; default: throw new NotSupportedException("SquibEventChannel::EngineeringUnits Unknown MeasurementType " + MeasurementType.ToString()); } } set { ;} } /// /// Get/set this object's IsoCode . /// public string IsoCode { get; set; } /// /// Convert this object to a DTS.Serialization.Test.Module.Channel. /// /// /// /// A equivalent for this object. /// /// public override Serialization.Test.Module.Channel ToDtsSerializationTestModuleChannel( Serialization.Test.Module parentModule) { try { var that = new Serialization.Test.Module.AnalogInputChannel(parentModule); if (!IsConfigured) throw new Exception("cannot serialize unconfigured analog input channel"); that.ChannelId = ChannelId; //that.AverageAdcOverTime = 0; //that.AverageAdcOverTime = this.AverageAdcOverTime; that.Bridge = Test.Module.Channel.Sensor.BridgeType.SQUIB; that.BridgeResistanceOhms = 0; that.ZeroPoint = 0; that.UserValue1 = UserValue1; that.UserValue2 = UserValue2; that.UserValue3 = UserValue3; //that.Bridge = this.Bridge; //that.BridgeResistanceOhms = this.BridgeResistanceOhms; that.ChannelDescriptionString = ChannelDescriptionString; that.ChannelName2 = ChannelName2; that.Description = ChannelDescriptionString; that.Manufacturer = Manufacturer; that.Model = Model; that.HardwareChannelName = HardwareChannelName; that.ChannelId = ChannelId; that.ChannelGroupName = ChannelGroupName; that.DesiredRange = 1; that.EngineeringUnits = EngineeringUnits; that.ExcitationVoltage = Test.Module.Channel.Sensor.ExcitationVoltageOption.Volt5; that.InitialEu = 0; that.IsInverted = false; that.IsSubsampled = false; if (IsLastCalibrationDateValid) { that.LastCalibrationDate = LastCalibrationDate; } if (IsSensorIDValid) { that.SensorID = SensorID; } if (IsOffsetToleranceLowMvValid) { that.OffsetToleranceLowMv = OffsetToleranceLowMv; } if (IsOffsetToleranceHighMvValid) { that.OffsetToleranceHighMv = OffsetToleranceHighMv; } that.IsoCode = IsoCode; that.NoiseAsPercentageOfFullScale = NoiseAsPercentageOfFullScale; that.Number = Number; that.AbsoluteDisplayOrder = AbsoluteDisplayOrder; that.PreTestZeroLevelAdc = PreTestZeroLevelAdc; that.ZeroMvInADC = ZeroMvInADC; that.WindowAverageADC = WindowAverageADC; //that.PreTestZeroLevelmV = this.PreTestZeroLevelMv; that.RemovedADC = RemovedADC; that.ProportionalToExcitation = false; that.RemoveOffset = false; that.Sensitivity = 1D; that.SerialNumber = ""; that.ShuntEnabled = false; that.VoltageInsertionCheckEnabled = false; that.CalSignalEnabled = false; that.Start = Start; that.PreTestZeroLevelAdc = PreTestZeroLevelAdc; that.ZeroMvInADC = ZeroMvInADC; that.WindowAverageADC = WindowAverageADC; //I'm not entirely sure why this is being set twice ... but why break with tradition! //that.PreTestZeroLevelmV = this.PreTestZeroLevelMv; that.RemovedADC = RemovedADC; that.AbsoluteDisplayOrder = AbsoluteDisplayOrder; that.ZeroAverageWindow = new Serialization.Test.IntervalSec(-1, 1); that.ZeroMethod = Test.Module.Channel.Sensor.ZeroMethodType.UsePreEventDiagnosticsZero; that.RemoveOffset = true; that.UnitConversion = 1.0; that.AtCapacity = false; that.CapacityOutputIsBasedOn = 1.000; that.SensitivityUnits = Test.Module.Channel.Sensor.SensUnits.NONE; try { if (TimeOfFirstSampleSecValid) { that.TimeOfFirstSampleSec = TimeOfFirstSampleSec; } } catch { }; that.SoftwareFilter = CurrentFilter.ToBaseString(); that.Data = new Serialization.Test.Module.Channel.DataArray(); // this.UnfilteredData.ToArray( ) ); that.Data.MvPerEu = GetMvPerEu(); that.Data.ScaleFactorMv = GetScaleFactorMv(); that.Data.Multiplier = Multiplier; that.Data.UnitConversion = UnitConversion; that.AtCapacity = AtCapacity; that.CapacityOutputIsBasedOn = CapacityOutputIsBasedOn; that.SensitivityUnits = SensitivityUnits; that.Data.UserOffsetEU = UserOffsetEU; if (UnfilteredData is Serialization.SliceRaw.File.PersistentChannel) that.PersistentChannelInfo = UnfilteredData as Serialization.SliceRaw.File.PersistentChannel; return that; } catch (System.Exception ex) { throw new Exception("encountered problem converting " + GetType().FullName + " to " + typeof(Serialization.Test.Module.AnalogInputChannel), ex); } } /// /// Initialize this object from the specified DTS.Serialization.Test.Module.Channel. /// /// /// /// A from which to initialize this object. /// /// public override void FromDtsSerializationTestModuleChannel( Serialization.Test.Module.Channel that) { throw new NotImplementedException("SquibEventChannel::FromDtsSerializationTestModuleChannel"); } //DataPROWin7.Properties.Settings.Default.UseISOCodesInReview private bool UseISOCodesInReview = false; /* /// /// Method to allow derived classes to initialize their own reviewable attributes. /// /// /// /// The or s to be initialized. /// /// /// /// Initialize this object's list of reviewable attributes. /// protected override void InitializeReviewableAttributes(List reviewableAttributes) { try { try { reviewableAttributes.Add(new ReviewableDescriptionAttribute(this)); } catch { } if (true == UseISOCodesInReview) { try { reviewableAttributes.Add(new ReviewableIsoCodeAttribute(this)); } catch { } } try { reviewableAttributes.Add(new ReviewableUnitsAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableMinMaxEuAttribute(this)); } catch { } } catch (System.Exception ex) { throw new Event.Module.AnalogInputChannel.Exception("encountered problem initializing reviewiable attribute list", ex); } } /// /// A reviewable min/max EU attribute attached to a specific channel. /// public class ReviewableMinMaxEuAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute { /// /// Initialize an instance of this class. /// /// /// /// The to which this attribute is attached. /// /// public ReviewableMinMaxEuAttribute(Event.Module.Channel channel) : base("Max/Min (EU)", delegate { return channel.DataMaxFilteredEu.ToString("F1") + "/" + channel.DataMinFilteredEu.ToString("F1"); }) { } } /// /// A reviewable engineering units attribute attached to a specific channel. /// public class ReviewableUnitsAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute { /// /// Initialize an instance of this class. /// /// /// /// The to which this attribute is attached. /// /// public ReviewableUnitsAttribute(Event.Module.Channel channel) : base("Units", delegate { return (channel as DTS.Common.DAS.Concepts.DAS.Channel.IEngineeringUnitAware).EngineeringUnits.ToString(); }) { } } /// /// A reviewable serial number attribute attached to a specific channel. /// public class ReviewableIsoCodeAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute { /// /// Initialize an instance of this class. /// /// /// /// The to which this attribute is attached. /// /// public ReviewableIsoCodeAttribute(Event.Module.Channel channel) : base("ISO Code", delegate { return (channel as AnalogInputChannel).IsoCode.ToString(); }) { } } /// /// A reviewable CFC attribute attached to a specific channel. /// public class ReviewableDescriptionAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute { /// /// Initialize an instance of this class. /// /// /// /// The to which this attribute is attached. /// /// public ReviewableDescriptionAttribute(Event.Module.Channel channel) : base("Description", delegate { return channel.ChannelDescriptionString; }) { } } */ public override List GetUnfilteredDataEu() { throw new NotImplementedException("SquibEventChannel::GetUnfilteredDataEu"); } public override List GetUnfilteredDataMV() { throw new NotImplementedException("SquibEventChannel::GetUnfilteredDataMV"); } /// /// Get value indicating whether or not the specified channel is configured. /// public override bool IsConfigured { get; set; } /// /// Get the actual available maximum EU range based on scaling factor and bit resolution. /// public override double ActualMaxRangeEu => throw new NotImplementedException("SquibEventChannel::ActualMaxRangeEu"); /// /// Get the actual available minimum EU range based on scaling factor and bit resolution. /// public override double ActualMinRangeEu => throw new NotImplementedException("SquibEventChannel::ActualMinRangeEu"); public override double DesiredRangeEU => throw new NotImplementedException("SquibEventChannel::DesiredRangeEu"); public override double SensorCapacityEU => throw new NotImplementedException("SquibEventChannel::SensorCapacityEU"); /// /// Get the data min in EU. /// public override double DataMinEu => throw new NotImplementedException("SquibEventChannel::DataMinEu"); /// /// Get the data max in EU. /// public override double DataMaxEu => throw new NotImplementedException("SquibEventChannel::DataMaxEu"); /// /// Get the data range in EU. /// public override double DataRangeEu => throw new NotImplementedException("SquibEventChannel::DataRangeEu"); /// /// Get the data range/2 in EU. /// public override double DataHalfRangeValueEu => throw new NotImplementedException("SquibEventChannel::DataHalfRangeValueEu"); /// /// Get data zero level counts. /// public override short DataZeroLevelAdc => throw new NotImplementedException("SquibEventChannel::DataZeroLevelAdc"); /// /// Set the appropriate properties in this class from the equivalent properties /// of the specified object. /// /// /// /// The object containing the /// property values to be copied. /// /// public override void SetPropertyValuesFrom(DASChannel dasChannel) { try { if (null == dasChannel) throw new ArgumentNullException("could not initialize from null das channel reference"); var squib = dasChannel as OutputSquibChannel; if (null == squib) throw new ArgumentException("could not interpret " + dasChannel.GetType().FullName + " initialization object as " + typeof(OutputSquibChannel).FullName); OffsetToleranceLowMv = double.NaN; OffsetToleranceHighMv = double.NaN; //this.SensorID = null != analogChannel.IDs && analogChannel.IDs.Length > 0 ? analogChannel.IDs[0].ID : ""; SensorID = squib.IDs[0].ID.ToString(); LastCalibrationDate = (DateTime) System.Data.SqlTypes.SqlDateTime.MinValue; ChannelDescriptionString = string.IsNullOrWhiteSpace(squib.UserValue1) ? squib.SquibDescription : squib.UserValue1; ChannelName2 = squib.ChannelName2; switch (MeasurementType) { case OutputSquibChannel.SquibMeasurementType.CURRENT: if (ChannelDescriptionString.EndsWith(".1")) { ChannelDescriptionString = ChannelDescriptionString.Substring(0, ChannelDescriptionString.Length - 2) + ".2"; } ChannelDescriptionString += " (Current)"; if (ChannelName2 != null) { if (ChannelName2.EndsWith(".1")) { ChannelName2 = ChannelName2.Substring(0, ChannelName2.Length - 2) + ".2"; } ChannelName2 += " (Current)"; } break; case OutputSquibChannel.SquibMeasurementType.INIT_SIGNAL: ChannelDescriptionString += " (Init Signal)"; ChannelName2 += " (Init Signal)"; break; case OutputSquibChannel.SquibMeasurementType.VOLTAGE: ChannelDescriptionString += " (Voltage)"; ChannelName2 += " (Voltage)"; break; case OutputSquibChannel.SquibMeasurementType.NONE: ChannelDescriptionString += " (NONE)"; ChannelName2 += " (NONE)"; break; default: throw new NotSupportedException( "unknown measurement type " + MeasurementType.ToString()); } //this.Description = squib.SquibDescription; IsConfigured = squib.IsConfigured(); IsoCode = squib.ISOCode; Number = squib.ModuleChannelNumber; AbsoluteDisplayOrder = dasChannel.AbsoluteDisplayOrder; UnitConversion = dasChannel.UnitConverision; MvPerEu = 1; // analogChannel.SensitivityMilliVoltsPerEU; ScaleFactorMv = squib.ScaleFactorMv; PreTestZeroLevelAdc = squib.PreTestDataZeroLevelADC; Start = squib.EventStartTime; UserValue1 = squib.UserValue1; UserValue2 = squib.UserValue2; UserValue3 = squib.UserValue3; HardwareChannelName = squib.HardwareChannelName; if (squib.SoftwareFilterFrequency > 0) { CurrentFilter = new DefaultSaeJ211Filter(squib.SoftwareFilterFrequency); DefaultFilter = new DefaultSaeJ211Filter(squib.SoftwareFilterFrequency); } } catch (System.Exception ex) { throw new Exception( "encountered problem setting property values from " + (null != dasChannel ? dasChannel.GetType().FullName : "<>") + " object", ex); } } } public partial class SquibDigitalChannel : Channel { /// /// Initialize an instance of the DTS.Slice.Control.Event.Module.SquibEventChannel class. /// /// /// /// The that contains this channel. /// /// /// /// The unique "absolute" number of the channel with respect to all other channels /// on all other DASes in the system. /// /// protected SquibDigitalChannel(Module parentModule, int absoluteNumber) : base(parentModule, absoluteNumber) { // // Intended only for constructing implicit conversion instances, hence the // restrictive access modifier. } // /// /// Initialize an instance of the DTS.Slice.Control.Event.Module.SquibEventChannel class. /// /// /// /// The with which to initialize this object. /// /// /// /// The that contains this channel. /// /// /// /// The unique "absolute" number of the channel with respect to all other channels /// on all other DASes in the system. /// /// public SquibDigitalChannel(DASChannel channel, Module parentModule, int absoluteNumber) : base(channel, parentModule, absoluteNumber) { try { // // Initialize this object's analog input-specific values with whatever we can // squeeze out of the specified channel object. // channel. // MvPerEu = 1.0; ScaleFactorMv = 1.0; SetPropertyValuesFrom(channel); } catch (System.Exception ex) { throw new Exception("encountered problem constructing " + GetType().FullName, ex); } } /// /// Convert this object to a DTS.Serialization.Test.Module.Channel. /// /// /// /// A equivalent for this object. /// /// public override Serialization.Test.Module.Channel ToDtsSerializationTestModuleChannel( Serialization.Test.Module parentModule) { throw new NotImplementedException("SquibDigitalChannel::ToDtsSerializationTestModuleChannel"); } /// /// Initialize this object from the specified DTS.Serialization.Test.Module.Channel. /// /// /// /// A from which to initialize this object. /// /// public override void FromDtsSerializationTestModuleChannel( Serialization.Test.Module.Channel that) { throw new NotImplementedException("SquibDigitalChannel::FromDtsSerializationTestModuleChannel"); } /* /// /// Method to allow derived classes to initialize their own reviewable attributes. /// /// /// /// The or s to be initialized. /// /// /// /// Initialize this object's list of reviewable attributes. /// protected override void InitializeReviewableAttributes(List reviewableAttributes) { try { } catch (System.Exception ex) { throw new Event.Module.AnalogInputChannel.Exception("encountered problem initializing reviewiable attribute list", ex); } } */ public override List GetUnfilteredDataEu() { throw new NotImplementedException("SquibDigitalChannel::GetUnfilteredDataEu"); } public override List GetUnfilteredDataMV() { throw new NotImplementedException("SquibDigitalChannel::GetUnFilteredDataMV"); } /// /// Get value indicating whether or not the specified channel is configured. /// public override bool IsConfigured { get; set; } /// /// Get the actual available maximum EU range based on scaling factor and bit resolution. /// public override double ActualMaxRangeEu => throw new NotImplementedException("SquibDigitalChannel::ActualMaxRangeEu"); public override double DesiredRangeEU => throw new NotImplementedException("SquibDigitalChannel:DesiredRangeEu"); public override double SensorCapacityEU => throw new NotImplementedException("SquibDigitalChannel:SensorCapacityEu"); /// /// Get the actual available minimum EU range based on scaling factor and bit resolution. /// public override double ActualMinRangeEu => throw new NotImplementedException("SquibDigitalChannel::ActualMinRangeEu"); /// /// Get the data min in EU. /// public override double DataMinEu => throw new NotImplementedException("SquibDigitalChannel::DataMinEu"); /// /// Get the data max in EU. /// public override double DataMaxEu => throw new NotImplementedException("SquibDigitalChannel::DataMaxEu"); /// /// Get the data range in EU. /// public override double DataRangeEu => throw new NotImplementedException("SquibDigitalChannel::DataRangeEu"); /// /// Get the data range/2 in EU. /// public override double DataHalfRangeValueEu => throw new NotImplementedException("SquibDigitalChannel::DataHalfRangeValueEu"); /// /// Get data zero level counts. /// public override short DataZeroLevelAdc => throw new NotImplementedException("SquibDigitalChannel::DataZeroLevelAdc"); /// /// Set the appropriate properties in this class from the equivalent properties /// of the specified object. /// /// /// /// The object containing the /// property values to be copied. /// /// public override void SetPropertyValuesFrom(DASChannel dasChannel) { try { } catch (System.Exception ex) { throw new Exception("encountered problem setting property values from " + (null != dasChannel ? dasChannel.GetType().FullName : "<>") + " object", ex); } } } public partial class IEPEInputChannel : AnalogInputChannel { public IEPEInputChannel(DASChannel channel, Module parentModule, int absoluteNumber) : base(channel, parentModule, absoluteNumber) { } } /// /// Representation of the DTS.Slice.Control.Event.Module.AnalogInputChannel class. /// public partial 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.ILevelTriggerable, Common.DAS.Concepts.DAS.Channel.ILinearized { /// /// Initialize an instance of the DTS.Slice.Control.Event.Module.AnalogInputChannel class. /// /// /// /// The that contains this channel. /// /// /// /// The unique "absolute" number of the channel with respect to all other channels /// on all other DASes in the system. /// /// protected AnalogInputChannel(Module parentModule, int absoluteNumber) : base(parentModule, absoluteNumber) { // // Intended only for constructing implicit conversion instances, hence the // restrictive access modifier. } // /// /// Initialize an instance of the DTS.Slice.Control.Event.Module.AnalogInputChannel class. /// /// /// /// The with which to initialize this object. /// /// /// /// The that contains this channel. /// /// /// /// The unique "absolute" number of the channel with respect to all other channels /// on all other DASes in the system. /// /// public AnalogInputChannel(DASChannel channel, Module parentModule, int absoluteNumber) : base(channel, parentModule, absoluteNumber) { try { // // Initialize this object's analog input-specific values with whatever we can // squeeze out of the specified channel object. // channel. // MvPerEu = 1.0; ScaleFactorMv = 1.0; SetPropertyValuesFrom(channel); DoRoundOffLevelTriggerThresholdValues = true; } catch (System.Exception ex) { throw new Exception("encountered problem constructing " + GetType().FullName, ex); } } /// /// Initialize an instance of the DTS.Slice.Control.Event.Module.AnalogInputChannel class. /// /// /// /// The with which to initialize this object. /// /// /// /// The that contains this channel. /// /// /// /// The unique "absolute" number of the channel with respect to all other channels /// on all other DASes in the system. /// /// public AnalogInputChannel(Serialization.Test.Module.Channel channel, Module parentModule, int absoluteNumber) : base(channel, parentModule, absoluteNumber) { try { // // Initialize this object's analog input-specific values with whatever we can // squeeze out of the specified channel object. // if (channel is Serialization.Test.Module.AnalogInputChannel) { Scaler.IEPE = (channel as Serialization.Test.Module.AnalogInputChannel).Bridge == Test.Module.Channel.Sensor.BridgeType.IEPE; Scaler.Digital = (channel as Serialization.Test.Module.AnalogInputChannel).Bridge == Test.Module.Channel.Sensor.BridgeType.DigitalInput; InitialOffset = (channel as Serialization.Test.Module.AnalogInputChannel).InitialOffset; } MvPerEu = channel.Data.MvPerEu; ScaleFactorMv = channel.Data.ScaleFactorMv; if (channel.Data.UseTDASScaleFactors) { try { ScaleFactorEU = channel.Data.ScaleFactorEU; } catch (System.Exception) { ScaleFactorEU = 0; } } Scaler.SetUseTDASScaleFactors(channel.Data.UseTDASScaleFactors); RemovedADC = channel.RemovedADC; ChannelId = channel.ChannelId; ChannelGroupName = channel.ChannelGroupName; AbsoluteDisplayOrder = channel.AbsoluteDisplayOrder; UnitConversion = (channel as Serialization.Test.Module.AnalogInputChannel).UnitConversion; AtCapacity = (channel as Serialization.Test.Module.AnalogInputChannel).AtCapacity; CapacityOutputIsBasedOn = (channel as Serialization.Test.Module.AnalogInputChannel).CapacityOutputIsBasedOn; SensitivityUnits = (channel as Serialization.Test.Module.AnalogInputChannel).SensitivityUnits; FromDtsSerializationTestModuleChannel(channel); try { if (channel.Data.UseTDASScaleFactors) { Scaler.SetDataZeroLevelADC((short)channel.TDASPersistentChannelInfo.DataZeroLevelInCnts); } else { Scaler.SetDataZeroLevelADC(DataZeroLevelAdc); //if we have a linearized value and are set for none, the the datazeroleveladc shouldn't be used //we should be using only the zeromvinadc... var aic = channel as Serialization.Test.Module.AnalogInputChannel; if (null != aic) { if (aic.LinearizationFormula.IsValid() && aic.ZeroMethod == Test.Module.Channel.Sensor.ZeroMethodType.None) { Scaler.SetDataZeroLevelADC(0); } } } } catch (System.Exception) { Scaler.SetDataZeroLevelADC(PreTestZeroLevelAdc); } Scaler.SetRemovedADC(channel.RemovedADC); Scaler.SetRemovedInternalADC(channel.RemovedInternalADC); var aveOverTime = double.NaN; try { if (channel.Data.UseTDASScaleFactors) { aveOverTime = Convert.ToDouble(channel.TDASPersistentChannelInfo.DataZeroLevelInCnts); } else { aveOverTime = Convert.ToDouble(DataZeroLevelAdc); } } catch (System.Exception) { } var diagnosticsADC = double.NaN; try { diagnosticsADC = Convert.ToDouble(PreTestZeroLevelAdc); } catch (System.Exception) { } /*try { Scaler.SetIRTraccZeros(aveOverTime, diagnosticsADC); } catch (System.Exception) { } */ try { Scaler.SetZeroMvInADC(ZeroMvInADC); } catch (System.Exception) { } try { Scaler.SetWindowAverageADC(WindowAverageADC); } catch (System.Exception) { } } catch (System.Exception ex) { throw new Exception("encountered problem constructing " + GetType().FullName, ex); } } private bool UseISOCodesInReview = false; private bool UseShuntDeflectionInReview = false; private bool ReviewForm_UseCalSigInReview = false; /* /// /// Initialize this object's list of reviewable attributes. /// protected override void InitializeReviewableAttributes(List reviewableAttributes) { try { try { reviewableAttributes.Add(new ReviewableSerialNumberAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableDescriptionAttribute(this)); } catch { } if (true == UseISOCodesInReview) { try { reviewableAttributes.Add(new ReviewableIsoCodeAttribute(this)); } catch { } } if (true == UseShuntDeflectionInReview) { try { reviewableAttributes.Add(new ReviewableTargetShuntDeflectionAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableMeasuredShuntDeflectionAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableShuntDeflectionPercentageAttribute(this)); } catch { } } if (true == ReviewForm_UseCalSigInReview) { //if (CalSignalEnabled) { try { reviewableAttributes.Add(new ReviewableTargetCalSignalAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableMeasuredCalSignalAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableCalSignalPercentageAttribute(this)); } catch { } } } try { reviewableAttributes.Add(new ReviewableUnitsAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableFilterFrequencyAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableCfcAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableMinMaxEuAttribute(this)); } catch { } } catch (System.Exception ex) { throw new Event.Module.AnalogInputChannel.Exception("encountered problem initializing reviewiable attribute list", ex); } } */ /// /// Get/set the bridge configuration of this channel. /// public Test.Module.Channel.Sensor.BridgeType Bridge { get => _Bridge.Value; set => _Bridge.Value = value; } private readonly Property _Bridge = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.BridgeType", Test.Module.Channel.Sensor.BridgeType.FullBridge, false ); private readonly Property _ZeroPoint = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.ZeroPoint", 0D, false); public double ZeroPoint { get { if (_ZeroPoint.IsValueInitialized) { return _ZeroPoint.Value; } return 0D; } set => _ZeroPoint.Value = value; } /// /// Get/set the bridge resistance for this channel. /// public double BridgeResistanceOhms { get => _BridgeResistanceOhms.Value; set => _BridgeResistanceOhms.Value = value; } private readonly Property _BridgeResistanceOhms = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.BridgeResistanceOhms", 0.0, false ); /// /// Get/set the description for this channel. /// public string Description { get => null != _Description.Value ? _Description.Value : ""; set => _Description.Value = value; } private readonly Property _Description = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.Description", "", true ); /// /// Get/set the manufacturer for this channel. /// public string Manufacturer { get => null != _Manufacturer.Value ? _Manufacturer.Value : ""; set => _Manufacturer.Value = value; } private readonly Property _Manufacturer = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.Manufacturer", "", true ); /// /// Get/set the description for this channel. /// public string Model { get => null != _Model.Value ? _Model.Value : ""; set => _Model.Value = value; } private readonly Property _Model = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.Model", "", true ); /// /// Get/set the desired range for this channel. /// public double DesiredRange { get => _DesiredRange.Value; set => _DesiredRange.Value = value; } private readonly Property _DesiredRange = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.DesiredRange", 0.0, false ); /// /// Get/set the sensor capacity for this channel. /// public double SensorCapacity { get => _SensorCapacity.Value; set => _SensorCapacity.Value = value; } private readonly Property _SensorCapacity = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.SensorCapacity", 0.0, false ); /// /// Get/set the sensitivity for this channel. /// public double Sensitivity { get => _Sensitivity.Value; set => _Sensitivity.Value = value; } private readonly Property _Sensitivity = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.Sensitivity", 0.0, false ); /// /// Get/set the descriptor indiciating whether or not this channel is /// proportional to excitation. /// public bool ProportionalToExcitation { get { try { return Scaler.ProportionalToExcitation; } catch (System.Exception ex) { throw new Exception("encountered problem getting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.ProportionalToExcitation property value", ex); } } set { try { Scaler.ProportionalToExcitation = value; } catch (System.Exception ex) { throw new Exception("encountered problem setting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.ProportionalToExcitation property value", ex); } } } /// /// Get/set the nominal excitation voltage for this channel. /// public Test.Module.Channel.Sensor.ExcitationVoltageOption ExcitationVoltage { get { try { return Scaler.NominalExcitationVoltage; } catch (System.Exception ex) { throw new Exception("encountered problem getting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.NominalExcitationVoltage property value", ex); } } set { try { Scaler.NominalExcitationVoltage = (value == Test.Module.Channel.Sensor.ExcitationVoltageOption.Undefined ? ParentModule.NominalExcitationVoltage : value); } catch (System.Exception ex) { throw new Exception("encountered problem setting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.NominalExcitationVoltage property value", ex); } } } /// /// Get/set the measured excitation voltage for this channel. /// public double MeasuredExcitationVoltage { get { try { return Scaler.MeasuredExcitationVoltage; } catch (System.Exception ex) { throw new Exception("encountered problem setting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.MeasuredExcitationVoltage property value", ex); } } set { try { Scaler.MeasuredExcitationVoltage = value; } catch (System.Exception ex) { throw new Exception("encountered problem getting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.MeasuredExcitationVoltage property value", ex); } } } public bool FactoryExcitationVoltageValid { get { if (null == Scaler || !Scaler.FactoryExcitationVoltageValid) { return false; } return true; } } /// /// Get/set the factory excitation voltage for this channel. /// public double FactoryExcitationVoltage { get { try { return Scaler.FactoryExcitationVoltage; } catch (System.Exception ex) { throw new Exception("encountered problem setting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.FactoryExcitationVoltage property value", ex); } } set { try { Scaler.FactoryExcitationVoltage = value; } catch (System.Exception ex) { throw new Exception("encountered problem getting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.FactoryExcitationVoltage property value", ex); } } } /// /// Get/set the engineering units for this channel. /// public string EngineeringUnits { get => _EngineeringUnits.Value; set => _EngineeringUnits.Value = value; } private readonly Property _EngineeringUnits = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.EngineeringUnits", null, false ); /// /// Get/set the flag indicating whether or not this channel is /// actually configured. /// public override bool IsConfigured { get => _IsConfigured.Value; set => _IsConfigured.Value = value; } private readonly Property _IsConfigured = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.IsConfigured", false, false ); /// /// Get/set channel inversion status. /// public bool IsInverted { get { try { return Scaler.IsInverted; } catch (System.Exception ex) { throw new Exception("encountered problem getting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.IsInverted property value", ex); } } set { try { Scaler.IsInverted = value; } catch (System.Exception ex) { throw new Exception("encountered problem setting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.IsInverted property value", ex); } } } /// /// Get/set channel inversion status. /// public LinearizationFormula LinearizationFormula { get { try { return Scaler.GetLinearizationFormula(); } catch (System.Exception ex) { throw new Exception("encountered problem getting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.LinearizationFormula property value", ex); } } set { try { Scaler.SetLinearizationFormula(value); } catch (System.Exception ex) { throw new Exception("encountered problem setting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.LinearizationFormula property value", ex); } } } public DigitalInputScaleMultiplier DigitalMultiplier { get { try { return Scaler.GetDigitalMultiplier(); } catch (System.Exception ex) { throw new Exception("encountered problem getting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.DigitalMultiplier property value", ex); } } set { try { Scaler.SetDigitalMultiplier(value); Scaler.Digital = Bridge == Test.Module.Channel.Sensor.BridgeType.DigitalInput; } catch (System.Exception ex) { throw new Exception("encountered problem setting " + typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.DigitalMultiplier property value", ex); } } } public DigitalInputScaleMultiplier.InputModes DigitalMode { get => Scaler.DigitalMode; set { try { Scaler.DigitalMode = value; } catch (System.Exception) { } } } /// /// Get/set the ISO code for this channel's data source. /// public string IsoCode { get => _IsoCode.Value; set => _IsoCode.Value = value; } private readonly Property _IsoCode = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.IsoCode", null, false ); /// /// Get/set the measured shunt deflection value. /// public double MeasuredShuntDeflectionMv { get => _MeasuredShuntDeflectionMv.Value; set => _MeasuredShuntDeflectionMv.Value = value; } private readonly Property _MeasuredShuntDeflectionMv = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.MeasuredShuntDeflectionMv", 0.0, false ); /// /// Get/set the target shunt deflection value. /// public double TargetShuntDeflectionMv { get => _TargetShuntDeflectionMv.Value; set => _TargetShuntDeflectionMv.Value = value; } private readonly Property _TargetShuntDeflectionMv = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.TargetShuntDeflectionMv", 0.0, false ); /// /// Get/set the measured shunt deflection value. /// public double MeasuredCalSignalMv { get => _MeasuredCalSignalMv.Value; set => _MeasuredCalSignalMv.Value = value; } private readonly Property _MeasuredCalSignalMv = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.MeasuredCalSignalMv", 0.0, false ); /// /// Get/set the target shunt deflection value. /// public double TargetCalSignalMv { get => _TargetCalSignalMv.Value; set => _TargetCalSignalMv.Value = value; } private readonly Property _TargetCalSignalMv = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.TargetCalSignalMv", 0.0, false ); /// /// Get/set the serial number for this channel's data source. /// public string SerialNumber { get => _SerialNumber.Value; set => _SerialNumber.Value = value; } private readonly Property _SerialNumber = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.SerialNumber", null, false ); /// /// Get/set the shunt enable indicator for this channel. /// public bool CalSignalEnabled { get { if (_CalSignalEnabled.IsInitialized) { return _CalSignalEnabled.Value; } return false; } set => _CalSignalEnabled.Value = value; } private readonly Property _CalSignalEnabled = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.CalSignalEnabled", false, false ); /// /// Get/set the shunt enable indicator for this channel. /// public bool ShuntEnabled { get => _ShuntEnabled.Value; set => _ShuntEnabled.Value = value; } private readonly Property _ShuntEnabled = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.ShuntEnabled", false, false ); /// /// Get/set the shunt enable indicator for this channel. /// public bool VoltageInsertionCheckEnabled { get => _VoltageInsertionCheckEnabled.Value; set => _VoltageInsertionCheckEnabled.Value = value; } private readonly Property _VoltageInsertionCheckEnabled = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.VoltageInsertionCheckEnabled", false, false ); /// /// Get/set the remove offset option for this channel. /// public bool RemoveOffset { get => _RemoveOffset.Value; set => _RemoveOffset.Value = value; } private readonly Property _RemoveOffset = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.RemoveOffset", false, false ); /// /// Get/set the zero method option for this channel. /// public Test.Module.Channel.Sensor.ZeroMethodType ZeroMethod { get => _ZeroMethod.Value; set { _ZeroMethod.Value = value; Scaler.ZeroMethodType = value; } } private readonly Property _ZeroMethod = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.ZeroMethod", Test.Module.Channel.Sensor.ZeroMethodType.AverageOverTime, false ); /// /// Get/set zero average window definition. /// public IntervalSec ZeroAverageWindow { get => _ZeroAverageWindow.Value; set => _ZeroAverageWindow.Value = value; } private readonly Property _ZeroAverageWindow = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.ZeroAverageWindow", null, false ); /// /// Get/set the initial EU value. /// public double InitialEu { get => _InitialEu.Value; set => _InitialEu.Value = value; } private readonly Property _InitialEu = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.InitialEu", 0.0, false ); public string InitialOffset { get => _initialOffset.Value??""; set { _initialOffset.Value = value; Scaler.SetInitialOffset(value); } } private readonly Property _initialOffset = new Property( typeof(AnalogInputChannel).Namespace + ".Event.Module.AnalogInputChannel.InitalOffset", "", true); /// /// Get/set whether or not level trigge threshold values are automatically rounded. /// public bool DoRoundOffLevelTriggerThresholdValues { get; set; } /// /// Get/set the number of decimal places level trigger threshold values will automatically /// be rounded to if DoRoundOffValues property is true. /// public int NumberOfLevelTriggerThresholdValueRoundingDecimalPlaces { get => _NumberOfLevelTriggerThresholdValueRoundingDecimalPlaces.Value; set => _NumberOfLevelTriggerThresholdValueRoundingDecimalPlaces.Value = value; } private readonly Property _NumberOfLevelTriggerThresholdValueRoundingDecimalPlaces = new Property( typeof(AnalogInputChannel).Namespace + ".NumberOfLevelTriggerThresholdValueRoundingDecimalPlaces", 6, true ); /// /// Get/set the "trigger below" threshold. Set to "null" to deactivate. /// public double? TriggerBelowThresholdEu { get => (DoRoundOffLevelTriggerThresholdValues && null != _TriggerBelowThreshold.Value) ? Math.Round((double)_TriggerBelowThreshold.Value, NumberOfLevelTriggerThresholdValueRoundingDecimalPlaces) : _TriggerBelowThreshold.Value; set => _TriggerBelowThreshold.Value = value; } private readonly Property _TriggerBelowThreshold = new Property( typeof(AnalogInputChannel).FullName + ".TriggerBelowThresholdEu", null, false ); /// /// Get/set the "trigger above" threshold. Set to "null" to deactivate. /// public double? TriggerAboveThresholdEu { get => (DoRoundOffLevelTriggerThresholdValues && null != _TriggerAboveThreshold.Value) ? Math.Round((double)_TriggerAboveThreshold.Value, NumberOfLevelTriggerThresholdValueRoundingDecimalPlaces) : _TriggerAboveThreshold.Value; set => _TriggerAboveThreshold.Value = value; } private readonly Property _TriggerAboveThreshold = new Property( typeof(AnalogInputChannel).FullName + ".TriggerAboveThresholdEu", null, false ); private readonly Property _LevelTriggerType = new Property( typeof(AnalogInputChannel).FullName + ".LevelTriggerType", Common.DAS.Concepts.DAS.Channel.LevelTriggerTypes.NONE, true); public Common.DAS.Concepts.DAS.Channel.LevelTriggerTypes LevelTriggerType { get => _LevelTriggerType.Value; set => _LevelTriggerType.Value = value; } /// /// Get data zero level counts. /// public override short DataZeroLevelAdc { get { if (null == _DataZeroLevelCounts) switch (ZeroMethod) { case Test.Module.Channel.Sensor.ZeroMethodType.AverageOverTime: if ((ZeroAverageWindow.Begin == 0) && (ZeroAverageWindow.End == 0)) { _DataZeroLevelCounts = PreTestZeroLevelAdc; } else //if we have Average Over Time we do two things, if we have a known average via WindowAverageADC we use it //otherwise we try to calculate it on the fly, we can handle older data and newer and it's done in a way //similar to the other zeroing methods //if (WindowAverageADC != InvalidWindowAverage) { _DataZeroLevelCounts = WindowAverageADC; } //else { var preTriggerTime = 0D; if (null != ParentModule.TriggerSampleNumbers) { preTriggerTime = ((double) ParentModule.TriggerSampleNumbers[0] - (double) ParentModule.StartRecordSampleNumber)/ (double) ParentModule.SampleRateHz; } if (preTriggerTime < 0) { preTriggerTime = 0; } try { var numSamples = (ulong) ((ZeroAverageWindow.End - ZeroAverageWindow.Begin)* ParentModule.SampleRateHz) + 1; var windowSamples = new double[numSamples]; var startingIndex = ((ulong) ((preTriggerTime + ZeroAverageWindow.Begin)* ParentModule.SampleRateHz)); var pc = UnfilteredData as Serialization.SliceRaw.File.PersistentChannel; var insertPoint = 0; for (var i = startingIndex; i < startingIndex + numSamples; i++) { //windowSamples[i] = this[i]; windowSamples[insertPoint ++] = Convert.ToDouble(pc[i]); } //PER TJK, and MB, don't use filtering for the averaging window, since it's double work //if( null != CurrentFilter && CurrentFilter.Type != ChannelFilter.Unfiltered) //{ // double averageNoFilter = windowSamples.Average(); // windowSamples = CurrentFilter.Apply(windowSamples, ParentModule.SampleRateHz); // _DataZeroLevelCounts = Convert.ToInt16(windowSamples.Average()); // System.Diagnostics.Trace.WriteLine("unfiltered average: " + averageNoFilter.ToString() + " filtered average: " + windowSamples.Average()); //} //else //{ _DataZeroLevelCounts = Convert.ToInt16(windowSamples.Average()); //} //calculating the average requires that we filter the data set, //since we just loaded all the data to calculate it, now go and unload it all ... // unsetting takes time and we are likely to reuse this data // have something else unset it //if (this is Slice.Control.Event.Module.Channel) //{ // (this as Slice.Control.Event.Module.Channel).UnSet(); //} } catch (System.Exception ex) { APILogger.Log(ex); _DataZeroLevelCounts = PreTestZeroLevelAdc; } } break; case Test.Module.Channel.Sensor.ZeroMethodType .UsePreEventDiagnosticsZero: _DataZeroLevelCounts = PreTestZeroLevelAdc; break; case Test.Module.Channel.Sensor.ZeroMethodType.None: //all NonLinear sensors use GetMv() which already makes an adjustment for ZeroMvInADC, so we don't want to double adjust ... //if (null != LinearizationFormula && LinearizationFormula.IsValid()) { _DataZeroLevelCounts = 0; } //else { _DataZeroLevelCounts = ZeroMvInADC; } //if (!RemoveOffset) { _DataZeroLevelCounts = ZeroMvInADC; } //else { _DataZeroLevelCounts = 0;} //per RJW, ZeroMvInADC is not what we want to use, we want to use FinalOffsetADC, which I don't seem to have, but I do have //PreTestZeroLevelADC if (RemoveOffset) { _DataZeroLevelCounts = PreTestZeroLevelAdc; } else { _DataZeroLevelCounts = ZeroMvInADC; } break; default: throw new NotImplementedException("Data zero level count generation for zero method \"" + ZeroMethod.ToString() + "\" is not implemented"); } return (short)_DataZeroLevelCounts; } } private short? _DataZeroLevelCounts = 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 ); /// /// Set applicable analog input channel values from the corresponding /// -borne properties. /// /// /// /// The containing values to be transfered /// to this channel. /// /// public override void SetPropertyValuesFrom(DiagnosticsResult calibrationResults) { try { if (null != calibrationResults.MeasuredExcitationMilliVolts) MeasuredExcitationVoltage = (double)(calibrationResults.MeasuredExcitationMilliVolts) / 1000.0; FactoryExcitationVoltage = calibrationResults.ExpectedExcitationMilliVolts / 1000.0; base.SetPropertyValuesFrom(calibrationResults); } catch (System.Exception ex) { throw new Exception("encountered problem setting analog input channel property values from calibration results", ex); } } /// /// Set the appropriate properties in this class from the equivalent properties /// of the specified object. /// /// /// /// The object containing the /// property values to be copied. /// /// public override void SetPropertyValuesFrom(DASChannel dasChannel) { try { if (null == dasChannel) throw new ArgumentNullException("could not initialize from null das channel reference"); var analogChannel = dasChannel as AnalogInputDASChannel; if (null == analogChannel) throw new ArgumentException("could not interpret " + dasChannel.GetType().FullName + " initialization object as " + typeof(AnalogOutputDASChannel).FullName); Scaler.Digital = analogChannel.TypeOfBridge == Test.Module.Channel.Sensor.BridgeType.DigitalInput; Scaler.IEPE = analogChannel.IEPEChannel; OffsetToleranceLowMv = analogChannel.OffsetToleranceLowMilliVolts; OffsetToleranceHighMv = analogChannel.OffsetToleranceHighMilliVolts; //this.SensorID = null != analogChannel.IDs && analogChannel.IDs.Length > 0 ? analogChannel.IDs[0].ID : ""; SensorID = analogChannel.SensorID; LastCalibrationDate = analogChannel.LastCalibrationDate; Bridge = analogChannel.TypeOfBridge; BridgeResistanceOhms = analogChannel.BridgeResistanceOhms; ZeroPoint = analogChannel.ZeroPoint; ChannelDescriptionString = analogChannel.ToString(); ChannelName2 = analogChannel.ChannelName2; ChannelId = analogChannel.ChannelId; ChannelGroupName = analogChannel.ChannelGroupName; HardwareChannelName = analogChannel.HardwareChannelName; UserValue1 = analogChannel.UserValue1; UserValue2 = analogChannel.UserValue2; UserValue3 = analogChannel.UserValue3; Description = analogChannel.Description; Manufacturer = analogChannel.Manufacturer; Model = analogChannel.Model; DesiredRange = analogChannel.SensorCapacityEU; SensorCapacity = analogChannel.SensorCapacity; EngineeringUnits = analogChannel.EngineeringUnits; ExcitationVoltage = analogChannel.Excitation; IsConfigured = analogChannel.IsConfigured(); IsInverted = analogChannel.IsInverted; LinearizationFormula = analogChannel.LinearizationFormula; DigitalMultiplier = analogChannel.DigitalMultiplier; DigitalMode = analogChannel.DigitalMode; InitialEu = analogChannel.InitialEU; ZeroMvInADC = analogChannel.ZeromVInADC; InitialOffset = analogChannel.InitialOffset; IsoCode = analogChannel.ISOCode; Number = analogChannel.ModuleChannelNumber; AbsoluteDisplayOrder = analogChannel.AbsoluteDisplayOrder; ProportionalToExcitation = analogChannel.IsProportionalToExcitation; AtCapacity = analogChannel.AtCapacity; CapacityOutputIsBasedOn = analogChannel.CapacityOutputIsBasedOn; SensitivityUnits = analogChannel.SensitivityUnits; RemoveOffset = analogChannel.RemoveOffset; MvPerEu = analogChannel.SensitivityMilliVoltsPerEU;// *(analogChannel.IsProportionalToExcitation ? DTS.Common.DAS.Concepts.Test.Module.Channel.Sensor.GetExcitationVoltageMagnitudeFromEnum(analogChannel.Excitation) : 1); ScaleFactorMv = analogChannel.ScalefactorMilliVoltsPerADC; UnitConversion = analogChannel.UnitConverision; Sensitivity = analogChannel.SensitivityMilliVoltsPerEU; SerialNumber = analogChannel.SerialNumber; ShuntEnabled = analogChannel.ShuntIsEnabled; VoltageInsertionCheckEnabled = analogChannel.VoltageInsertionCheckEnabled; CalSignalEnabled = analogChannel.CalSignalIsEnabled; Start = analogChannel.EventStartTime; NoiseAsPercentageOfFullScale = analogChannel.NoiseAsPercentOfFullScale; // Note that we'll have to change this logic when ISO codes are introduced, so // we'll know to create a CFC filter instead of an ad hoc which appropriate, and // vice versa. CurrentFilter = analogChannel.SoftwareFilterFrequency > 0 ? new SaeJ211Filter(analogChannel.SoftwareFilterFrequency) : new SaeJ211Filter(ChannelFilter.Unfiltered); if (!AvailableFilters.Contains(CurrentFilter)) AvailableFilters.Add(CurrentFilter); UserValue1 = analogChannel.UserValue1; UserValue2 = analogChannel.UserValue2; UserValue3 = analogChannel.UserValue3; ZeroAverageWindow = new IntervalSec(analogChannel.ZeroAverageStartSeconds, analogChannel.ZeroAverageStopSeconds); ZeroMethod = analogChannel.ZeroMethod; } catch (System.Exception ex) { throw new Exception("encountered problem setting property values from " + (null != dasChannel ? dasChannel.GetType().FullName : "<>") + " object", ex); } } /// /// Convert this object to a DTS.Serialization.Test.Module.Channel. /// /// /// /// The equivalent to this object. /// /// public override Serialization.Test.Module.Channel ToDtsSerializationTestModuleChannel(Serialization.Test.Module parentModule) { try { var that = new Serialization.Test.Module.AnalogInputChannel(parentModule); if (!IsConfigured) throw new Exception("cannot serialize unconfigured analog input channel"); that.AverageAdcOverTime = AverageAdcOverTime; that.Bridge = Bridge; that.BridgeResistanceOhms = BridgeResistanceOhms; that.ZeroPoint = ZeroPoint; that.ChannelDescriptionString = ChannelDescriptionString; that.ChannelId = ChannelId; that.ChannelGroupName = ChannelGroupName; that.ChannelName2 = ChannelName2 != null ? ChannelName2 : "N/A"; that.HardwareChannelName = HardwareChannelName != null ? HardwareChannelName : "N/A"; that.Description = Description; that.Manufacturer = Manufacturer; that.Model = Model; that.DesiredRange = DesiredRange; that.EngineeringUnits = EngineeringUnits; that.ExcitationVoltage = ExcitationVoltage; that.InitialOffset = InitialOffset; that.InitialEu = InitialEu; that.DigitalMultiplier = DigitalMultiplier; that.DigitalMode = DigitalMode; that.LinearizationFormula = LinearizationFormula; that.IsInverted = IsInverted; that.IsSubsampled = IsSubsampled; if (IsLastCalibrationDateValid) { that.LastCalibrationDate = LastCalibrationDate; } if (IsSensorIDValid) { that.SensorID = SensorID; } if (IsOffsetToleranceLowMvValid) { that.OffsetToleranceLowMv = OffsetToleranceLowMv; } if (IsOffsetToleranceHighMvValid) { that.OffsetToleranceHighMv = OffsetToleranceHighMv; } that.UserValue1 = UserValue1; that.UserValue2 = UserValue2; that.UserValue3 = UserValue3; that.IsoCode = IsoCode; that.NoiseAsPercentageOfFullScale = NoiseAsPercentageOfFullScale; that.Number = Number; that.AbsoluteDisplayOrder = AbsoluteDisplayOrder; that.PreTestZeroLevelAdc = PreTestZeroLevelAdc; that.ZeroMvInADC = ZeroMvInADC; that.AbsoluteDisplayOrder = AbsoluteDisplayOrder; that.WindowAverageADC = WindowAverageADC; if (RemoveOffset) { that.RemovedADC = RemovedADC; } else { that.RemovedADC = 0; } that.ProportionalToExcitation = ProportionalToExcitation; that.AtCapacity = AtCapacity; that.CapacityOutputIsBasedOn = CapacityOutputIsBasedOn; that.SensitivityUnits = SensitivityUnits; that.RemoveOffset = RemoveOffset; that.Sensitivity = Sensitivity; that.SerialNumber = SerialNumber; that.ShuntEnabled = ShuntEnabled; that.VoltageInsertionCheckEnabled = VoltageInsertionCheckEnabled; that.CalSignalEnabled = CalSignalEnabled; that.Start = Start; that.ZeroAverageWindow = ZeroAverageWindow; that.ZeroMethod = ZeroMethod; if (_MeasuredShuntDeflectionMv.IsInitialized) { try { that.MeasuredShuntDeflectionMv = MeasuredShuntDeflectionMv; } catch { }; // *** potentially unitialized *** } if (_TargetShuntDeflectionMv.IsInitialized) { try { that.TargetShuntDeflectionMv = TargetShuntDeflectionMv; } catch { }; // } if (_MeasuredCalSignalMv.IsInitialized) { try { that.MeasuredCalSignalMv = MeasuredCalSignalMv; } catch { }; // *** potentially unitialized *** } if (_TargetCalSignalMv.IsInitialized) { try { that.TargetCalSignalMv = TargetCalSignalMv; } catch { }; // } if (_TriggerAboveThreshold.IsInitialized) { try { that.TriggerAboveThresholdEu = TriggerAboveThresholdEu; } catch { }; // } if (_TriggerBelowThreshold.IsInitialized) { try { that.TriggerBelowThresholdEu = TriggerBelowThresholdEu; } catch { }; // } if (_LevelTriggerType.IsInitialized) { try { that.LevelTriggerType = LevelTriggerType; } catch { }; } if (Scaler.MeasuredExcitationVoltageValid) { try { that.MeasuredExcitationVoltage = MeasuredExcitationVoltage; } catch { }; } if (Scaler.FactoryExcitationVoltageValid) { try { that.FactoryExcitationVoltage = FactoryExcitationVoltage; } catch { }; } try { if (TimeOfFirstSampleSecValid) { that.TimeOfFirstSampleSec = TimeOfFirstSampleSec; } } catch { }; that.SoftwareFilter = CurrentFilter.ToBaseString(); that.UnitConversion = UnitConversion; that.AtCapacity = AtCapacity; that.CapacityOutputIsBasedOn = CapacityOutputIsBasedOn; that.SensitivityUnits = SensitivityUnits; that.Data = new Serialization.Test.Module.Channel.DataArray { MvPerEu = GetMvPerEu(), ScaleFactorMv = GetScaleFactorMv(), Multiplier = Multiplier, UserOffsetEU = UserOffsetEU }; // this.UnfilteredData.ToArray( ) ); that.UserOffsetEU = UserOffsetEU; that.Multiplier = Multiplier; if (UnfilteredData is Serialization.SliceRaw.File.PersistentChannel) that.PersistentChannelInfo = UnfilteredData as Serialization.SliceRaw.File.PersistentChannel; that.SensorCapacity = SensorCapacity; return that; } catch (System.Exception ex) { throw new Exception("encountered problem converting " + GetType().FullName + " to " + typeof(Serialization.Test.Module.AnalogInputChannel), ex); } } /// /// Initialize this object from a DTS.Serialization.Test.Module.Channel. /// /// /// /// The from which to initialize this object. /// /// public override void FromDtsSerializationTestModuleChannel(Serialization.Test.Module.Channel that) { try { if (null == that) throw new ArgumentNullException("cannot initialize " + GetType().FullName + " object from a null test module channel reference"); if ((that is Serialization.Test.Module.AnalogInputChannel) || (that is Serialization.Test.Module.CalculatedChannel)) { var thatAnalogChannel = that as Serialization.Test.Module.AnalogInputChannel; AverageAdcOverTime = thatAnalogChannel.AverageAdcOverTime; Bridge = thatAnalogChannel.Bridge; BridgeResistanceOhms = thatAnalogChannel.BridgeResistanceOhms; ZeroPoint = thatAnalogChannel.ZeroPoint; ChannelId = thatAnalogChannel.ChannelId; ChannelGroupName = thatAnalogChannel.ChannelGroupName; ChannelDescriptionString = thatAnalogChannel.ChannelDescriptionString; ChannelName2 = thatAnalogChannel.ChannelName2; HardwareChannelName = thatAnalogChannel.HardwareChannelName; UserValue1 = thatAnalogChannel.UserValue1; UserValue2 = thatAnalogChannel.UserValue2; UserValue3 = thatAnalogChannel.UserValue3; Description = thatAnalogChannel.Description; Manufacturer = thatAnalogChannel.Manufacturer; Model = thatAnalogChannel.Model; DesiredRange = thatAnalogChannel.DesiredRange; try { SensorCapacity = thatAnalogChannel.SensorCapacity; } catch (System.Exception ex) { APILogger.Log("could not get sensorcapacity, ", ex); } EngineeringUnits = thatAnalogChannel.EngineeringUnits; ExcitationVoltage = thatAnalogChannel.ExcitationVoltage; IsConfigured = true; IsInverted = thatAnalogChannel.IsInverted; LinearizationFormula = thatAnalogChannel.LinearizationFormula; DigitalMultiplier = thatAnalogChannel.DigitalMultiplier; DigitalMode = thatAnalogChannel.DigitalMode; IsSubsampled = thatAnalogChannel.IsSubsampled; if (thatAnalogChannel.IsLastCalibrationDateValid) { LastCalibrationDate = thatAnalogChannel.LastCalibrationDate; } if (thatAnalogChannel.IsSensorIDValid) { SensorID = thatAnalogChannel.SensorID; } if (thatAnalogChannel.IsOffsetToleranceLowMvValid) { OffsetToleranceLowMv = thatAnalogChannel.OffsetToleranceLowMv; } if (thatAnalogChannel.IsOffsetToleranceHighMvValid) { OffsetToleranceHighMv = thatAnalogChannel.OffsetToleranceHighMv; } InitialOffset = thatAnalogChannel.InitialOffset; InitialEu = thatAnalogChannel.InitialEu; if (thatAnalogChannel.IsIsoCodeValid) { IsoCode = thatAnalogChannel.IsoCode; } NoiseAsPercentageOfFullScale = thatAnalogChannel.NoiseAsPercentageOfFullScale; Number = thatAnalogChannel.Number; PreTestZeroLevelAdc = thatAnalogChannel.PreTestZeroLevelAdc; WindowAverageADC = thatAnalogChannel.WindowAverageADC; ZeroMvInADC = thatAnalogChannel.ZeroMvInADC; //try { this.ZeroMvInADC = thatAnalogChannel.ZeroMvInADC; } AbsoluteDisplayOrder = thatAnalogChannel.AbsoluteDisplayOrder; //this.PreTestZeroLevelMv = thatAnalogChannel.PreTestZeroLevelmV; if (thatAnalogChannel.RemoveOffset) { RemovedADC = thatAnalogChannel.RemovedADC; } else { RemovedADC = 0; } ProportionalToExcitation = thatAnalogChannel.ProportionalToExcitation; RemoveOffset = thatAnalogChannel.RemoveOffset; Sensitivity = thatAnalogChannel.Sensitivity; SerialNumber = thatAnalogChannel.SerialNumber; ShuntEnabled = thatAnalogChannel.ShuntEnabled; VoltageInsertionCheckEnabled = thatAnalogChannel.VoltageInsertionCheckEnabled; CalSignalEnabled = thatAnalogChannel.CalSignalEnabled; Start = thatAnalogChannel.Start; ZeroAverageWindow = thatAnalogChannel.ZeroAverageWindow; ZeroMethod = thatAnalogChannel.ZeroMethod; UnitConversion = thatAnalogChannel.UnitConversion; AtCapacity = thatAnalogChannel.AtCapacity; CapacityOutputIsBasedOn = thatAnalogChannel.CapacityOutputIsBasedOn; SensitivityUnits = thatAnalogChannel.SensitivityUnits; var bWorked = false; try { if (thatAnalogChannel.MeasureShuntDeflectionMvValid) { MeasuredShuntDeflectionMv = thatAnalogChannel.MeasuredShuntDeflectionMv; bWorked = true; } if (!thatAnalogChannel.ShuntEnabled) { bWorked = false; } } catch { bWorked = false; } if (!bWorked) { /*ReviewableAttributes.RemoveAll( delegate(ReviewableAttribute attribute) { return attribute is ReviewableMeasuredShuntDeflectionAttribute // Can't display it, so remove it || attribute is ReviewableShuntDeflectionPercentageAttribute; // } );*/ } bWorked = false; try { if (thatAnalogChannel.TargetShuntDeflectionMvValid) { TargetShuntDeflectionMv = thatAnalogChannel.TargetShuntDeflectionMv; bWorked = true; } if (!thatAnalogChannel.ShuntEnabled) { bWorked = false; } } catch { bWorked = false; } if (!bWorked) { /*ReviewableAttributes.RemoveAll( delegate(ReviewableAttribute attribute) { return attribute is ReviewableTargetShuntDeflectionAttribute // Can't display it, so remove it || attribute is ReviewableShuntDeflectionPercentageAttribute; } );*/ } bWorked = false; try { if (thatAnalogChannel.MeasuredCalSignalMvValid) { MeasuredCalSignalMv = thatAnalogChannel.MeasuredCalSignalMv; bWorked = true; } } catch { bWorked = false; } if (!bWorked) { /*ReviewableAttributes.RemoveAll( delegate(ReviewableAttribute attribute) { return attribute is ReviewableMeasuredCalSignalAttribute // Can't display it, so remove it || attribute is ReviewableCalSignalPercentageAttribute; // } );*/ } bWorked = false; try { if (thatAnalogChannel.TargetCalSignalMvValid) { TargetCalSignalMv = thatAnalogChannel.TargetCalSignalMv; bWorked = true; } } catch { bWorked = false; } if (!bWorked) { /*ReviewableAttributes.RemoveAll( delegate(ReviewableAttribute attribute) { return attribute is ReviewableTargetCalSignalAttribute // Can't display it, so remove it || attribute is ReviewableCalSignalPercentageAttribute; } );*/ } try { if (thatAnalogChannel.TriggerAboveThresholdValid) { TriggerAboveThresholdEu = thatAnalogChannel.TriggerAboveThresholdEu; } } catch { } try { if (thatAnalogChannel.TriggerBelowThresholdValid) { TriggerBelowThresholdEu = thatAnalogChannel.TriggerBelowThresholdEu; } } catch { } try { if (thatAnalogChannel.LevelTriggerTypeValid) { LevelTriggerType = thatAnalogChannel.LevelTriggerType; } } catch { } //try { this.TriggerBelowThresholdEu = thatAnalogChannel.TriggerBelowThresholdEu; } //catch { /* no reviewable attributes to remove... yet */ } try { if (thatAnalogChannel.MeasuredExcitationVoltageValid) { MeasuredExcitationVoltage = thatAnalogChannel.MeasuredExcitationVoltage; } } catch { /* leave it uninitialized */ } try { if (thatAnalogChannel.FactoryExcitationVoltageValid) { FactoryExcitationVoltage = thatAnalogChannel.FactoryExcitationVoltage; } } catch { /* leave it uninitialized */ } //try { this.TimeOfFirstSampleSec = thatAnalogChannel.TimeOfFirstSampleSec; } //catch { /* leave it uninitialized */ } try { if (thatAnalogChannel.TimeOfFirstSampleValid) { TimeOfFirstSampleSec = thatAnalogChannel.TimeOfFirstSampleSec; } } catch { } CurrentFilter = SaeJ211Filter.Parse(thatAnalogChannel.SoftwareFilter); if (!AvailableFilters.Contains(CurrentFilter)) AvailableFilters.Add(CurrentFilter); MvPerEu = that.Data.MvPerEu; ScaleFactorMv = that.Data.ScaleFactorMv; if (thatAnalogChannel.PersistentChannelInfo == null) { UnfilteredData = thatAnalogChannel.TDASPersistentChannelInfo; } else { UnfilteredData = thatAnalogChannel.PersistentChannelInfo; // new List( that.Data.Values ); } FileName = thatAnalogChannel.FileName ?? string.Empty; //double windowAve = double.NaN; //Scaler.SetIRTraccZeros(windowAve, thatAnalogChannel.OriginalOffsetADC); } else { throw new ArgumentException("Can't initialize from a " + that.GetType().FullName + " object"); } } catch (System.Exception ex) { throw new Exception("encountered problem initializing from " + GetType().FullName + " to " + typeof(Serialization.Test.Module.Channel).FullName, ex); } } /// /// Generate a representation for this object. /// /// /// /// The representation of this object. /// /// public override string ToString() { try { return !string.IsNullOrEmpty(ChannelDescriptionString) ? ChannelDescriptionString : Description; } catch (System.Exception ex) { throw new Exception("encountered problem getting string representation", ex); } } /// /// Get the data range in EU. /// public override double DataRangeEu => Math.Abs(Scaler.GetEU(DataRangeAdc)); /// /// Get the data range/2 in EU. /// public override double DataHalfRangeValueEu => Scaler.GetEU(DataHalfRangeValueAdc); /// /// Get the data min in EU. /// public override double DataMinEu => (Scaler.GetAdcToEuScalingFactor() >= 0) ? Scaler.GetEU(DataMinAdc) : Scaler.GetEU(DataMaxAdc); /// /// Get the data max in EU. /// public override double DataMaxEu => (Scaler.GetAdcToEuScalingFactor() >= 0) ? Scaler.GetEU(DataMaxAdc) : Scaler.GetEU(DataMinAdc); /// /// Get the actual available maximum EU range based on scaling factor and bit resolution. /// public override double ActualMaxRangeEu { get { try { var min = Scaler.GetEU(ActualMinRangeAdc); var max = Scaler.GetEU(ActualMaxRangeAdc); if (double.IsNaN(min) || double.IsNaN(max)) { min = -150; max = 150; } else if (min > max) { var temp = min; min = max; max = temp; } if ((Scaler.GetAdcToEuScalingFactor() >= 0 || ((true == IsInverted) ^ (Sensitivity < 0)))) { return max; } return min; //return (Scaler.GetAdcToEuScalingFactor() >= 0) ? max : min; } catch (System.Exception ex) { throw new Exception("encountered problem calculating actual max EU range", ex); } } } /// /// Get the actual available minimum EU range based on scaling factor and bit resolution. /// public override double ActualMinRangeEu { get { try { var min = Scaler.GetEU(ActualMinRangeAdc); var max = Scaler.GetEU(ActualMaxRangeAdc); if (double.IsNaN(min) || double.IsNaN(max)) { min = -150; max = 150; } else if (min > max) { var temp = min; min = max; max = temp; } if ((Scaler.GetAdcToEuScalingFactor() >= 0 || ((true == IsInverted) ^ (Sensitivity < 0)))) { return min; } return max; //return (Scaler.GetAdcToEuScalingFactor() >= 0) ? min : max; } catch (System.Exception ex) { throw new Exception("encountered problem calculating actual min EU range", ex); } } } public void PersistentChannelUnset() { if (UnfilteredData is Serialization.SliceRaw.File.PersistentChannel) { (UnfilteredData as Serialization.SliceRaw.File.PersistentChannel).UnSet(); } else { //Viewing TDC data (UnfilteredData as Serialization.TDAS.File.PersistentChannel).UnSet(); } } public override List GetUnfilteredDataEu() { if (UnfilteredData is Serialization.SliceRaw.File.PersistentChannel) { using (var persistentUnfilteredData = UnfilteredData as Serialization.SliceRaw.File.PersistentChannel) { var dataCount = persistentUnfilteredData.Count; var Unfiltered_Data_Eu = new List(dataCount); for (var i = 0; i < dataCount; i++) { try { //Unfiltered_Data_Eu.Add(Scaler.GetEU(persistentUnfilteredData[i])); var temp = Scaler.GetEU(persistentUnfilteredData[i]); Unfiltered_Data_Eu.Add(temp); } catch (System.Exception ex) { APILogger.Log("problem getting SliceRAW unfiltered data ", ex); } } //persistentUnfilteredData.Dispose(); return Unfiltered_Data_Eu; } } using (var persistentUnfilteredData = UnfilteredData as Serialization.TDAS.File.PersistentChannel) { var dataCount = persistentUnfilteredData.Count; var Unfiltered_Data_Eu = new List(dataCount); for (var i = 0; i < dataCount; i++) { try { var temp = Scaler.GetEU(persistentUnfilteredData[i]); Unfiltered_Data_Eu.Add(temp); } catch (System.Exception ex) { APILogger.Log("problem getting TDAS unfiltered data ", ex); } } //persistentUnfilteredData.Dispose(); return Unfiltered_Data_Eu; } } public override List GetUnfilteredDataMV() { if (UnfilteredData is Serialization.SliceRaw.File.PersistentChannel) { using (var persistentUnfilteredData = UnfilteredData as Serialization.SliceRaw.File.PersistentChannel) { var dataCount = persistentUnfilteredData.Count; var Unfiltered_Data_MV = new List(dataCount); for (var i = 0; i < dataCount; i++) { try { //Unfiltered_Data_Eu.Add(Scaler.GetEU(persistentUnfilteredData[i])); var temp = Scaler.GetMv(persistentUnfilteredData[i]); Unfiltered_Data_MV.Add(temp); } catch (System.Exception ex) { APILogger.Log("problem getting SliceRAW unfiltered data ", ex); } } //persistentUnfilteredData.Dispose(); return Unfiltered_Data_MV; } } using (var persistentUnfilteredData = UnfilteredData as Serialization.TDAS.File.PersistentChannel) { var dataCount = persistentUnfilteredData.Count; var Unfiltered_Data_MV = new List(dataCount); for (var i = 0; i < dataCount; i++) { try { var temp = Scaler.GetMv(persistentUnfilteredData[i]); Unfiltered_Data_MV.Add(temp); } catch (System.Exception ex) { APILogger.Log("problem getting TDAS unfiltered data ", ex); } } //persistentUnfilteredData.Dispose(); return Unfiltered_Data_MV; } } public override double DesiredRangeEU => DesiredRange; public override double SensorCapacityEU => SensorCapacity; } } } }