Create a DataAcquisition Interface
This example shows how to create a DataAcquisition interface and add channels to acquire and generate data. You can also configure DataAcquisition and channel properties needed for your operation.
Step 1. Find Devices for the Vendor.
daqlist("ni")
2×4 table DeviceID Description Model DeviceInfo ________ ___________________________________ __________ _______________________ "Dev2" "National Instruments(TM) USB-6509" "USB-6509" [1×1 daq.ni.DeviceInfo] "Dev3" "National Instruments(TM) USB-6211" "USB-6211" [1×1 daq.ni.DeviceInfo]
Step 2. Create a DataAcquisition Object.
d = daq("ni")
DataAcquisition using National Instruments(TM) hardware: Running: 0 Rate: 1000 NumScansAvailable: 0 NumScansAcquired: 0 NumScansQueued: 0 NumScansOutputByHardware: 0 RateLimit: []
After you create a DataAcquisition object, add channels using the
addinput
and addoutput
functions.
Step 3. Add Channels to the DataAcquisition.
Add an analog input channel, and view the DataAcquisition channel list:
addinput(d,"Dev3","ai0","Voltage") d.Channels
Index Type Device Channel Measurement Type Range Name _____ ____ ______ _______ ________________ __________________ __________ 1 "ai" "Dev3" "ai0" "Voltage (Diff)" "-10 to +10 Volts" "Dev3_ai0"
Step 4. Change Channel Properties.
Change the channel TerminalConfig
property to
'SingleEnded'
, and view the updated configuration:
d.Channels.TerminalConfig = "SingleEnded";
d.Channels
Index Type Device Channel Measurement Type Range Name _____ ____ ______ _______ _____________________ __________________ __________ 1 "ai" "Dev3" "ai0" "Voltage (SingleEnd)" "-10 to +10 Volts" "Dev3_ai0"