Instrument Control Toolbox | ![]() ![]() |
Example: Understanding EOI and EOS
This example illustrates how the EOI line and the EOS character are used to complete read and write operations, and how the EOIMode
, EOSMode
, and EOSCharCode
properties are related to each other. In most cases, you can successfully communicate with your instrument by accepting the default values for these properties.
The default value for EOIMode
is on
, which means that the EOI line is asserted when the last byte is written to the instrument. The default value for EOSMode
is none
, which means that the EOSCharCode
value is not written to the instrument, and read operations will not complete when the EOSCharCode
value is read. Therefore, when you use the default values for EOIMode
and EOSMode
,
g
associated with a National Instruments GPIB controller with board index 0, and an instrument with primary address 1.
g
to the oscilloscope.
g
so that the EOI line is not asserted after the last byte is written to the instrument, and the EOS character is used to complete write operations. The default format for fprintf
is %s\n
, where \n
is replaced by the EOS character as given by EOSCharCode
.
EOSMode
is configured so that read operations will not complete after receiving the EOS character, the preceding read operation succeeded because the EOI line was asserted.
Now configure g
so that the EOS character is not used to complete read or write operations. Because the EOI line is not asserted and the EOS character is not written, the instrument cannot interpret the *IDN?
command and a timeout occurs.
g.EOSMode = 'none'; fprintf(g,'*IDN?') out = fscanf(g) Warning: GPIB: NI: An I/O operation has been canceled mostly likely due to a timeout.
Now configure g
so that the read operation terminates after the "X" character is read. The EOIMode
property is configured to on
so that the EOI line is asserted after the last byte is written. The EOSMode
property is configured to read
so that the read operation completes when the EOSCharCode
value is read.
g.EOIMode = 'on'; g.EOSMode = 'read'; g.EOSCharCode = 'X'; fprintf(g,'*IDN?') out = fscanf(g) out = TEKTRONIX
Note that the rest of the identification string remains in the instrument's hardware buffer. If you do not want to return this data during the next read operation, you should clear it from the instrument buffer with the clrdevice
function.
g
, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.
![]() | Example: Parsing Input Data Using scanstr | Events and Callbacks | ![]() |