解決方案
Python 類比輸入範例程式未建立用於 streaming (串流) 傳輸類比資料的緩衝區,所以當它們轉換每個單獨的取樣點時,速率會降低。
要實現緩衝區以 streaming (串流) 方式傳輸資料,您需要初始化
nidaqmx.stream_readers。以下是一個使用 DAQmx API在 Python 中實現 stream reader (
串流讀取器) 的範例:
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)