Instrument Control Toolbox | ![]() ![]() |
Using Events and Actions
You can enhance the power and flexibility of your instrument control application by using events. An event occurs after a condition is met, and may result in one or more actions.
While the instrument object is connected to the instrument, you can use events to display a message, display data, analyze data, or perform just about any other action. Actions are controlled through action properties and action functions. All event types have an associated action property. Action functions are M-file functions that you construct to suit your specific application needs.
You execute an action when a particular event occurs by specifying the name of the M-file action function as the value for the associated action property.
Example: Introduction to Events and Actions
This example uses the M-file action function instraction
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); fopen(g) g.BytesAvailableActionMode = 'eosCharCode'; g.BytesAvailableAction = 'instraction'; fprintf(g,'*IDN?') readasync(g)
The resulting display from instraction
is shown below.
BytesAvailable event occurred at 17:30:11 for the object: GPIB0-1.
fclose(g) delete(g) clear g
You can use the type
command to display instraction
at the command line.
![]() | Example: Understanding EOI and EOS | Event Types and Action Properties | ![]() |