Data Acquisition Toolbox
  Function/Property:
    Search    Help Desk 

Examples: Using Action Properties and Functions

Examples that show you how to create action functions and configure action-related properties are given below.

Displaying Event Information with an Action Function

This example illustrates how the action function prototype allows you to easily display event information. The example shown below uses daqaction to display information for trigger, runtime error, and stop events. The default SampleRate and SamplesPerTrigger values are used, which results in a one second acquisition for each trigger issued.

Initialization: Create the analog input object AI for a sound card. The available adaptors are found with daqhwinfo.

Configuration: Add one hardware channel to AI, 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, runtime error, or stop event occurs.

Execution: Start AI and wait for it to stop running. The pause command allows the output from daqaction to be displayed.

Termination: Delete AI.

The output is shown below.

Specifying a Toolbox Function as an Action

You can specify the start, stop, or trigger toolbox functions as actions. This example illustrates how you can specify a toolbox function as an action. As shown in the example code below, when an over-range condition occurs on the sound card channel, the acquisition is stopped.

Passing Additional Parameters to an Action Function

This example illustrates how additional arguments are passed to the action function, and generates timer events to display data. The M-file to execute is called daqdoc4_8plot and this function is executed every 0.5 seconds.

Initialization: Create the analog input object AI for a sound card. The installed adaptors and hardware ID's are found with daqhwinfo.

Configuration: Add one hardware channel to AI, define a ten second acquisition, and execute the M-file daqug3_8plot every 0.5 seconds. Note that the variables size, P, and T are passed to the action function.

Execution: Start AI. The drawnow command in daqdoc4_8plot forces MATLAB to update the display.

Termination: Clear the action function from the workspace and delete AI.

The function daqdoc4_8plot is given below.

Note:
With action functions, you can perform essentially any data acquisition task. However, if you repeatedly display information to the MATLAB command line, you will usually not be able to issue the stop command. You can verify this by removing the semicolon from the size(data) command and running daqdoc4_8.



[ Previous | Help Desk | Next ]