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.
g
associated with a National Instruments GPIB controller with board index 0, and an instrument with primary address 1.
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.
g
to the oscilloscope.
instrcallback
is called every time 5000 bytes is stored in the input buffer. The resulting displays are shown below.
BytesAvailable event occurred at 09:41:42 for the object: GPIB0-1. BytesAvailable event occurred at 09:41:50 for the object: GPIB0-1. BytesAvailable event occurred at 09:41:58 for the object: GPIB0-1. BytesAvailable event occurred at 09:42:06 for the object: GPIB0-1. BytesAvailable event occurred at 09:42:14 for the object: GPIB0-1. BytesAvailable event occurred at 09:42:22 for the object: GPIB0-1. BytesAvailable event occurred at 09:42:30 for the object: GPIB0-1.
Wait until all the data is sent to the input buffer, and then transfer the data to MATLAB as unsigned 8-bit integers.
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 | ![]() |