s.startBackground() starts the operation of the session object, s, without blocking MATLAB command line and other code. To block MATLAB execution, use daq.Session.startForeground.
When you use startBackground() with analog input channels, the operation uses the DataAvailable event to deliver the acquired data. This event is fired periodically while an acquisition is in progress. For more information, see Events and Listeners — Concepts.
When you add analog output channels to the session, you must call queueOutputData() before calling startBackground().
During a continuous generation, the DataRequired event is fired periodically to request additional data to be queued to the session. See DataRequired for more information.
By default, the IsContinuous property is set to false and the operation stops automatically. If you have set it to true, use daq.Session.stop to stop background operations explicitly.
Use daq.Session.wait to block MATLAB execution until a background operation is complete.
If your session has analog input channels, you must use a DataAvailable event to receive the acquired data in a background acquisition.
If your session has analog output channels and is continuous, you can use a DataRequired event to queue additional data during background generations.
Create an acquisition session and add a channel before you use this method. See daq.createSession for more information.
Call daq.Session.prepare to reduce the latency associated with startup and to preallocate resources.
Use an ErrorOccurred event to display errors during an operation.
Acquire data in the background by creating a session and adding a listener to access the acquired data using an anonymous function:
s = daq.createSession ('ni'); s.addAnalogInputChannel('cDAQ1Mod1', 'ai0', 'Voltage'); lh = s.addlistener('DataAvailable', @plotData); function plotData(src,event) plot(event.TimeStamps, event.Data) end
Start the session and perform other MATLAB® operations:
s.startBackground(); % perform other MATLAB operations.
Since this is not a continuous operation, the operation stops automatically.
Delete the listener:
For a continuous background generation, add a listener event to queue additional data to be output:
s = daq.createSession('ni'); s.addAnalogOutputChannel('cDAQ1Mod2', 0, 'Voltage'); s.IsContinuous = true; s.Rate = 10000; data = linspace(-1, 1, 5000)'; lh = s.addlistener('DataRequired', ... @(src,event) src.queueOutputData(data)); s.queueOutputData(data) s.startBackground(); % perform other MATLAB operations during the generation.
The operation is continuous,
daq.createSession | daq.Session | daq.Session.addAnalogInputChannel | daq.Session.addAnalogOutputChannel | daq.Session.addlistener | daq.Session.prepare | daq.Session.startForeground | DataAvailable | DataRequired | ErrorOccurred