Main Content

start

Start DataAcquisition background operation

Since R2020a

Description

start(d) starts the DataAcquisition interface background operation. When the input acquisition and output generation begin depends on channel configuration and preloaded output data:

  • If the DataAcquisition has only input channels, the acquisition begins immediately, collecting scan data, which you can access later with the read function. The default scan duration is 1 second.

  • If the DataAcquisition interface has only output channels, generation begins immediately if data is already queued with the preload function. If no data is queued, output begins when data is made available with write function.

  • If the DataAcquisition has both input and output channels, the input acquisition begins and ends at the same time as the output generation, resulting in the same number of scans.

start(d,"Continuous") starts the background operation running continuously. If there is data already available from the preload function, output generation begins immediately along with acquisition on any input channels. Otherwise, acquisition begins when you execute write. The operation continues until you call stop. As output scan data is generated or input scan data is acquired, you might need to call write or read while the DataAcquisition is still running.

start(d,"RepeatOutput") starts the background operation, generating periodic output in a repeating loop of the output scan data. If there is data already available from the preload function, output generation begins immediately along with acquisition on any input channels. Otherwise, generation and acquisition begin when you execute write. The operation continues until you call stop. If input scan data is being acquired, you might need to call read while the DataAcquisition is still running.

start(d,"Duration",span) or start(d,"NumScans",span) starts the background input acquisition to run for a finite span of time, specified as either a duration or a number of scans. If the DataAcquisition has any output channels, the start occurs but the duration specification is ignored.

example

Examples

collapse all

When a background acquisition is initiated with the start function, use read to import the data.

d = daq("ni");
ch = addinput(d,"Dev1",1:2,"Voltage")
start(d,"NumScans",5)
Background operation has started.
Background operation will stop after 0.005 s.
To read acquired scans, use read.
scanData = read(d,"all")
scanData =

  5×2 timetable

      Time       Dev1_ai1    Dev1_ai2
    _________    ________    ________

    0 sec        0.012466    0.023977
    0.001 sec    0.019373    0.023319
    0.002 sec    0.021017     0.02299
    0.003 sec    0.021346     0.02299
    0.004 sec    0.022661    0.023648

Define and preload data for device output, then start output generation to repeat in the background while MATLAB continues.

d = daq("ni");
addoutput(d,"Dev1",1,"Voltage");
signalData = sin((1:1000)*2*pi/1000); 
preload(d,signalData') % Column of data for one channel
start(d,"RepeatOutput")
% Device output now repeated while MATLAB continues.
stop(d)

Input Arguments

collapse all

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

Example: d = daq()

Length of background operation, specified as a duration or double. For "Duration" specify a duration type; for "NumScans" specify a double for the number of scans. The default is 1 second.

Example: seconds(5)

Data Types: double | duration

Version History

Introduced in R2020a