Esempio n. 1
0
        //      public System.Collections.IEnumerable RecordIterator(ADIDataFlags dataFlags, int chan, ADIPosition pos)
        //      public IEnumerator<float> RecordIterator(ADIDataFlags dataFlags, int chan, ADIPosition pos)

        //Creates a object to enumerate samples in the record from left to right starting at position pos and ending at the sample before endOffset.
        //If the parameter endOffset is set to ADIPosition.kRecordEndOffset, the enumerator will continue to return samples until the last sample in the record is reached.
        public FloatIter RecordIterator(ADIDataFlags dataFlags, int chan, ADIPosition pos, int endOffset)
        {
            ADIScaling   scaling = new ADIScaling(1); //identity scaling
            IEnumFloatEx enumFloat;

            mADIData.GetEnumFloat(dataFlags, new ADIChannelId(chan), pos, endOffset, ref scaling, out enumFloat); //(ADIScaling*)IntPtr.Zero);
            return(new FloatIter(enumFloat));
        }
Esempio n. 2
0
        public static void ShowStats(ADIDataReader reader)
        {
            int nChannels = reader.NumberOfChannels;
            int nRecords  = reader.NumberOfRecords;

            Debug.Log("Number of records = " + nRecords);
            Debug.Log("Number of channels = " + nChannels);

            //loop over channels, displaying their names
            for (int chan = 0; chan < nChannels; ++chan)
            {
                Debug.Log("Channel " + (chan + 1) + " name is " + reader.ChannelName(chan));
            }

            for (int record = 0; record < nRecords; ++record)
            {
                //print the time and date of the first tick in the record, and of the origin of the record
                //(in case there is a pre or post trigger delay).
                DateTime startTime = reader.GetRecordStartTime(record);
                Debug.Log("Block start time:" + startTime + ", Block zero time:" + reader.GetRecordTriggerTime(record));

                //print the length of the record in ticks
                Debug.Log("Record " + (record + 1) + " is " + reader.GetRecordLength(record) + " ticks long.");

                //Output all the comments in the record (including all channels and AllChannel comments).
                //Start iterator at the beginning (i.e. record offset 0) of record rec.

/*            using (CommentIter comments = reader.CommentIterator(new ADIPosition(record, 0), ADIPosition.kRecordEndOffset))
 *             {
 *             foreach (IADIComment comment in comments)
 *                {
 *                int pos, chan, num;
 *                String text = comment.GetCommentInfo(out pos, out chan, out num).GetBStr();
 *                if(chan == -1)
 *                   Debug.Log("Comment " + num + ", All Channels: " + (chan+1) + " \"" + text + "\"");
 *                else
 *                   Debug.Log("Comment " + num + ", Chan " + (chan+1) + ": \"" + text + "\"");
 *
 *                //Get the value of the channel data at the comment if possible
 *                ADIDataFlags dataFlags = ADIDataFlags.kADIDataAtTickRate | ADIDataFlags.kADIDataScaleToPrefixedUnits;
 *                double value = reader.GetValue(dataFlags, chan, new ADIPosition(record, pos));
 *
 *                String unitsName = reader.UnitsName(chan, record, dataFlags);
 *                Debug.Log("Value at comment= " + value + " " + unitsName);
 *                }
 *             }
 */

                //Demonstrate using the reverse comment iterator and finding individual comments
                //Output 2nd last comment in channel 3

/*            ADIPosition rightPos = new ADIPosition(record, ADIPosition.kRecordEndOffset);
 *          int stopTick = 0; //Iterator can run right back to the start of the record
 *          using (CommentIter comments = reader.CommentIteratorReverse(EnumCommentFlags.kSearchSpecificChannelOnly,
 *             2, rightPos, stopTick))
 *             {
 *             int count = 0;
 *             foreach (IADIComment comment in comments)
 *                {
 *                int pos, chan, num;
 *                if (++count == 2)
 *                   {
 *                   String text = comment.GetCommentInfo(out pos, out chan, out num).GetBStr();
 *                   Debug.Log("2nd last comment in record: Comment " + num + " Chan " + (chan+1) + " \"" + text + "\"");
 *                   break;
 *                   }
 *                }
 *             //Alternative to foreach:
 *             //for(;comments.MoveNext();)
 *             //   {
 *             //   IADIComment comment = comments.Current;
 *             //   int pos, chan, num;
 *             //   String text = comment.GetCommentInfo(out pos, out chan, out num).GetBStr();
 *             //   Debug.Log("2nd last Comment " + num + " Chan " + chan + " \"" + text + "\"");
 *             //   }
 *             }
 */

                //Find the right-most comment in this record.
                IADIComment rightMostComment = reader.RightMostCommentInRange(EnumCommentFlags.kSearchAnyChannel,
                                                                              new ADIPosition(record, 0), new ADIPosition(record, ADIPosition.kRecordEndOffset), 0);
                if (rightMostComment != null)
                {
                    int    pos, chan, num;
                    String text = rightMostComment.GetCommentInfo(out pos, out chan, out num).GetBStr();

                    Debug.Log("Right-most in record: Comment " + num + " Chan " + (chan + 1) + " \"" + text + "\"");
                }


                for (int channel = 0; channel < nChannels; ++channel)
                {
                    //Specify that we want data at the raw sample rate of the channel (not the tick rate), in prefixed units such as mV (rather than V, say).
                    ADIDataFlags dataFlags = ADIDataFlags.kADIDataAtSampleRate | ADIDataFlags.kADIDataScaleToPrefixedUnits;

                    int    samplesInRecord = reader.GetNumSamplesInRecord(dataFlags, channel, record);
                    double samplePeriod    = reader.GetSecsPerSample(dataFlags, channel, record);
                    Debug.Log("Channel " + (channel + 1) + ", record " + record + " contains " + samplesInRecord + " samples with a sample period of " + samplePeriod + " s.");

                    //Demonstrate that records can start part-way through a sample in multi-rate files
                    TTickToSample tickToSample      = reader.ADIData.GetTickToSample(dataFlags, new ADIChannelId(channel), record);
                    double        samplePosInRecord = tickToSample.TickToSample(0);
                    if (samplePosInRecord != 0.0)
                    {
                        Debug.Log("First tick in channel has sample position " + samplePosInRecord + ".");
                        Debug.Log("I.e. the record  starts " + (samplePosInRecord * 100.0) + " percent through the time period of the 1st sample in this channel.");
                    }
                    Debug.Log("Last sample in channel starts at tick " + tickToSample.SampleToTick(samplesInRecord));

                    //Print the units for the channel and record
                    String channelName = reader.ChannelName(channel);
                    String unitsName   = reader.UnitsName(channel, record, dataFlags);
                    Debug.Log(channelName + " units [" + unitsName + ']');

                    //Process the samples in the channel and record
                    using (FloatIter iter = reader.RecordIterator(dataFlags, channel, new ADIPosition(record, 0), ADIPosition.kRecordEndOffset))
                    {
                        double sum     = 0.0;
                        int    samples = 0;
                        double minVal  = double.MaxValue;
                        double maxVal  = double.MinValue;
                        foreach (float val in iter)
                        {
                            sum += val;
                            samples++;
                            if (val > maxVal)
                            {
                                maxVal = val;
                            }
                            if (val < minVal)
                            {
                                minVal = val;
                            }
                        }
                        int samplePos = iter.GetPosition();
                        if (samplePos > 0)
                        {
                            if (samplePos != samples)
                            {
                                throw new Exception("Unexpected mismatch: iter.GetPosition() error");
                            }

                            double mean = sum / samplePos; //samplePos should equal the number of samples since it started at 0.
                            Debug.Log("Channel " + (channel + 1) + ", record " + (record + 1) + " : sum=" + sum + ",samples=" + samples +
                                      ", mean= " + mean + " " + unitsName + ", max= " + maxVal + " " + unitsName + ", min= " + minVal + " " + unitsName);
                        }
                        else
                        {
                            Debug.Log("Channel " + (channel + 1) + ", record " + (record + 1) + " has no data");
                        }
                    }

                    //Example demonstrating driving iterator backwards
                    using (FloatIter iter = reader.RecordIterator(dataFlags, channel, new ADIPosition(record, samplesInRecord), ADIPosition.kRecordEndOffset))
                    {
                        double sum     = 0.0;
                        int    samples = 0;
                        for (; iter.MovePrev();)
                        {
                            sum += iter.Current;
                            samples++;
                        }
                        Debug.Log("Reverse sum=" + sum + ", samples = " + samples);
                    }
                }
            }
        }
