Data Acquisition Toolbox    

Examples: Using Callback Properties and Callback Functions

Examples showing how to create callback functions and configure callback properties are given below.

Displaying the Number of Samples Output

This example illustrates how to generate samples output events. You can run this example by typing daqdoc6_4 at the MATLAB command line. The local callback function daqdoc6_4disp (not shown below) displays the number of events that were output from the engine whenever the samples output event occurred.

  1. Create a device object -- Create the analog output object AO for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo.
  2. Add channels -- Add two channels to AO.
  3. Configure property values -- Configure the trigger to repeat four times, specify daqdoc6_4disp as the M-file callback function to execute whenever 8000 samples are output, generate data to be queued, and queue the data with one call to putdata.
  4. Output data -- Start AO. The waittilstop function blocks the MATLAB command line, and waits for AO to stop running.
  5. Clean up -- When you no longer need AO, you should remove it from memory and from the MATLAB workspace.

Displaying EventLog Information

This example illustrates how callback functions allow you to easily display information stored in the EventLog property. You can run this example by typing daqdoc6_5 at the MATLAB command line. The local callback function daqdoc6_5disp (not shown below) displays the absolute time and relative sample associated with the start, trigger, and stop events.

  1. Create a device object -- Create the analog output object AO for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo.
  2. Add channels -- Add one channel to AO.
  3. Configure property values -- Specify daqdoc6_5disp as the M-file callback function to execute when the start, trigger, and stop events occur, generate data to be queued, and queue the data with one call to putdata.
  4. Output data -- Start AO. The waittilstop function blocks the MATLAB command line, and waits for AO to stop running.
  5. Clean up -- When you no longer need AO, you should remove it from memory and from the MATLAB workspace.

  Recording and Retrieving Event Information Linearly Scaling the Data: Engineering Units