Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding GetPrecisionTimeStamps

I think I don't understand GetPrecisionTimeStamps.

 

I'm doing typical analog "waveform" acquisition. I have:

 

    Private AnalogInData As AnalogWaveform(Of Double)()

 I do the acquisition with BeginReadWaveform, and in my callback, I have

 

AnalogInData = AnalogInReader.EndReadWaveform(AnalogInAsyncResult)

To get the timestamps, I do 

 

               Dim TimeStamps As NationalInstruments.PrecisionDateTime()
                TimeStamps = AnalogInData(0).GetPrecisionTimeStamps

 It's strange to have to get the array of time stamps from the first element in the array, but I guess that's a byproduct of it being an array (rather than a custom class that contains the array inside). Anyway, I noticed that something in the call to GetPrecisionTimeStamps throws an overflow exception about once per second:

 

A first chance exception of type 'System.OverflowException' occurred in NationalInstruments.Common.dll

 In the documentation for GetPrecisionTimeStamps I see:

 

If the timing information in AnalogWaveform<(Of <(TData>)>) was set using PrecisionTiming, then this method will return time stamps with the precision of PrecisionDateTime. If the timing information was set using Timing, the time stamps returned will only be as precise as DateTime

 

As a test, I saw that the result of 

 

                AnalogInData(0).IsPrecisionTimingInitialized

 is false. Looking into PrecisionTiming, it expects me to "create" the precision time span... I think I'm heading in the wrong direction.

 

Since I'm not actually creating AnalogInData, I'm apparently not the one responsible for setting up PrecisionTiming. So how is this done, and is this exception that I see a result of the fact that precision timing is not "turned on"?

 

As usual, NI's documentation policy of "expanding function names into complete sentences" is no help. I evidently don't understand the concept of time stamps here.

 

0 Kudos
Message 1 of 4
(4,628 Views)

Hey Pelesl,

To use the GetPrecisionTimeStamps function you have to do a few steps to set up your waveform data:

 

1) You need a PrecisionDateTime variable array

2) Set your PrecisionTimeSpan

3) Enable PrecisionWaveformTiming with the desired constructor

 

Example:

Dim times(<number of Samples>) As PrecisionDateTime 

Dim timeInterval As PrecisionTimeSpan = New PrecisionTimeSpan(<Interval Rate>) //generally your sample rate
myWaveform.PrecisionTiming = PrecisionWaveformTiming.CreateWithRegularInterval(timeInterval, PrecisionDateTime.FromDateTime(myWaveform.Timing.StartTime))// <--Timing.StartTime is your reference start time from your first Sample

times = myWaveform.GetPrecisionTimeStamps()

 

 

This is by far not the only way, you can look at the Start » Programs » National Instruments »  Measurement Studio » Measurement Studio Documentation to view the Help for each one of these functions if you want to reduce the number of parameters you have to send to each function. 

Hope this Helps

BeauH
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(4,614 Views)

But I still get values from GetPrecisionTimeStamps.

 

I don't understand why I have to set things up like the interval and start time. How can the NI library not know what this is already, given that I already set up the timing with a given sample rate and asked acquisition to start.

 

Also, when am I supposed to do the code you posted? I don't allocate the waveform array; it gets done by EndReadWaveform, so only after I've received data via the callback. How is this timing "accurate" if I have to set up the start time and interval after I've already received data?

0 Kudos
Message 3 of 4
(4,611 Views)

Hey Pelesl,

You would use the above code after your analogInReader.EndReadWaveform() the reason is that analogInReader sets the size of the waveform data array

so prior to that call you will get an exception thrown that the "object" is not initialized if you try to call one index one of the data array elements.

 

What is happening is precisionTiming is not on by default because it requires a lot of overhead and can really reduce the performance of your application. So when you initially set up the timing and sample rate it is for the Timing object parameters. Therefore when you enable precisionTiming object you have to reset up those parameters. This is a postprocessing application, in the example above. So what is happening is you have your waveform data and you are replacing the Timestamp information with a more precise Timestamp based on the parameters sent.

 

 

BeauH
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(4,603 Views)