Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI USB-6289 HighFreq2Ctr implementation in python

I've been trying to interface with the NI USB-6289 using python, with varying degrees of success. Basically, I just use PyDAQmx and try to write the code as close as possible to the ansi-c examples that ship with LabVIEW. However, I'm stuck on the '2 Counters (High Frequency)'  implementation. The code is below. The program runs fine until it gets to the ReadCounterF64 function, where I get a timeout error because no samples are being measured (marked in red below). Does anyone else have experience with implementing this counter in python? Any help appreciated. Thanks...

 

from PyDAQmx import *

import numpy # numpy is recommended for PyDAQmx.

#---------------------------------------
# These conversions are related to the underlying NI-DAQmx c code.
int32 = ctypes.c_long
uInt32 = ctypes.c_ulong
uInt64 = ctypes.c_ulonglong
float64 = ctypes.c_double
#---------------------------------------
nSamples = 10            # Number of samples

numSampsPerChan = int32(nSamples)
arraySizeInSamps = uInt32(nSamples)
sampsPerChanToAcquire = uInt64(nSamples)

ctr0_task = Task()       # Create the task object

#--------------------------------------- 
# Create the actual task using this function:
ctr0_task.CreateCIFreqChan("Dev1/ctr0","",1.0,3.0,DAQmx_Val_Hz,DAQmx_Val_Rising,DAQmx_Val_HighFreq2Ctr,0.01,4,None)

# Create an array to store the measured data.
read_freq = numpy.zeros((nSamples,),dtype=numpy.float64)
#---------------------------------------                                                          
# Configure the task timing using this function
ctr0_task.CfgImplicitTiming(DAQmx_Val_FiniteSamps,sampsPerChanToAcquire)

ctr0_task.StartTask()    # Start the task

# The 'ReadCounterF64' function returns the number of samples read.
# We must supply a parameter to store this value: 
nSamples_read = int32()

#---------------------------------------
# THIS IS WHERE THE ERROR OCCURS!!!!
ctr0_task.ReadCounterF64(numSampsPerChan,5,read_freq, arraySizeInSamps,byref(nSamples_read),None)

ctr0_task.StopTask()    # Stop the task
ctr0_task.ClearTask()   # Clear the task, if we won't use it again here.

# Display the result
print read_freq

 Also, here's the error message:

 

DAQError: Some or all of the samples requested have not yet been acquired.

 

To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger, make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.


Property: DAQmx_Read_RelativeTo
Corresponding Value: DAQmx_Val_CurrReadPos
Property: DAQmx_Read_Offset
Corresponding Value: 0

Task Name: _unnamedTask<6>

Status Code: -200284


in function DAQmxReadCounterF64

0 Kudos
Message 1 of 1
(3,033 Views)