Data Acquisition Toolbox    

Examples: Using Action Properties and Functions

This section provides examples that show you how to create action functions and configure action properties.

Displaying Event Information with an Action Function

This example illustrates how action functions allow you to easily display event information. The example uses daqaction to display information for trigger, run-time error, and stop events. The default SampleRate and SamplesPerTrigger values are used, which results in a 1-second acquisition for each trigger executed.

You can run this example by typing daqdoc5_6 at the MATLAB command line.

1. Create a device object - Create the analog input object AI for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo.

2. Add channels - Add one hardware channel to AI.

3. Configure property values - Repeat the trigger three times, find the time for the acquisition to complete, and define daqaction as the M-file to execute when a trigger, run-time error, or stop event occurs.

4. Acquire data - Start AI and wait for it to stop running. The pause command allows the output from daqaction to be displayed.

5. Clean up - When you no longer need AI, you should remove it from memory and from the MATLAB workspace.

Passing Additional Parameters to an Action Function

This example illustrates how additional arguments are passed to the action function. Timer events are generated every 0.5 second to display data using the action function daqdoc5_7plot.

You can run this example by typing daqdoc5_7 at the MATLAB command line.

1. Create a device object - Create the analog input object AI for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo.

2. Add channels - Add one hardware channel to AI.

3. Configure property values - Define a 10-second acquisition and execute the M-file daqdoc5_7plot every 0.5 seconds. Note that the variables bsize, P, and T are passed to the action function.

4. Acquire data - Start AI. The drawnow command in daqdoc5_7plot forces MATLAB to update the display.

5. Clean up - When you no longer need AI, you should remove it from memory and from the MATLAB workspace.


 Creating and Executing Action Functions Linearly Scaling the Data: Engineering Units