DataRequired Event

Notify when additional data is required for output on continuous generation


lh = addlistener(session,DataRequired,callback);
lh = addlistener(session,DataRequired,@(src,event),expr);


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

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 to a 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.


    • The callback is typically used to queue more data to the device.

    • Frequency is controlled by NotifyWhenScansQueuedBelow.


expand all

Add an anonymous listener to a signal generation session

Create a session and add two analog output channels.

s = daq.createSession('ni');
addAnalogOutputChannel(s,'cDAQ1Mod2', 0:1, 'Voltage');

Create output data for the two channels :

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

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

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

Generate data and pause for up to 15 seconds:


Delete the listener:

Was this topic helpful?