Instrument Control Toolbox | ![]() ![]() |
Events and Callbacks
You can enhance the power and flexibility of your instrument control application by using events. An event occurs after a condition is met, and might result in one or more callbacks.
While the instrument object is connected to the instrument, you can use events to display a message, display data, analyze data, and so on. Callbacks are controlled through callback properties and callback functions. All event types have an associated callback property. Callback functions are M-file functions that you construct to suit your specific application needs.
You execute a callback when a particular event occurs by specifying the name of the M-file callback function as the value for the associated callback property.
Example: Introduction to Events and Callbacks
This example uses the M-file callback function instrcallback
to display a message to the command line when a bytes-available event occurs. The event is generated when the EOSCharCode
property value is read.
g = gpib('ni',0,1); g.BytesAvailableFcnMode = 'eosCharCode'; g.BytesAvailableFcn = @instrcallback; fopen(g) fprintf(g,'*IDN?') readasync(g)
The resulting display from instrcallback
is shown below.
You can use the type
command to display instrcallback
at the command line.
![]() | Example: Understanding EOI and EOS | Event Types and Callback Properties | ![]() |