Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Acquire Data in the Foreground

This example shows how to acquire voltage data from an NI 9205 device with ID cDAQ1Mod1.

Create a session object and save it to the variable, s:

s = daq.createSession('ni')

s = 

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Operation starts immediately.
      No channels have been added.

By default, the acquisition is configured to run for a duration of 1 second to acquire 1000 scans, at the rate of 1000 scans per second.

Change the duration of the acquisition to 2 seconds:

s.DurationInSeconds = 2.0

s = 

Data acquisition session using National Instruments hardware:
   Will run for 2 seconds (2000 scans) at 1000 scans/second.
   No channels have been added.   

The acquisition now runs for 2 seconds acquiring 2000 scans at the default rate.

Add an analog input 'Voltage' channel named 'ai0':

addAnalogInputChannel(s,'cDAQ1Mod1','ai0','Voltage')

ans = 

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Operation starts immediately.
      Number of channels: 1
      index Type  Device   Channel MeasurementType  Range            Name
      ----- ---- --------- ------- ---------------  ---------------- ----
      1     ai   cDAQ1Mod1 ai0     Voltage (Diff)   -10 to +10 Volts

For NI devices, use either a terminal name, like 'ai2', or a numeric equivalent like 2 for the channel ID.

Acquire the data and store it in the variable, data and plot it:

data = startForeground(s);
plot (data)

Change the number of scans to 4096.

s.NumberOfScans = 4096

s = 

Data acquisition session using National Instruments hardware:
   Will run for 4096 scans (4.096 seconds) at 1000 scans/second.
   Operation starts immediately.
      Number of channels: 1
      index Type  Device   Channel MeasurementType  Range            Name
      ----- ---- --------- ------- ---------------  ---------------- ----
      1     ai   cDAQ1Mod1 ai0     Voltage (Diff)   -10 to +10 Volts

Changing the number of scans changed the duration of the acquisition to 4.096 seconds at the default rate of 1000 scans per second.

Acquire the data and store it in the variable, data and plot it:

data = startForeground(s);
plot (data)

Related Topics

Was this topic helpful?