/* Test.Module.Channel.cs Copyright © 2008 Diversified Technical Systems, Inc. All Rights Reserved */ using System; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using DTS.Common.Utilities; using DTS.Common.Utilities.DotNetProgrammingConstructs; 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 serializable channel information. /// [XmlSerializationTag("Channel")] public abstract partial class Channel : Exceptional, IXmlSerializable { protected Channel() { } public Channel(Module parentModule) { try { ParentModule = parentModule; } catch (System.Exception ex) { throw new Exception("encountered problem constructing " + GetType().Name, ex); } } /// /// The that contains this channel. /// public Module ParentModule { get => _ParentModule.Value; private set => _ParentModule.Value = value; } private readonly Property _ParentModule = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.ParentModule", null, false ); /// /// Get/set the channel's ordinal number. /// [XmlSerializationTag("Number")] public int Number { get => _Number.Value; set => _Number.Value = value; } private readonly Property _Number = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.Number", -1, false ); /// /// get/set the absolute display order of the channel (absolutenumber refers to physical number) /// [XmlSerializationTag("AbsoluteDisplayOrder")] public int AbsoluteDisplayOrder { get { if (_absoluteDisplayOrder.IsValueInitialized) { return _absoluteDisplayOrder.Value; } return -1; } set => _absoluteDisplayOrder.Value = value; } private readonly Property _absoluteDisplayOrder = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.AbsoluteDisplayOrder", -1, true); /// /// Get/set the start time for this channel. /// [XmlSerializationTag("Start")] public DateTime Start { get => _Start.Value; set => _Start.Value = value; } private readonly Property _Start = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.Start", DateTime.Now, false ); public bool TimeOfFirstSampleValid => _TimeOfFirstSampleSec.IsInitialized; /// /// Get/set the time of first sample in this test. /// [XmlSerializationTag("TimeOfFirstSample")] public double TimeOfFirstSampleSec { get => _TimeOfFirstSampleSec.Value; set => _TimeOfFirstSampleSec.Value = value; } protected Property _TimeOfFirstSampleSec = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.TimeOfFirstSample", 0.0, false ); /// /// Get the type of this channel. /// [XmlSerializationTag("ChannelType")] public string ChannelType { get { try { return GetType().FullName; } catch (System.Exception ex) { throw new Exception("encountered problem getting channel type property", ex); } } } /// /// Get/set flag that determines whether or not data will be written to/read from XML serialization. /// public bool ExpressDataInlineOnXmlSerialization { get => _ExpressDataInlineOnXmlSerialization.Value; set => _ExpressDataInlineOnXmlSerialization.Value = value; } private readonly Property _ExpressDataInlineOnXmlSerialization = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.ExpressDataInlineOnXmlSerialization", false, true ); /// /// Get/set a user-readable description of this channel object. /// [XmlSerializationTag("ChannelDescriptionString")] public string ChannelDescriptionString { get => _ChannelDescriptionString.Value; set => _ChannelDescriptionString.Value = value; } private readonly Property _ChannelDescriptionString = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.ChannelDescriptionString", "", false ); [XmlSerializationTag("HardwareChannelName")] public string HardwareChannelName { get => _HardwareChannelName.Value; set => _HardwareChannelName.Value = value; } private readonly Property _HardwareChannelName = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.HardwareChannelName", "", true); /// /// refers to a unique id for a logical channel in the test /// for now this is using TestObjectChannel.GetId() /// which is in the form of TestObjectSerial_ChannelType_ChannelId /// [XmlSerializationTag("ChannelId")] public string ChannelId { //get { return _ChannelId.Value; } get { if (!_ChannelId.IsInitialized || null == _ChannelId.Value) { return $"{HardwareChannelName}_{ChannelName2}"; } return _ChannelId.Value; } set => _ChannelId.Value = value; } private readonly Property _ChannelId = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.ChannelId", "", true); /// /// refers to the Group name for a logical channel in the test /// [XmlSerializationTag("ChannelGroupName")] public string ChannelGroupName { get => _ChannelGroupName.Value; set => _ChannelGroupName.Value = value; } private readonly Property _ChannelGroupName = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.ChannelGroupName", "", true); /// /// This is the name of the channel before it was changed in the Display Name UI (if it was) /// [XmlSerializationTag("OriginalChannelName")] public string OriginalChannelName { get => _OriginalChannelName.Value; set => _OriginalChannelName.Value = value; } private readonly Property _OriginalChannelName = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.OriginalChannelName", "", true); [XmlSerializationTag("ChannelName2")] public string ChannelName2 { get => _ChannelName2.Value; set => _ChannelName2.Value = value; } private readonly Property _ChannelName2 = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.ChannelName2", "", true); /// /// Get/set the data values for this channel. /// [XmlSerializationTag("Data")] public DataArray Data { get => _Data.Value; set => _Data.Value = value; } private readonly Property> _Data = new Property>( typeof(Channel).Namespace + ".Test.Module.Channel.Data", null, false ); /// /// Get/set the subsampling indication for this channel's data. /// [XmlSerializationTag("IsSubsampled")] public bool IsSubsampled { get => _IsSubsampled.Value; set => _IsSubsampled.Value = value; } private readonly Property _IsSubsampled = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.IsSubsampled", false, true ); /// /// Get/set whether or not to use EU for scaling. /// [XmlSerializationTag("UseEUScaler")] public bool UseEUScaler { get => _UseEUScaler.Value; set => _UseEUScaler.Value = value; } private readonly Property _UseEUScaler = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.UseEUScaler", false, true ); [XmlSerializationTag("LastCalibrationDate")] public DateTime LastCalibrationDate { get => _lastCalibrationDate.Value; set => _lastCalibrationDate.Value = value; } private readonly Property _lastCalibrationDate = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.LastCalibrationDate", DateTime.MinValue, true ); public bool IsLastCalibrationDateValid => _lastCalibrationDate.IsInitialized; [XmlSerializationTag("CalDueDate")] public DateTime CalDueDate { get => _calDueDate.Value; set => _calDueDate.Value = value; } private readonly Property _calDueDate = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.CalDueDate", DateTime.MinValue, true ); public bool IsCalDueDateValid => _calDueDate.IsInitialized; [XmlSerializationTag("IsoChannelName")] public String IsoChannelName { get => _isoChannelName.Value; set => _isoChannelName.Value = value; } private readonly Property _isoChannelName = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.IsoChannelName", "", true ); public bool IsIsoChannelNameValid => _isoChannelName.IsInitialized; [XmlSerializationTag("UserChannelName")] public String UserChannelName { get => _userChannelName.Value; set => _userChannelName.Value = value; } private readonly Property _userChannelName = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.UserChannelName", "", true ); public string LinearSensorCalibration { get => _linearSensorCalibration.Value; set => _linearSensorCalibration.Value = value; } private readonly Property _linearSensorCalibration = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.LinearSensorCalibration", "", true ); public bool IsUserChannelNameValid => _userChannelName.IsInitialized; [XmlSerializationTag("UserCode")] public String UserCode { get => _userCode.Value; set => _userCode.Value = value; } private readonly Property _userCode = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.UserCode", "", true ); public bool IsUserCodeValid => _userCode.IsInitialized; [XmlSerializationTag("SensorID")] public string SensorID { get => _sensorID.Value; set => _sensorID.Value = value; } private readonly Property _sensorID = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.SensorID", "", true ); public bool IsSensorIDValid => _sensorID.IsInitialized; [XmlSerializationTag("OffsetToleranceLowMv")] public double OffsetToleranceLowMv { get => _offsetToleranceLowMv.Value; set => _offsetToleranceLowMv.Value = value; } private readonly Property _offsetToleranceLowMv = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.OffsetToleranceLowMv", 0D, true ); public bool IsOffsetToleranceLowMvValid => _offsetToleranceLowMv.IsInitialized; [XmlSerializationTag("OffsetToleranceHighMv")] public double OffsetToleranceHighMv { get => _offsetToleranceHighMv.Value; set => _offsetToleranceHighMv.Value = value; } private readonly Property _offsetToleranceHighMv = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.OffsetToleranceHighMv", 0D, true ); public bool IsOffsetToleranceHighMvValid => _offsetToleranceHighMv.IsInitialized; [XmlSerializationTag("UserValue1")] public string UserValue1 { get => _userValue1.Value; set => _userValue1.Value = value; } private readonly Property _userValue1 = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.UserValue1", "", true); [XmlSerializationTag("UserValue2")] public string UserValue2 { get => _userValue2.Value; set => _userValue2.Value = value; } private readonly Property _userValue2 = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.UserValue2", "", true); [XmlSerializationTag("UserValue3")] public string UserValue3 { get => _userValue3.Value; set => _userValue3.Value = value; } private readonly Property _userValue3 = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.UserValue3", "", true); /// /// the electronic id for a channel at test setup time /// [XmlSerializationTag("SetupEID")] public string SetupEID { get => _SetupEID.Value ?? string.Empty; set => _SetupEID.Value = value; } private readonly Property _SetupEID = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.SetupEID", string.Empty, true); /// /// the electronic id on a channel at run time /// [XmlSerializationTag("DataCollectionEID")] public string DataCollectionEID { get => _DataCollectionEID.Value ?? string.Empty; set => _DataCollectionEID.Value = value; } private readonly Property _DataCollectionEID = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.DataCollectionEID", string.Empty, true); /// /// Get/set the unsubsampled sample rate for this channel (if applicable). /// [XmlSerializationTag("UnsubsampledSampleRateHz")] public float UnsubsampledSampleRateHz { get => _UnsubsampledSampleRateHz.Value; set => _UnsubsampledSampleRateHz.Value = value; } private readonly Property _UnsubsampledSampleRateHz = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.UnsubsampledSampleRateHz", 0, true ); /// /// Get/set noise as percentage of full scale value for this channel. /// public double NoiseAsPercentageOfFullScale { get => _NoiseAsPercentageOfFullScale.Value; set => _NoiseAsPercentageOfFullScale.Value = value; } private readonly Property _NoiseAsPercentageOfFullScale = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.NoiseAsPercentageOfFullScale", 0.0, false ); /// /// Get the pre-test zero level (in ADC). /// public short PreTestZeroLevelAdc { get => _PreTestZeroLevelAdc.Value; set => _PreTestZeroLevelAdc.Value = value; } private readonly Property _PreTestZeroLevelAdc = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.PreTestZeroLevelAdc", 0, false ); //zeroMvInADC public short ZeroMvInADC { get { if (_ZeroMvInADC.IsValueInitialized) { return _ZeroMvInADC.Value; } return 0; } set => _ZeroMvInADC.Value = value; } private readonly Property _ZeroMvInADC = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.ZeroMvInADC", 0, false); /// /// WindowAverageADC is the average ADC over the averaging zero window for the channel /// WindowAverageADC is initialized to short.MinValue, so this value is considered /// an uninitialized or invalid value /// public short WindowAverageADC { get { if (_WindowAverageADC.IsValueInitialized) { return _WindowAverageADC.Value; } return short.MinValue; } set => _WindowAverageADC.Value = value; } private readonly Property _WindowAverageADC = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.WindowAverageADC", short.MinValue, false); public int TriggerAdjustmentSamples { get => _TriggerAdjustmentSamples.Value; set => _TriggerAdjustmentSamples.Value = value; } private readonly Property _TriggerAdjustmentSamples = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.TriggerAdjustmentSamples", 0, false); public short OriginalOffsetADC { get => _OriginalOffsetADC.Value; set => _OriginalOffsetADC.Value = value; } private readonly Property _OriginalOffsetADC = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.OriginalOffsetADC", 0, false); public double Excitation { get => _Excitation.Value; set => _Excitation.Value = value; } private readonly Property _Excitation = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.Excitation", 5D, false); public int RemovedADC { get { if (_RemovedADC.IsValueInitialized) { return _RemovedADC.Value; } return 0; } set => _RemovedADC.Value = value; } private readonly Property _RemovedADC = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.RemovedADC", 0, true ); public int RemovedInternalADC { get { if (_RemovedInternalADC.IsValueInitialized) { return _RemovedInternalADC.Value; } return 0; } set => _RemovedInternalADC.Value = value; } private readonly Property _RemovedInternalADC = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.RemovedInternalADC", 0, true ); /// /// Get/set the sample rate for this test module. /// [XmlSerializationTag("IsSupersampled")] public bool IsSupersampled { get => _IsSupersampled.Value; set => _IsSupersampled.Value = value; } private readonly Property _IsSupersampled = new Property( typeof(Module).Namespace + ".Test.Module.Channel.IsSupersampled", false, false ); /// /// Get/set the EU Scale Factor. /// [XmlSerializationTag("ScaleFactorEU")] public double ScaleFactorEU { get => _ScaleFactorEU.Value; set => _ScaleFactorEU.Value = value; } private readonly Property _ScaleFactorEU = new Property( typeof(Module).Namespace + ".Test.Module.Channel.ScaleFactorEU", 0D, false ); /// /// Get/set the sample rate for this test module. /// [XmlSerializationTag("UnsupersampledSampleRateHz")] public float UnsupersampledSampleRateHz { get => _UnsupersampledSampleRateHz.Value; set => _UnsupersampledSampleRateHz.Value = value; } private readonly Property _UnsupersampledSampleRateHz = new Property( typeof(Module).Namespace + ".Test.Module.Channel.UnsupersampledSampleRateHz", 0, false ); /// /// Get data zero level counts. /// public abstract short DataZeroLevelAdc { get; } /// /// Get/set the persistent information for this channel. /// public SliceRaw.File.PersistentChannel PersistentChannelInfo { get => _PersistentChannelInfo.Value; set => _PersistentChannelInfo.Value = value; } private readonly Property _PersistentChannelInfo = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.PersistentChannelInfo", null, false ); /// /// Get/set the persistent information for this channel. /// public TDAS.File.PersistentChannel TDASPersistentChannelInfo { get => _TDASPersistentChannelInfo.Value; set => _TDASPersistentChannelInfo.Value = value; } private readonly Property _TDASPersistentChannelInfo = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.TDASPersistentChannelInfo", null, false ); [XmlSerializationTag("DataFlag")] public int DataFlag { get => _DataFlag.Value; set => _DataFlag.Value = value; } private readonly Property _DataFlag = new Property( typeof(Channel).Namespace + ".Test.Module.Channel.DataFlag", 1, true); public bool IsDataFlagValid => _DataFlag.IsInitialized; //public DTS.Slice.Control.Event.Module.Channel emc; public object emc; /// /// Write XML serialization for this object to the specified writer. /// /// /// /// The to which this object's XML serialization /// will be written. /// /// public abstract void WriteXml(XmlWriter writer); /// /// Read XML serialization for this object from the specified reader. /// /// /// /// The from which this object's XML serialization /// will be read. /// /// public abstract void ReadXml(XmlReader reader); /// /// Should normally return a schema representing the form of the XML /// generated/consumed by WriteXml/ReadXml, but it never called during /// the serialization process so ours just returns null. /// /// /// /// Null reference, always. /// /// public virtual XmlSchema GetSchema() { // This method is never invoked during XML object serialization. return null; } /// /// 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 Channel; return null != obj && ChannelId.Equals(that.ChannelId) && Data.Equals(that.Data) && ExpressDataInlineOnXmlSerialization.Equals(that.ExpressDataInlineOnXmlSerialization) && Number.Equals(that.Number) && PreTestZeroLevelAdc.Equals(that.PreTestZeroLevelAdc) && NoiseAsPercentageOfFullScale.Equals(that.NoiseAsPercentageOfFullScale) && IsSubsampled.Equals(that.IsSubsampled) && UnsubsampledSampleRateHz.Equals(that.UnsubsampledSampleRateHz) && IsSupersampled.Equals(that.IsSupersampled) && UnsupersampledSampleRateHz.Equals(that.UnsupersampledSampleRateHz) && _TimeOfFirstSampleSec.IsInitialized == that._TimeOfFirstSampleSec.IsInitialized && (_TimeOfFirstSampleSec.IsInitialized ? TimeOfFirstSampleSec == that.TimeOfFirstSampleSec : true) && Start.ToString().Equals(that.Start.ToString()) && UserValue1.Equals(that.UserValue1) && UserValue2.Equals(that.UserValue2) && UserValue3.Equals(that.UserValue3) && AbsoluteDisplayOrder.Equals(that.AbsoluteDisplayOrder) && 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(); } public override string ToString() { return ChannelDescriptionString; } } } } }