Dan Colesworthy wrote: > > Hello, > > > > I started with the example in the scipy cookbook which acquires data > from a NI DAQ via the NIDAQmx DLL. Attempting to perform the inverse > function i.e.: > > > > # initialize variables > > taskHandle = TaskHandle(0) > > max_num_samples = 1000 > > dat = numpy.zeros(max_num_samples,dtype=numpy.float64) > > for i in numpy.arange(1000): > > dat[i] = 9.95*math.sin(i*2.0*PI*1000.0/16000.0) > > > > After initializing a task etc, I tried: > > > > CHK(nidaq.DAQmxWriteAnalogF64(taskHandle, > > 1000, > > 0, > > float64(10.0), > > DAQmx_Val_GroupByChannel, > > ctypes.byref(dat), > > None, > > None ) ) > > > > Which generates the error: > > > > Traceback (most recent call last): > > File "./ni_2.py", line 76, in ? > > ctypes.byref(dat), > > TypeError: byref() argument must be a ctypes instance, not 'numpy.ndarray' > > > > The call requires a float64 write_array[] argument. > > > Generally ctypes will not convert a python type into a C type. Only a few Python types like str and int are assigned default C types by ctypes. numpy arrays and float64s are not. But the address of a numpy array's data can be retrieved and used as a pointer argument to a foreign function. DOUBLEPTR = ctypes.POINTER(ctypes.c_double) CHK(nidaq.DAQmxWriteAnalogF64(taskHandle, 1000, 0, ctypes.c_double(10.0), DAQmx_Val_GroupByChannel, ctypes.cast(dat.ctypes.data, DOUBLEPTR), None, None ) ) -- Lenard Lindstrom