Write and Read Binary Data Using VISA
This example explores binary read and write operations with a VISA object using a Tektronix® TDS210 oscilloscope.
The VISA object supports seven interfaces: serial, GPIB, VXI, PXI, USB, Serial,
TCP/IP, and Socket. This example explores binary read and write operations using a
VISA-GPIB object. However, binary read and write operations for all interfaces are
identical to each other. Therefore, you can use the same commands. The only difference
is the resource name specified in the VISA constructor
visadev.
Binary read and write operations for the VISA-Serial object are identical to binary read and write operations for the serial port object. Therefore, to learn how to perform binary read and write operations for the VISA-Serial object, refer to Write and Read Serial Port Data.
Connect to Instrument
Create a VISA-GPIB object using the VISA resource string shown below.
v = visadev("GPIB0::2::INSTR")v =
GPIB with properties:
ResourceName: "GPIB0::2::INSTR"
Alias: "OSCOPE"
Vendor: "TEKTRONIX"
Model: "TDS 210"
BoardIndex: 0
PrimaryAddress: 1
SecondaryAddress: 0
Show all properties, functions
Write Binary Data
Use the write function to write binary data to the instrument.
The following commands configure and then send a sine wave to the instrument.
writeline(v,"Data:Destination RefB"); writeline(v,"Data:Encdg SRPbinary"); writeline(v,"Data:Width 2"; writeline(v,"Data:Start 1"); t = (0:499) .* 8 * pi / 500; data = round(sin(t) * 90 + 127); writeline(v,"CURVE #3500"); write(v,data,"int16")
The write function suspends MATLAB® execution until all the data is written or a timeout occurs as
specified by the Timeout property of the
visadev object.
By default, the write function writes binary data as
uint8 data. For more information about specifying other data
types, see write.
Note
When performing a write operation, you should think of the transmitted data in
terms of values rather than bytes. A value consists of one or more bytes. For
example, one uint32 value consists of four bytes.
Read Binary Data
Use the read function to read binary data from the instrument.
Use the following commands to read the sine wave from the instrument.
writeline(v,"Data:Source CH1"); writeline(v,"Data:Encdg SRIbinary"); writeline(v,"Data:Width 2"); writeline(v,"Data:Start 1"); writeline(v,"Curve?") data = read(v,1200,"int16");
The read function suspends MATLAB execution until one of the following occurs:
A timeout occurs as specified by the
TimeoutpropertyThe input buffer is filled
The specified number of values is read
The EOI line is asserted
The terminator is received as specified by the
Terminatorproperty
By default, the read function reads binary data as
uint8 data. For more information about specifying other data
types, see read.
Note
When performing a read operation, you should think of the received data in
terms of values rather than bytes. A value consists of one or more bytes. For
example, one uint32 value consists of four bytes.
Clean Up
When you are finished with the VISA-GPIB object, clear it.
clear v