High-Speed Digitizers

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get AnalogWaveform from AnalogWaveformCollection in C#.NET?

Solved!
Go to solution

Hi there,

I have a VS2008 C#.NET application based on NI examples that is continously streaming an AnalogWaveformCollection to file (hooray!) from both channels of my USB 5132 .   Now I want to read the file back in and look at the voltages.  My question is:  If I am reading in the file as 

AnalogWaveformCollection<int>[] records = binaryFormatter.Deserialize(fileStream) as AnalogWaveformCollection<int>[];

 how can I access the AnalogWaveform part of the AnalogWaveformCollection structure?  I want to send the AnalogWaveforms to the NI routine PlotRecords() as in

        private AnalogWaveform<double>[] ScaleRecords(AnalogWaveform<int>[] records)
        {
          
            AnalogWaveform<double>[] scaledRecords = new AnalogWaveform<double>[records.Length];
            for (int i = 0; i < records.Length; ++i)
            {
                scaledRecords[i] = AnalogWaveform<double>.FromArray1D(records[i].GetScaledData());
            }

            return scaledRecords;
        }

 

I have looked at the definition of AnalogWaveformCollection, below, but do not understand how to unpack any of its components.  Any thoughts would be appreciated.  Even one example of one component would help.

 

Thanks,

Penny

 

namespace NationalInstruments
{
    // Summary:
    //     Represents a strongly typed collection of AnalogWaveform<T> objects.
    //
    // Type parameters:
    //   TData:
    //     The underlying type of the waveforms. The following data types are supported
    //     by TData (generic type parameter): Byte, SByte, Decimal, Single, Double,
    //     Int16, UInt16, Int32, UInt32, Int64, and UInt64.
    [Serializable]
    public sealed class AnalogWaveformCollection<TData> : IServiceProvider, ICollection, IEnumerable, ICloneable, ISerializable
    {
        // Summary:
        //     Initializes a new instance of AnalogWaveformCollection<T>.
        public AnalogWaveformCollection();

        // Summary:
        //     Gets the number of channels in AnalogWaveformCollection<T>.
        public int Channels { get; }
        //
        // Summary:
        //     Gets the number of analog waveforms in AnalogWaveformCollection<T>.
        public int Count { get; }
        public bool IsSynchronized { get; }
        //
        // Summary:
        //     Gets the number of records in AnalogWaveformCollection<T>.
        public int Records { get; }
        public object SyncRoot { get; }

        // Summary:
        //     Gets the AnalogWaveform<T> at the specified index.
        //
        // Parameters:
        //   index:
        //     The zero-based index of the AnalogWaveform<T> to locate in the collection.
        //      Valid values range from zero to Count - 1.
        //
        // Exceptions:
        //   System.ArgumentOutOfRangeException:
        //     index (parameter) is less than zero.  -or- index (parameter) is greater than
        //     or equal to Count.  -or- index (parameter) is greater than or equal to Count.
        public AnalogWaveform<TData> this[int index] { get; }
        //
        // Summary:
        //     Gets the AnalogWaveform<T> at the specified indexes.
        //
        // Parameters:
        //   recordIndex:
        //     The zero-based record index of the AnalogWaveform<T> to locate in the collection.
        //      Valid values range from zero to Records - 1.
        //
        //   channelIndex:
        //     The zero-based channel index of the AnalogWaveform<T> to locate in the collection.
        //      Valid values range from zero to Channels - 1.
        //
        // Exceptions:
        //   System.IndexOutOfRangeException:
        //     recordIndex (parameter) or channelIndex (parameter) is less than zero.  -or-
        //     recordIndex (parameter) is greater than or equal to Records.  -or- channelIndex
        //     (parameter) is greater than or equal to Channels.  -or- recordIndex (parameter)
        //     is greater than or equal to Records.  -or- channelIndex (parameter) is greater
        //     than or equal to Channels.
        public AnalogWaveform<TData> this[int recordIndex, int channelIndex] { get; }

        // Summary:
        //     Creates a new object that is a deep copy of this instance.
        //
        // Returns:
        //     A new object that is a deep copy of this instance.
        public AnalogWaveformCollection<TData> Clone();
        //
        // Summary:
        //     Copies the collection to an array or a portion of an array.
        //
        // Parameters:
        //   array:
        //     Destination array for the collection.
        //
        //   index:
        //     The index in the target array at which you want to begin copying the collection
        //     to.
        //
        // Exceptions:
        //   System.ArgumentNullException:
        //     array (parameter) is null.
        //
        //   System.ArgumentException:
        //     index (parameter) is equal to or greater than the length of array (parameter).
        //      -or- The number of elements in the collection is greater than the available
        //     space between index (parameter) and the end of array (parameter).
        //
        //   System.ArgumentOutOfRangeException:
        //     index (parameter) is less than the lower bound of array (parameter).
        public void CopyTo(AnalogWaveform<TData>[] array, int index);
        //
        // Summary:
        //     Returns an enumerator that you can use to iterate through the collection.
        //
        // Returns:
        //     The enumerator for the collection.
        public IEnumerator GetEnumerator();
    }
}

 

0 Kudos
Message 1 of 2
(6,365 Views)
Solution
Accepted by topic author Penny

Hi,

All set.  Figured it out by looking at the C# example ConfiguredAcquisition. 

Thanks,

Penny

 

0 Kudos
Message 2 of 2
(6,355 Views)