05-21-2009 06:03 AM
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?
05-22-2009 10:41 AM
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
05-23-2009 01:55 AM
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
05-23-2009 11:37 AM
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
05-26-2009 06:41 PM
05-26-2009 11:53 PM
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
05-27-2009 12:57 AM
Imports NationalInstruments.DAQmx
Public Class Form1Inherits System.Windows.Forms.Form
Private myTask As TaskPrivate reader As AnalogMultiChannelReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton1.ClickTry
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 DaqExceptionMessageBox.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.LoadEnd Sub
Private Sub MainForm_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DisposedEnd 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
05-28-2009 03:17 PM
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.
05-29-2009 07:33 AM
'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 Form1Inherits System.Windows.Forms.Form
Private myTask As TaskPrivate reader As AnalogMultiChannelReader
Private counter As Short = 0Private outstr As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton1.ClickTry
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) & vbCrLfNext
TextBox1.Text = outstr
Catch exception As DaqExceptionMessageBox.Show(exception.Message)
Finally
myTask.Dispose()
End Try
End SubEnd Class
ALl the best jim
05-29-2009 07:37 AM
'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 Form1Inherits System.Windows.Forms.Form
Private myTask As TaskPrivate reader As AnalogMultiChannelReader
Private counter As Short = 0Private outstr As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton1.ClickTry
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 19outstr = outstr & data(counter, 0) & " " & data(counter, 1) & vbCrLf
Next
TextBox1.Text = outstr
Catch exception As DaqExceptionMessageBox.Show(exception.Message)
Finally
myTask.Dispose()
End Try
End SubEnd Class