11-28-2017 04:13 PM
Hey there!
I am looking into implementing the stream readers into my python code. The Docs have this interesting note:
Consider using the nidaqmx.stream_readers
and nidaqmx.stream_writers
classes to increase the performance of your application, which accept pre-allocated NumPy arrays.
I cannot find an example of the implementation for this. See the code I have below for a 5 minute record. What benefits would I get with the stream reader and how to setup??
Using a NI 9234, with a high sensitivity accelerometer.
Thanks
Example Code:
import nidaqmx from nidaqmx.constants import AcquisitionType import matplotlib.pyplot as plt sample_time = 60*5 # units = seconds s_freq = 2**12 num_samples = sample_time*s_freq dt = 1/s_freq with nidaqmx.Task() as task: task.ai_channels.add_ai_accel_chan("cDAQ1Mod1/ai0", sensitivity=9948.0, max_val=0.5, min_val=-0.5) task.timing.cfg_samp_clk_timing(4096, sample_mode = AcquisitionType.CONTINUOUS) data = task.read(number_of_samples_per_channel=num_samples, timeout = nidaqmx.constants.WAIT_INFINITELY)
06-06-2018 03:21 PM
I would also be very interested to learn about stream readers. Currently trying to implement them.
07-11-2018 01:08 PM
From what I see the closest we have to an example is https://github.com/ni/nidaqmx-python/blob/master/nidaqmx/tests/test_stream_analog_readers_writers.py
Just pull out the writer parts if you are only doing input.
12-05-2018 08:54 AM
I am trying to implement the use of a streamreader within a task.register_every_n_samples_acquired_into_buffer_event. I got the read function work.
Here is what I have for the input.
from nidaqmx import stream_readers as sr
readings=np.ndarray((4,16384))
print(readings)
sr.AnalogMultiChannelReader.read_many_sample(readings,16384)
This it the error I get.
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 234, in 'calling callback function'
File "CodeFileGraphStreamReader.py", line 27, in data_collect
sr.AnalogMultiChannelReader.read_many_sample(readings,16384)
File "C:\Users\chad_finkbeiner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\stream_readers.py", line 327, in read_many_sample
self._task._calculate_num_samps_per_chan(
AttributeError: 'numpy.ndarray' object has no attribute '_task'
The documentation clearly states to use a numpy array.
What am I missing?
02-12-2019 12:26 PM
Hi,
did you ever figure the stream_reader ADI out? I also would like to use it but the documentation is unclear. Any help appreciated.
02-13-2019 01:07 PM
Hey there,
The `read_many_sample` method is not a static method on `AnalogMultiChannelReader`. You need to instantiate an `AnalogMultiChannelReader` object and pass it the `in_stream` object from the `nidaqmx.Task` object.
You can find an example of doing this here:
04-04-2023 10:54 AM - edited 04-04-2023 10:55 AM
I just wanted to provide an updated link for the github code, since the paths have been changed and the links above are broken.
https://github.com/ni/nidaqmx-python/tree/master/tests/legacy