Main Content

start

R2026b

Start background operation for DataAcquisition interface

Description

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

  • If the interface has only input channels, the acquisition begins immediately and acquires scan data for the default scan duration of 1 second. Use the read function to access the acquired data.

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

  • If the interface 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. Output generation begins if there is queued data with preload or if you make data available with write.

start(d,"Continuous") runs the background operation continuously until you call stop. Preloaded output data is sent to the output channels once. You must call write to continue providing output data. If the interface has input channels, use read to access acquired data while the operation is running.

start(d,"RepeatOutput") generates periodic output by repeating the data provided by preload or write until you call stop. The interface d must have output channels. The function automatically repeats data without needing additional calls to write.

start(d,Name=Value) starts the finite background operation by specifying the span in duration or number of scans. If the interface has only input channels, acquisition runs for the specified span. If the interface has output channels, the function ignores the specified span and determines the number of scans from the amount of queued output data.

example

Examples

collapse all

After you initiate a background acquisition 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()

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: start(d,Duration=10) background operation runs for 10 seconds.

Span of background operation in time, specified as a duration value. If you specify a double, the function treats the value as seconds.

Example: start(d,Duration=minutes(5))

Example: start(d,Duration=3)

Data Types: double | duration

Span of background operation in scans, specified as a positive integer.

Example: start(d,NumScans=5000)

Version History

Introduced in R2020a