DataRequired Event

(Not recommended) Notify when additional data is required for output on continuous generation

This session object function is not recommended. Use DataAcquisition object functions instead. See Compatibility Considerations.



lh = addlistener(session,'DataRequired',callbackfct); creates a listener for the DataRequired event. When more data is required, the callback is executed. The callback is typically used to queue more data to the device. The callback can be any MATLAB® function with the (src,event) signature.


Frequency is controlled by NotifyWhenScansQueuedBelow.


lh = addlistener(session,'DataRequired',@(src,event) expr); creates a listener for the DataRequired event and fires an anonymous function. The anonymous function requires the specified input arguments and executes the operation specified in the expression expr. Anonymous functions provide a quick means of creating simple functions without storing your function in a separate file. For more information see Anonymous Functions.

The callback has two required parameters: src and event. src is the session object for the listener and event is a daq.DataRequiredInfo object.


collapse all

Create a session and add two analog output channels.

s = daq.createSession('ni');
s.IsContinuous = true;

Create output data for the two channels.

outputData0 = (linspace(-1,1,1000))';
outputData1 = (linspace(-2,2,1000))';

Queue the output data, add an anonymous listener, and generate the signal in the background.

lh = addlistener(s,'DataRequired', ...
			@(src,event) src.queueOutputData([outputData0,outputData1]));

Generate the output data and pause for up to 15 seconds.


Delete the listener.


Input Arguments

collapse all

Data acquisition session, specified as a session object. Create the session object using daq.createSession. Use the data acquisition session for acquisition and generation operations. Create one session per vendor and use that vendor session to perform all data acquisition operations.

Callback function, specified as a function handle.

Anonymous callback function, specified as a MATLAB operation. The expression executes when the trigger occurs.

Compatibility Considerations

expand all

Not recommended starting in R2020a

Introduced in R2010b