Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

continuous sample acquisition with multiple channels

Solved!
Go to solution

Hi! please tell me what I'm doing wrong here, I'm confused about how to do continuous sample acquisition with multiple channels (using NI USB-6215).

following code is python code but I'm sure that won't confuse you 🙂 (and it's only one part of my code so don't try it, it won't work 😉 

 

buffer_size = 2000 #samples to read
sampling_rate_hz = 20000
channels = "Dev1/ai0,Dev1/ai1" #this can be one channel or many...

CHK(nidaq.DAQmxCreateTask("",ctypes.byref(taskHandle)))

 

CHK(nidaq.DAQmxCreateAIVoltageChan(taskHandle,channels,"",DAQmx_Val_Cfg_Default,float64(-10.0),float64(10.0),DAQmx_Val_Volts,None))

 

CHK(nidaq.DAQmxCfgSampClkTiming(taskHandle,"",float64(sampling_rate_hz),DAQmx_Val_Rising,DAQmx_Val_ContSamps,uInt64(buffer_size)))

CHK(nidaq.DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,uInt32(1000),uInt32(0),EveryNCallback_func,None))

CHK(nidaq.DAQmxRegisterDoneEvent(taskHandle,uInt32(0),DoneCallback_func,None))

#and the callback function

def py_EveryNCallback_func(self, taskHandle, event_type, nSamples):
   data = numpy.zeros((self.channel_amount,buffer_size,),dtype=numpy.float64)
   read = int32()
   CHK(nidaq.DAQmxReadAnalogF64(taskHandle,buffer_size,float64(10.0),DAQmx_Val_GroupByScanNumber,data.ctypes.data,buffer_size*number_of_channels,ctypes.byref(read),None))
 

 

With one channel everything goes fine, and voltage chart looks like this:

 buffer_size = 2000 , sampling_rate_hz = 20000 

 

But if I use two channels, voltage chart looks like this

buffer_size = 2000, sampling_rate_hz = 20000

it looks like the sampling rate is higher or there is less values?!?, but with two channels the array with results is 2000*2 long and with one result it is 2000*1 long so it's not smaller

 

most important(?) settings in my code:

DAQmxCfgSampClkTiming "float64 rate":  20000 (sampling_rate_hz)
DAQmxCfgSampClkTiming "uInt64 sampsPerChanToAcquire" : 2000 (buffer_size)
DAQmxRegisterEveryNSamplesEvent "uInt32 nSamples" : 1000 (?!?!)
DAQmxReadAnalogF64 "int32 numSampsPerChan": 2000 (buffer_size)
DAQmxReadAnalogF64 "float64 readArray[]": [ [buffer_size]*number_of_channels ]
DAQmxReadAnalogF64 "uInt32 arraySizeInSamps" : buffer_size*number_of_channels

 

as you can see nSamples is a big question mark, but the problem still exist if I put buffer_size variable (2000) there

Message Edited by Dazzler on 09-04-2008 05:00 AM
Message Edited by Dazzler on 09-04-2008 05:02 AM
0 Kudos
Message 1 of 11
(12,987 Views)

I got this error message -200877 when trying different values for nSamples which said:

"modify the buffer size and/or the Every N Samples Event Interval

so the buffer size is an even multiple of the Every N Samples Event Interval."

 so nSamples must be buffer_size/2 ?

 

I changed the nSamples to buffer_size / 2 , but that didn't solve the problem... 

 

I couldn't edit first message but the chart with 3channels looks like this:

 

Message Edited by Dazzler on 09-04-2008 05:17 AM
0 Kudos
Message 2 of 11
(12,981 Views)

I'm still having problems... my code now looks like this:

 

buffer_size = 2000 #samples to read
sampling_rate_hz = 20000
channels = "Dev1/ai0,Dev1/ai1" #this can be one channel or many...

 

 

CHK(nidaq.DAQmxCreateAIVoltageChan(taskHandle,channels,"",DAQmx_Val_Cfg_Default,float64(-10.0),float64(10.0),DAQmx_Val_Volts,None))

CHK(nidaq.DAQmxCfgSampClkTiming(taskHandle,None,float64(sampling_rate_hz),DAQmx_Val_Rising,DAQmx_Val_ContSamps,uInt64(0)))

#I changed sampsPerChanToAcquire to 0, as stated in manual "If the value of the samples per channel attribute/property is less than the value in the table, NI-DAQmx uses the value in the table.", so now the ni-daqmx will determinate it automaticly

 

CHK(nidaq.DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,uInt32(buffer_size),uInt32(0),EveryNCallback_func,None))

#so now the callback function should occur when there's as much data (per channel) ready as "buffer_size" variable states(?)

 

CHK(nidaq.DAQmxRegisterDoneEvent(taskHandle,uInt32(0),DoneCallback_func,None))

 

and the data reading in the callback function:

 

CHK(nidaq.DAQmxReadAnalogF64(taskHandle,buffer_size,float64(10.0),DAQmx_Val_GroupByScanNumber,data.ctypes.data,buffer_size*number_of_channels,ctypes.byref(read),None))

 

please help me, is this the right way to do multichannel acquisition, or am I missing something?

Message Edited by Dazzler on 09-15-2008 05:58 AM
0 Kudos
Message 3 of 11
(12,919 Views)

I have not solved my problem yet, if some of you have working example of continous acquisition with multiple channels, please show me your code.

 

-Dana

0 Kudos
Message 4 of 11
(12,789 Views)

Please, could you move this thread to Multifunction DAQ section -> http://forums.ni.com/ni/board?board.id=250

If I could get response there, and this isn't really measurement studio related problem.

 

thanks 

 

(so, I'm still looking for a simple example of making continuous sample acquisition with multiple channels using ansi-c)

Message Edited by Dazzler on 10-22-2008 04:57 AM
0 Kudos
Message 5 of 11
(12,685 Views)

If anyone have measurement studio with visual studio, could you make an example project (continuous sample acquisition with multiple channel, c++ or ansi-c) and then paste the generated code here? Maybe I could there see what I am doing wrong here.

0 Kudos
Message 6 of 11
(12,634 Views)

This should be one of the most common tasks to do?!?

 

I'm surprised to see that I haven't got any response 😞

0 Kudos
Message 7 of 11
(12,569 Views)
anyone?
0 Kudos
Message 8 of 11
(12,477 Views)
I have similar problems with my NI 6122 DAQ board. Single-channel acquisitions work fine, but I run into buffer dimensioning problems when using multiple channels. Just like the OP, I Would be very grateful for a small example (in ANSI C, if possible) showing the associated arithmetic -- obviously I'm missing something.
0 Kudos
Message 9 of 11
(12,413 Views)
Solution
Accepted by topic author Dazzler

Hi Dazzler,

 

There isn't a multichannel example that ships with the driver but after a quick look at the code you are using in the your third post, everything seems to be configured correctly. The one thing I thing I had a question about was your plots. It looks like you are plotting the same number of points each time. If you are just plotting the data array straight from the read function, you would need to plot (buffer_size*number_of_channels) number of channels since the data returned is as an interleaved array. You may also choose to deinterleave the samples. More information about this can be found in the NI-DAQmx C Reference Help which is installed with the NI-DAQmx driver. 

 

Regards,

Kent

Applications Engineer

Message 10 of 11
(12,401 Views)