Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

USB 6008:How do you measure 500 results of ai0 and ai1@500 samples per sec.

I am talking about the example to be found at C:\Documents and Settings\All Users\Shared documents\National Instruments\NI-DAQ\Examples\

specifically the example ContAcqVoltageSamples_IntClk.

1)the statement  analogInReader.BeginReadMultiSample(Convert to Int32(500),analogCallback,myTask)

appears in the Sub AnalogInCallback(By val...) and is also the 1st statement executed when the callback returns .That is it appears twice on pg7 of the example.

I don't Know why it appears this twice or what it does.?

2)the callback procedure contains the stmnt    data=analogInReader.EndReadMultiSAmple(ar)

                                                                       'plot your data here

would I recover the data by the routine

Dn=D(0)

D(n+1)=D(1)

n=n+1

IT seems as if the conversion is taking place once every time the AnalogInCallback is called?

0 Kudos
Message 1 of 15
(6,632 Views)

Hi Jeffrey,

 

From the title, it seems you are trying to do a finite aquisition. The example ContAcqVoltageSamples_IntClk reads a fixed number samples at a time (500 in your code), but it is a continuous aquisition, which is why the there are two BeginReadMultiSample statements in the code. The first statement makes the first aquisition, and second statement is executed after every AnalogInCallback, which is thown at the end of each aquisition of 500 samples. 

 

For a finite aquisition, a better example to look at would be the AcqVoltageSamples_IntClk example.

 

The BeginReadMultiSample returns an array of AnalogWaveform objects, and to extract a particular sample, you can use the syntax

waveform.Samples[N].Value, where waveform is the name you give to the AnalogWaveform object and N is the particular sample you are trying to extract.

 

-Abram

 

 

 

0 Kudos
Message 2 of 15
(6,609 Views)

yes thank you Abram

I'm using VB8 and I'm with AcqVoltageSamples_IntClk.

problem in reading or recovering the data in variables after Dim data As Double( , )=reader.ReadMultiSample(20).

Have decided for simplicity to only collect 20 samples from each of ai0 and ai1.

I expect the data to end up in a 20x2 matrix ; data(0) data(2) data(4) thru to data(38) in column 1 and the uneven numbers up to data(39) in column 2.

is this a real expectation.

remember I don't want to use a data table but I must be able to recover the data

thanks  a lot for your time and interest

regards jeff

0 Kudos
Message 3 of 15
(6,600 Views)

Dim samplesperchannumericval=New Decimal(New Integer() {20,0,0,0})

Dim sampsPerchann as Int32=Convert.ToInt32(samplesperchannumericval)

 

Dim data As Double(,)=reader.ReadMultiSample(sampsPerchann)

 

 

 

The last of these stmnts is holding things up

do i need this monstrocity or is there abetter way

 

 

regards and much thanks

jeff                                                                                                                                                                  Channyn

 

0 Kudos
Message 4 of 15
(6,584 Views)

Hi Jeff,

 

I just have a couple of questions:

 

1)  Where are you placing these new statements in your code?

2) What do you mean by holding up?  Are you getting an error or is the code not working properly?

3) What is the goal of these additions of code?

Regards,
Jim Schwartz
0 Kudos
Message 5 of 15
(6,552 Views)

hi jim,

I am putting the statament Dim data as double(,)=reader.ReadMultiSamples(20)

in the same place as the exampmle  and when I run it    this statement gets a yellow block and won't run

the reason for the other code is to recover the data in variables.

thenk you very much jim

       jd(<)=mm

jeff

0 Kudos
Message 6 of 15
(6,546 Views)

Imports NationalInstruments.DAQmx

Public Class Form1

Inherits System.Windows.Forms.Form

Private myTask As Task

Private reader As AnalogMultiChannelReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton1.Click

Try

myTask = New Task()

'Dim samplesperchannumericval = New Decimal(New Integer() {20, 0, 0, 0})

'Dim samplesPerChan As Int32 = Convert.ToInt32(samplesperchannumericval)

myTask.AIChannels.CreateVoltageChannel("Dev1/ai0:1", "", AITerminalConfiguration.Rse, Convert.ToDouble("-10"), Convert.ToDouble("10"), AIVoltageUnits.Volts)myTask.Timing.ConfigureSampleClock("", Convert.ToDouble("1000"), SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 20)

