Contenu principal

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.

Note

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, call the start function before calling the write function. The inputs to the start function determine if the generation is finite, repeating, or continuous. Continuous output requires write to provide data for as long as output is needed. Multiple calls to write might be necessary. Background acquisition does not block interaction with MATLAB.

If you queue data for output using the preload function, calling the start function starts background generation. If start uses the finite or continuous option, queued data is sent to the output channels once. You must then call write to continue providing data for generation. If start uses the repeating option, you do not need to call write for continued data generation.

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