DataRequired Event

Notify when additional data is required for output on continuous generation

Syntax

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

Description

example

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 (MATLAB).

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

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.

Introduced in R2010b