Why Am I Not Getting High Sampling Rates When I Use the Python with DAQ API

Updated Oct 26, 2018

Issue Details

When I use the python with DAQ API the rate of reading is really slow. I'm using the analog input example and there's no other examples that show doing a continuous input. 

Solution

The python analog input example doesn't create a buffer to stream analog data so the rates are slowed down as they convert each individual sample. To implement a buffer to stream data, you'll need to intialize nidaqmx.stream_readers. 

Here is an example for implementing a stream reader in python with the DAQ API: 

import nidaqmx
import numpy
from nidaqmx.stream_readers import AnalogSingleChannelReader

with nidaqmx.Task() as read_task:
    number_of_samples = 10000  # change this to number of samples to acquire

    # create task and channel
    read_task.ai_channels.add_ai_voltage_chan("Dev1/ai0",
                                              max_val=10, min_val=-10)

    # create stream reader object
    reader = AnalogSingleChannelReader(read_task.in_stream)

    # initialize data array
    read_array = numpy.zeros(number_of_samples, dtype=numpy.float64)

    # acquire and store in read_array
    reader.read_many_sample(
        read_array, number_of_samples_per_channel=number_of_samples,

        timeout=10.0)

    # print to console the result
    print(read_array)