NI acquisition#
[1]:
import os
import sys
sys.path.insert(0, os.path.realpath('../'))
[2]:
import nidaqwrapper
[3]:
nidaqwrapper.get_connected_devices()
[3]:
{'Dev1', 'SimDev1', 'SimDev2', 'cDAQ2', 'cDAQ2Mod3', 'cDAQ2Mod4'}
[4]:
nidaqwrapper.list_devices()
[4]:
[{'name': 'cDAQ2', 'product_type': 'cDAQ-9174'},
{'name': 'cDAQ2Mod3', 'product_type': 'NI 9260 (BNC)'},
{'name': 'cDAQ2Mod4', 'product_type': 'NI 9215 (BNC)'},
{'name': 'Dev1', 'product_type': 'PCIe-6320'},
{'name': 'SimDev1', 'product_type': 'PCIe-6361'},
{'name': 'SimDev2', 'product_type': 'PCIe-6361'}]
[5]:
nidaqwrapper.list_tasks()
[5]:
['IM3', 'SimTask1']
[6]:
import LDAQ
[7]:
# Create a NI AITask:
# (if you defined a task in NI MAX you can skip this step)
task_in = LDAQ.national_instruments.AITask("input_task_test", sample_rate=25000)
task_in # prints available devices, here we will use virtual device predefined in NI MAX
[7]:
<nidaqwrapper.ai_task.AITask at 0x7c88863a6cf0>
[ ]:
# add channels to the task:
task_in.add_channel(channel_name='vol1', device='cDAQ2Mod4', channel_ind=0, units='V')
task_in.add_channel(channel_name='vol2', device='cDAQ2Mod4', channel_ind=1, units='V')
task_in.add_channel(channel_name='vol3', device='cDAQ2Mod4', channel_ind=2, units='V')
[9]:
# use created AITask in acquisition source:
# (if you created a task using NI MAX, you can just use the task name in a string as the first argument)
acq_ni = LDAQ.national_instruments.NIAcquisition(task_in, acquisition_name="NI")
[ ]:
# create core object and add acquisition source:
ldaq = LDAQ.Core(acquisitions=[acq_ni])
# set trigger:
ldaq.set_trigger(
source="NI",
channel="vol1",
level=0.0,
duration=1.0,
presamples=1000,
trigger_type='abs'
)
# run acquisition:
ldaq.run(hotkeys=False)
[ ]:
# Retrieve the measurement data:
measurement = ldaq.get_measurement_dict()
measurement
{'NI': {'time': array([0.04 , 0.04004, 0.04008, ..., 1.03988, 1.03992, 1.03996],
shape=(25000,)),
'channel_names': ['vol1'],
'data': array([[ 0. ],
[ 0. ],
[ 0. ],
...,
[-0.00020209],
[ 0.00043547],
[ 0.00011669]], shape=(25000, 1)),
'sample_rate': 25000}}
[ ]: