main content

getting started with ni devices -凯发k8网页登录

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)");

网站地图