WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rating: Thread Rating: 20 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
Old 09-11-2012, 01:59 PM
mhead10 mhead10 is offline
Join Date: Mar 2012
Posts: 40
Continuous DAQ with NI USB 6008 and DAQmx

Does anyone have any experience with continuous data acquisition using a NI-DAQ using the ctypes module to access the NI-DAQ family of libraries for NI instruments? I'm trying to use the "cookbook article" from here from SciPy which translates a sample C program for analog signal acquisition into Python.

I changed it to sample two channels continuosly by setting
HTML Code:

I also then changed the clock timing to continuous samples
HTML Code:

I can obtain finite samples fine, however, if I change to "ContSamps", then my data values are read as zero.

If I go back to "FiniteSamps", and then use a timer, I typically only get one or two repeated data arrays, and then nothing else happens. Typically nothing else will happen after the "after stark task" print statement.

I will include all of my code in the hopes that others can benefit off of it because I think this would be a common task, and I have not found any similar complete code elsewhere.

HTML Code:
import ctypes
import numpy
nidaq = ctypes.windll.nicaiu # load the DLL

int32 = ctypes.c_long
uInt32 = ctypes.c_ulong
uInt64 = ctypes.c_ulonglong
float64 = ctypes.c_double
TaskHandle = uInt32
read = int32()

# constants
DAQmx_Val_Cfg_Default = int32(-1)
DAQmx_Val_Volts = 10348
DAQmx_Val_Rising = 10280
DAQmx_Val_FiniteSamps = 10178
DAQmx_Val_ContSamps = 10123
DAQmx_Val_GroupByChannel = 0
DAQmx_Val_GroupByScanNumber= 1 #interleaved

# initialize variables
taskHandle = TaskHandle(0)    
max_num_samples = 2
data = numpy.zeros((max_num_samples,),dtype=numpy.float64)

print 'before error check'
def CHK(err):
    if err < 0:
        buf_size = 100
        buf = ctypes.create_string_buffer('\000' * buf_size)
        raise RuntimeError('nidaq call failed with error %d: %s'%(err,repr(buf.value)))

#def obtain_value():    
#Main Program
print 'entered main program'
print 'after create task'
print 'after create voltage'
CHK(nidaq.DAQmxCfgSampClkTiming(taskHandle,"",float64(2),DAQmx_Val_Rising,DAQmx_Val_ContSamps,uInt64(max_num_samples))); #(samples/sec/channel)  #ContSamps    
print 'after clk'
print 'after start task'
print 'after read'
print data
if taskHandle.value != 0:
print 'after main program'        

print 'end of loop'
Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 08:00 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC