Instrument Control Toolbox    

Example: Using Events and Callbacks to Read Binary Data

This example extends Example: Reading Binary Data by using the M-file callback function instrcallback to display event-related information to the command line when a bytes-available event occurs during a binary read operation.

  1. Create an instrument object -- Create the GPIB object g associated with a National Instruments GPIB controller with board index 0, and an instrument with primary address 1.
  2. Configure properties -- Configure the input buffer to accept a reasonably large number of bytes, and configure the timeout value to two minutes to account for slow data transfer.
  1. Configure g to execute the callback function instrcallback every time 5000 bytes is stored in the input buffer. Because instrcallback requires an instrument object and event information to be passed as input arguments, the callback function is specified as a function handle.

  1. Connect to the instrument -- Connect g to the oscilloscope.
  2. Write and read data -- Configure the scope to transfer the screen display as a bitmap.
  1. Initiate the asynchronous read operation, and begin generating events.

    instrcallback is called every time 5000 bytes is stored in the input buffer. The resulting displays are shown below.

    Wait until all the data is sent to the input buffer, and then transfer the data to MATLAB as unsigned 8-bit integers.

  1. Disconnect and clean up -- When you no longer need g, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.

  Enabling Callback Functions After They Error Triggers