Main Content

write

R2026b

Write output scans to hardware channels

Description

write(d,scanData) writes data from each column of the scanData matrix to the corresponding device output channels on the DataAcquisition object d.

The write operation can occur synchronously (in the foreground) or asynchronously (in the background).

  • Foreground generation (synchronous write) — To initiate foreground data generation, call the write function. This action generates data while blocking interaction with MATLAB® until the write operation completes.

  • Background generation (asynchronous write) — To initiate background data generation without blocking interaction with MATLAB, call the start function before calling write. The inputs to start determine whether generation is finite, repeating, or continuous.

    Continuous background generation requires write to supply data for as long as output is needed.

    • If you queue data using preload, calling start begins background generation. For finite or continuous generation, the queued data is output once, after which you must call write to provide additional data.

    • If you use start with "RepeatOutput" option, the queued data repeats automatically, so additional calls to write are not required.

example

Examples

collapse all

If the supplied data value specifies only a single scan of data for all output channels, the write function generates an on-demand output without clocking.

Create a DataAcquisition object and add two output channels.

d = daq("ni");
ch = addoutput(d,"Dev1",0:1,"Voltage");
ch = 

    Index    Type    Device    Channel      Measurement Type             Range              Name   
    _____    ____    ______    _______    _____________________    __________________    __________

      1      "ao"    "Dev1"     "ao0"     "Voltage (SingleEnd)"    "-10 to +10 Volts"    "Dev1_ao0"
      2      "ao"    "Dev1"     "ao1"     "Voltage (SingleEnd)"    "-10 to +10 Volts"    "Dev1_ao1"

Output 5 volts on both channels.

write(d,[5 5])

Start a data acquisition interface for background operation, then provide data for device output.

d = daq("ni");
addoutput(d,"Dev1",1,"Voltage");
signalData = sin((1:1000)*2*pi/1000); 
start(d,"RepeatOutput")
% ⋮
write(d,signalData')
% Device output now repeated while MATLAB continues.
pause(5)
stop(d)

Input Arguments

collapse all

Data acquisition interface, specified as a DataAcquisition object, created using the daq function.

Example: d = daq()

Scan data for device output, specified as an M-by-N matrix, where M is the number of data scans and N is the number of output channels in the DataAcquisition object. Each column of scanData contains the data for one channel. For a single channel, the data is a column vector.

Data Types: double

Version History

Introduced in R2020a