Main Content

write

Write output scans to hardware channels

Since R2020a

Description

write(d,scanData) writes scan data to the DataAcquisition interface for the device output. The DataAcquisition might already be started or not.

  • If the DataAcquisition has not been started, write sends the data and starts device output generation. As a finite foreground generation, this blocks MATLAB until completed.

  • If the DataAcquisition had already been started, write provides the data for the output operation to begin, which then runs in the background without blocking MATLAB. The start function arguments 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.

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 interface 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 DataAcquisition 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

DataAcquisition 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 interface. 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

See Also

Functions