myTask.Control(TaskAction.Verify)

Dim data As Double(,) = reader.ReadMultiSample(20)

'here to capture data in variables

 Catch exception As DaqException

MessageBox.Show(exception.Message)

Finally

myTask.Dispose()

End Try

End Sub

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

 Private Sub MainForm_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed

End Sub

End Class

This is acopy of the code.

when i debug i get a yellow block around the stmnt " Dim data as double............................."

and the report NullReferenceException was unhandled

Object refrence not set to an instance of an object.

Thanks Jim

regards

jeff

0 Kudos
Message 7 of 15
(6,544 Views)

Hey Jeff,

 

After looking at your code, I think that you are not declaring 'reader.'   You have it defined correctly, then you are using it.  Somewhere in there, you have to declare the variable.The null reference exception error comes from using an undeclared variable. I have included a screenshot from the AcqVoltageSamples_IntClk example of the line that you have missed.

 

 

text screenshot.JPG

Regards,
Jim Schwartz
Message 8 of 15
(6,505 Views)

'Hi there Jim,

' Yes thanks ! a silly mistake rectified now 'still got problems recovering the data

'ha

'Have a look at what I try do in the programme below

'in debugging a yellow box on outsrt=outstr........................

'"Index was outside the bounds of the array"

'can't thus figure out how the data is structured or

'even if it goes by the name data no clue!

Imports NationalInstruments.DAQmx

Public Class Form1

Inherits System.Windows.Forms.Form

Private myTask As Task

Private reader As AnalogMultiChannelReader

Private counter As Short = 0

Private outstr As String

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton1.Click

Try

myTask = New Task()

myTask.AIChannels.CreateVoltageChannel("Dev1/ai0:1", "", AITerminalConfiguration.Rse, Convert.ToDouble("-10"), Convert.ToDouble("10"), AIVoltageUnits.Volts)myTask.Timing.ConfigureSampleClock(

"", Convert.ToDouble("1000"), SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 20)

myTask.Control(TaskAction.Verify)

reader =
New AnalogMultiChannelReader(myTask.Stream) Dim data As Double(,) = reader.ReadMultiSample(20)

' presuming that(,) leads to a data structure of a 20x2 matrix with elements data(0,0) data(0,1)

'data(1,0) data(1,1) all the way to the last 2 elements data(19,0) data (19,1)

 For counter = 0 To 19 outstr = outstr & data(counter, 0) & " " & data(counter, 1) & vbCrLf

Next

TextBox1.Text = outstr

Catch exception As DaqException

MessageBox.Show(exception.Message)

Finally

myTask.Dispose()

End Try

 End Sub

End Class

ALl the best jim

 

0 Kudos
Message 9 of 15
(6,491 Views)

'Hi there Jim,

' Yes thanks ! a silly mistake rectified now

'still got problems recovering the data

'ha

'Have a look at what I try do in the programme below

'in debugging a yellow box on outsrt=outstr........................

'"Index was outside the bounds of the array"

'can't thus figure out how the data is structured

Imports NationalInstruments.DAQmx

Public Class Form1

Inherits System.Windows.Forms.Form

Private myTask As Task

Private reader As AnalogMultiChannelReader

Private counter As Short = 0

Private outstr As String

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton1.Click

Try

myTask = New Task()

myTask.AIChannels.CreateVoltageChannel("Dev1/ai0:1", "", AITerminalConfiguration.Rse, Convert.ToDouble("-10"), Convert.ToDouble("10"), AIVoltageUnits.Volts)myTask.Timing.ConfigureSampleClock(

"", Convert.ToDouble("1000"), SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 20)

myTask.Control(TaskAction.Verify)

reader =
New AnalogMultiChannelReader(myTask.Stream)

Dim data As Double(,) = reader.ReadMultiSample(20)

' presuming that(,) leads to a data structure of a 20x2 matrix with elements data(0,0) data(0,1)

'data(1,0) data(1,1) all the way to the last 2 elements data(19,0) data (19,1)

 For counter = 0 To 19

outstr = outstr & data(counter, 0) & " " & data(counter, 1) & vbCrLf

Next

TextBox1.Text = outstr

Catch exception As DaqException

MessageBox.Show(exception.Message)

Finally

myTask.Dispose()

End Try

 End Sub

End Class

 

0 Kudos
Message 10 of 15
(6,490 Views)