09-04-2008 04:57 AM - edited 09-04-2008 05:02 AM
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
Solved! Go to Solution.
09-04-2008 05:13 AM - edited 09-04-2008 05:17 AM
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:
09-15-2008 05:49 AM - edited 09-15-2008 05:58 AM
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?
10-08-2008 02:08 AM
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
10-22-2008 04:56 AM - edited 10-22-2008 04:57 AM
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)
10-28-2008 07:12 AM
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.
11-05-2008 04:50 AM
This should be one of the most common tasks to do?!?
I'm surprised to see that I haven't got any response 😞
11-18-2008 03:49 AM
11-24-2008 02:25 PM
11-24-2008 04:32 PM
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