Esempio n. 3
0
        //Returns a single data value. This not an efficient way to access ranges of samples, for which
        //RecordIterator() should be used.
        //If the specified channel and record is empty the value returned will be
        //a nan (0x7ff8700000000000LL). If pos.mRecordOffset is beyond the end of the specified record an exception
        //(E_INVALIDARG) will be thrown.
        public double GetValue(ADIDataFlags dataFlags, int chan, ADIPosition pos)
        {
            ADIScaling scaling = new ADIScaling(1);                                             //identity scaling

            return(mADIData.GetValDouble(dataFlags, new ADIChannelId(chan), pos, ref scaling)); //(ADIScaling*)IntPtr.Zero);
        }
Esempio n. 4
0
        public String UnitsName(int chan, int rec, ADIDataFlags scalingType)
        {
            IAutoADIString adiStr = mADIData.GetUnitsName(scalingType, new ADIChannelId(chan), rec);

            return(adiStr != null?adiStr.GetBStr() : "");
        }
Esempio n. 5
0
 /// <summary>
 /// Returns a TTickToSample struct containing the linear transform mapping a tick within a record to a sample
 /// within that record and specified channel.
 /// This linear transform will be the identity transform unless the file contains multirate data.
 /// </summary>
 /// <param name="dataFlags"> This parameter is currently ignored.</param>
 /// <param name="channel">channel index (0 based)</param>
 /// <param name="rec">record index (0 based)</param>
 /// <returns>TTickToSample value type containing linear transform</returns>
 public TTickToSample GetTickToSample(ADIDataFlags dataFlags, ADIChannelId channel, int rec)
 {
     return(GetTickToSample(dataFlags, channel, rec));
 }
Esempio n. 6
0
 /// <summary>
 /// Returns the period in seconds of the samples in the specified channel for the specified record
 /// </summary>
 /// <param name="dataFlags">Specifies the type of data to return information about (tick rate vs sample rate)</param>
 /// <param name="chan">channel index (0 based)</param>
 /// <param name="rec">record index (0 based)</param>
 /// <returns>period in seconds</returns>
 public double GetSecsPerSample(ADIDataFlags dataFlags, int chan, int rec)
 {
     return(mADIData.GetSecsPerSample(ADIDataFlags.kADIDataAtSampleRate, new ADIChannelId(chan), rec));
 }
Esempio n. 7
0
 //If dataFlags does not have kADIDataAtTickRate set (i.e. kADIDataAtSampleRate), returns the actual number of recorded samples in this record and channel.
 //If dataFlags has kADIDataAtTickRate set, returns the number of recorded samples transformed into ticks, which may not agree with the number of ticks returned by GetRecordLength().
 public int GetNumSamplesInRecord(ADIDataFlags dataFlags, int chan, int rec)
 {
     return(mADIData.GetNumSamplesInRecord(dataFlags, new ADIChannelId(chan), rec));
 }