Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Contents

DataAvailable

Notify when acquired data is available to process

Syntax

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

Description

lh=addlistener(session,'DataAvailable',callback); creates a listener for the DataAvailable event. When data is available to process, the callback is executed. The callback can be any MATLAB® function with the (src, event) signature.

lh=addlistener(session,'DataAvailable', @(src, event), expr) creates a listener for the DataAvailable event and fires an anonymous callback 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.DataAvailableInfo object containing the data associated and timing information. Properties of daq.DataAvailableInfo are:

Data

An mxn matrix of doubles where m is the number of scans acquired, and n is the number of input channels in the session.

TimeStamps

The timestamps relative to TriggerTime in an mx1 array where m is the number of scans acquired.

TriggerTime

A MATLAB serial date time stamp representing the absolute time the acquisition trigger occurs.

Examples

Create a session, add an analog input channel, and change the duration of the acquisition:

s=daq.createSession('ni');
addAnalogInputChannel(s,'cDAQ1Mod1', 'ai0', 'Voltage');
s.DurationInSeconds=5;

To add a listener for the DataAvailable event to plot the data, type:

lh=addlistener(s,'DataAvailable', @plotData);

Create a function that plots the data when the event occurs:

 function plotData(src,event)
     plot(event.TimeStamps, event.Data)
end

Start the acquisition and wait:

startBackground(s);
wait(s);

Delete the listener:

delete(lh)

See Also

| | |

Related Examples

Was this topic helpful?