Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems to acquire data more then once using Python

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.

0 Kudos
Message 1 of 7
(4,380 Views)

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.

0 Kudos
Message 2 of 7
(4,373 Views)

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?

 

 

0 Kudos
Message 3 of 7
(4,369 Views)

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.

 

 

0 Kudos
Message 4 of 7
(4,362 Views)

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?

0 Kudos
Message 5 of 7
(4,323 Views)

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?

0 Kudos
Message 6 of 7
(4,310 Views)

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

 

0 Kudos
Message 7 of 7
(4,307 Views)