Getting Started with NI Devices

This example shows how to get started with National Instruments devices from the command line.

Discover Available Devices

Discover devices connected to your system using daqlist. To learn more about an individual device, access the entry in the device table.

d = daqlist;
d(1, :)
ans =

  1×5 table

    VendorID     DeviceID               Description                Model               DeviceInfo          
    ________    ___________    ______________________________    _________    _____________________________

      "ni"      "cDAQ1Mod1"    "National Instruments NI 9205"    "NI 9205"    [1×1 daq.ni.CompactDAQModule]

d{1, "DeviceInfo"}
ans = 

ni: National Instruments NI 9205 (Device ID: 'cDAQ1Mod1')
   Analog input supports:
      4 ranges supported
      Rates from 0.6 to 250000.0 scans/sec
      32 channels ('ai0' - 'ai31')
      'Voltage' measurement type
   
This module is in slot 1 of the 'cDAQ-9178' chassis with the name 'cDAQ1'.


Create a DataAcquisition

The daq command creates a DataAcquisition object. The DataAcquisition contains information describing hardware, scan rate, and other properties associated with the acquisition.

dq = daq("ni")
dq = 

DataAcquisition using National Instruments hardware:

                     Running: 0
                        Rate: 1000
           NumScansAvailable: 0
            NumScansAcquired: 0
              NumScansQueued: 0
    NumScansOutputByHardware: 0
                   RateLimit: []

Show channels
Show properties and methods

Add an Analog Input Channel

The addinput command attaches an input channel to the DataAcquisition.

ch = addinput(dq,"cDAQ1Mod1", "ai0","Voltage")
ch = 

    Index    Type      Device       Channel    Measurement Type          Range                Name      
    _____    ____    ___________    _______    ________________    __________________    _______________

      1      "ai"    "cDAQ1Mod1"     "ai0"     "Voltage (Diff)"    "-10 to +10 Volts"    "cDAQ1Mod1_ai0"

Acquire Timestamped Data

The read command starts the acquisition and returns the results as a timetable.

data = read(dq, seconds(1));

Plot Data

plot(data.Time, data.cDAQ1Mod1_ai0);
ylabel("Voltage (V)");

Change Default Properties of the Acquisition

By default, run at a scan rate of 1000 scans per second. To acquire at a higher rate, change the Rate property.

dq.Rate = 5000;

Run the acquisition and plot the acquired data:

[data, startTime] = read(dq, seconds(2));
plot(data.Time, data.cDAQ1Mod1_ai0);
ylabel("Voltage (V)");