06-04-2012 09:32 AM
Hello,
I'm trying to use an USB-6251 device to conduct some measurements using Python.
For that I'm using the ctypes library. Everything works fine the first time I run the program, the data
is being collected and I can read it afterwards. The Problem arises once I try to run the program a second time.
The program times out while trying to read the data, it always returns with zero points acquired.
There is no problem acquiring data using the Measurement & Automatisation Explorer.
The program basically is the example from the scipy cookbook:
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
TaskHandle2 = uInt32
# the constants
DAQmx_Val_Cfg_Default = int32(-1)
DAQmx_Val_Volts = 10348
DAQmx_Val_Rising = 10280
DAQmx_Val_FiniteSamps = 10178
DAQmx_Val_GroupByChannel = 0
DAQmx_Val_Task_Unreserve = int32(5)
# initialize variables
taskHandle = TaskHandle(0)
max_num_samples = 1000
data = numpy.zeros((max_num_samples,),dtype=numpy.float64)
# now, on with the program
nidaq.DAQmxCreateTask("",ctypes.byref(taskHandle))
nidaq.DAQmxCreateAIVoltageChan(taskHandle,"Dev2/ai0","",
DAQmx_Val_Cfg_Default,
float64(-10.0),float64(10.0),
DAQmx_Val_Volts,None)
nidaq.DAQmxCfgSampClkTiming(taskHandle,"",float64(10000.0),
DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,
uInt64(max_num_samples));
nidaq.DAQmxCfgInputBuffer(taskHandle,200000)
nidaq.DAQmxStartTask(taskHandle)
read = int32()
nidaq.DAQmxReadAnalogF64(taskHandle,-1,float64(10.0),
DAQmx_Val_GroupByChannel,data.ctypes.data,
max_num_samples,ctypes.byref(read),None)
print "Acquired %d points"%(read.value)
nidaq.DAQmxStopTask(taskHandle)
nidaq.DAQmxClearTask(taskHandle)
anyone knows how to solve this?
oh yes, Im running Win 7 32bit.
06-05-2012 04:52 AM
Hello,
i could not reproduce your problem. It runs fine and more than only one time. You can try to run the Program with a simulated Device in the Measurement and Automation Explorer. Just to second test result.
06-05-2012 06:31 AM
Thanks for your reply,
I tested it with an virtual device as well as with an NI USB-6009 and it worked well both times
It just dosen't work with the 6251 device.
Any idea what could be wrong?
06-05-2012 07:59 AM
I tested your program now on the exact same device NI USB-6251. Works fine. I used Python 2.7.3.
What version of the Measurement and Automation Explorer do you have? Maybye an update would help.
06-27-2012 03:53 AM
sorry for the late reply, I have been off work wor a while. I'm running version 5.1.0
It is still not working. Maybe it's because i'm running the system on a virtual machine but
it's working with the USB-6009 so I don't think that this is the Problem.
Any other thoughts?
06-28-2012 01:55 AM
Hey, you can try a DAQmx update:
http://joule.ni.com/nidu/cds/view/p/id/2933/lang/de
And if this doesn't work maybe you can download the same Version of Python that I used. It worked fine. Which Version do you use?
06-28-2012 02:14 AM
Hey, thanks for all your help!
I'm running 2.7.2 (python xy)
DAQmx is up to date
I will try to update to 2.7.3 now but somehow I don't think that will do it.
I might try to get an native windows machine and check if the Instrument works there.
Also try it with Matlab