I am using the nidaqmx-python
library for acquiring data. Is it possible to access an existing task, which is already defined in the NI MAX?
Asked
Active
Viewed 943 times
1

blaz
- 4,108
- 7
- 29
- 54
-
2Is `tasks` near the bottom of [this page](https://nidaqmx-python.readthedocs.io/en/latest/system.html), or the contents of [this page](https://nidaqmx-python.readthedocs.io/en/latest/persisted_task_collection.html), any help? – nekomatic Feb 28 '18 at 13:48
1 Answers
3
My solution, thanks to the tip from @nekomatic, is:
import nidaqmx
system = nidaqmx.system.System.local() # load local system
task_names = system.tasks.task_names # returns a list of task names
task = system.tasks[0] # selected the first task
loaded_task = task.load() # load the task
sent_samples = [] # list for saving acquired data
with loaded_task:
loaded_task.timing.cfg_samp_clk_timing(
rate=2560,
sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,
samps_per_chan=1000)
def callback(task_handle, every_n_samples_event_type,
number_of_samples, callback_data):
"""
Callback function/
"""
print('Every N Samples callback invoked.')
samples = loaded_task.read(number_of_samples_per_channel=2560)
sent_samples.extend(samples)
return 0
loaded_task.register_every_n_samples_acquired_into_buffer_event(
200, callback)
loaded_task.start()
input('Running task. Press Enter to stop.\n')

blaz
- 4,108
- 7
- 29
- 54