Main Content

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 Version History.

Description

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.

Tips

Frequency is controlled by NotifyWhenScansQueuedBelow.

example

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.

example

Examples

collapse all

Create a session and add two analog output channels.

s = daq.createSession('ni');
s.IsContinuous = true;
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, 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 the output data and pause for up to 15 seconds.

startBackground(s);
pause(15)

Delete the listener.

delete(lh)

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.

Version History

Introduced in R2010b

collapse all

R2020a: session object interface is not recommended

Use of this function with a session object is not recommended. To access a data acquisition device, use a DataAcquisition object with its functions and properties instead.

For more information about using the recommended functionality, see Transition Your Code from Session to DataAcquisition Interface.