Instrument Control Toolbox    

Creating and Executing Callback Functions

You specify the callback function to be executed when a specific event type occurs by including the name of the M-file as the value for the associated callback property. You can specify the callback function as a function handle or as a string cell array element. Function handles are described in the MATLAB function_handle reference pages. Note that if you are executing a local callback function from within an M-file, then you must specify the callback as a function handle.

For example, to execute the callback function mycallback every time the EOSCharCode property value is read from your instrument:

Alternatively, you can specify the callback function as a cell array.

M-file callback functions require at least two input arguments. The first argument is the instrument object. The second argument is a variable that captures the event information given in Table 3-10, GPIB Event Information,. This event information pertains only to the event that caused the callback function to execute. The function header for mycallback is shown below.

You pass additional parameters to the callback function by including both the callback function and the parameters as elements of a cell array. For example, to pass the MATLAB variable time to mycallback:

Alternatively, you can specify mycallback as a string in the cell array.

The corresponding function header is

If you pass additional parameters to the callback function, then they must be included in the function header after the two required arguments.


  Storing Event Information Enabling Callback Functions After They Error