Transition Your Code to VISA-GPIB Interface
The gpib function, its object functions, and its properties will be
removed. Use the VISA-GPIB interface with visadev instead.
gpib Interface | visadev Interface | Example |
|---|---|---|
instrhwinfo | visadevlist | Discover GPIB Instruments |
gpib and fopen | visadev | Connect to GPIB Instrument |
fwrite | write | Write and Read Binary or String Data |
fread | read | |
fprintf | writeline | Read Terminated String |
fscanf | readline | Read Terminated String |
fgetl | ||
fgets | Read and Parse String Data | |
query | writeread | Write and Read Back Data |
binblockwrite | writebinblock | Write and Read Binblock Data |
binblockread | readbinblock | |
flushinput, flushoutput, and
clrdevice | flush | Flush Data from Memory |
Terminator | configureTerminator | Set Terminator |
spoll | visastatus | |
trigger | visatrigger | |
RsrcName | ResourceName | |
EOSMode and EOSCharCode | Terminator | |
ErrorFcn | ErrorOccurredFcn |
Removed Functionality
The BusManagementStatus, CompareBits,
and HandshakeStatus properties will be removed.
The ValuesReceived and
ValuesSent properties will be removed.
The readasync and
stopasync functions and the
ReadAsyncMode and TransferStatus
properties will be removed. The updated interface reads data synchronously.
The BytesToOutput,
InputBufferSize, and OutputBufferSize
properties will be removed. Buffer sizes are automatically managed and sized as
needed.
The BytesAvailableFcnCount,
BytesAvailableFcnMode,
BytesAvailableFcn, BytesAvailable, and
OutputEmptyFcn properties will be removed. Callback
functions are not supported in the updated interface.
The RecordDetail, RecordMode,
RecordName, and RecordStatus
properties will be removed.
The TimerFcn and TimerPeriod properties
will be removed. Use timer instead.
The Name, Type,
ObjectVisibility, Status, and
Tag properties will be removed.
Discover GPIB Instruments
This example shows how to discover GPIB instruments using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
instrhwinfo('gpib','ni') |
list = visadevlist;
list.ResourceName(list.Type=="gpib") |
For more information, see visadevlist.
Connect to GPIB Instrument
These examples show how to connect to a GPIB instrument and disconnect from it using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
g = gpib('ni',0,1)
fopen(g) |
g = visadev("GPIB0::1::0::INSTR"); |
fclose(g)
delete(g)
clear g |
clear g |
The fopen function is not available in the updated interface.
The object creation function visadev both creates the object
and connects the object to the instrument.
The fclose function is not available in the updated
interface. The clear function disconnects the object from the
instrument when it removes the object from the workspace.
For more information, see visadev.
Write and Read Binary or String Data
These examples show how to perform a binary write and read, and how to write and read nonterminated string data, using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
% g is a gpib object
fwrite(g,1:5)
data = fread(g,5)data =
1
2
3
4
5 |
% g is a visadev object
write(g,1:5)
data = read(g,5)data =
1 2 3 4 5
|
% g is a gpib object fwrite(g,'hello','char') length = 5; data = fread(g,length,'char') data = 104 101 108 108 111 data = char(data)' data =
'hello' |
% g is a visadev object write(g,"hello","string") length = 5; data = read(g,length,"string") data =
"hello" |
Read Terminated String
This example shows how to perform a terminated string write and read using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
% g is a gpib object g.Terminator = 'CR/LF'; fprintf(g,'SOUR:%d:FREQ',ch) data = fscanf(g,'%e') data =
11.9000 |
% g is a visadev object configureTerminator(g,"CR/LF") str = sprintf("SOUR:%d:FREQ",ch) writeline(g,str) data = readline(g) data =
"11.9000"data = sscanf(data,'%e')data =
11.9000 |
% g is a gpib object g.Terminator = 'CR/LF'; fprintf(g,'hello') data = fgetl(g) data =
'hello'
|
% g is a visadev object configureTerminator(g,"CR/LF") writeline(g,"hello") data = readline(g) data =
"hello" |
% g is a gpib object g.Terminator = 'CR/LF'; fprintf(g,'hello') data = fgets(g) data =
'hello
'
|
Read and Parse String Data
This example shows how to read and parse string data using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
% g is a gpib object data = scanstr(g,';') data =
3×1 cell array
{'a'}
{'b'}
{'c'} |
% g is a visadev object
data = readline(g)data =
"a;b;c"data = strsplit(data,";")data =
1×3 string array
"a" "b" "c" |
For more information, see readline.
Write and Read Back Data
This example shows how to write ASCII terminated data and read ASCII terminated data back using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
% g is a gpib object data = query(g,'ctrlcmd') data =
'success' |
% g is a visadev object data = writeread(g,"ctrlcmd") data =
"success" |
Write and Read Binblock Data
This example shows how to write data with the IEEE standard binary block protocol using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
% g is a gpib object
binblockwrite(g,1:5);
data = binblockread(g)data =
1
2
3
4
5 |
% g is a visadev object
writebinblock(g,1:5)
data = readbinblock(g)data =
1 2 3 4 5
|
For more information, see writebinblock or readbinblock.
Flush Data from Memory
This example shows how to flush data from the buffer using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
% g is a gpib object
flushinput(g)
clrdevice(g) |
% g is a visadev object flush(g,"input") |
% g is a gpib object
flushoutput(g)
clrdevice(g) |
% g is a visadev object flush(g,"output") |
% g is a gpib object
flushinput(g)
flushoutput(g)
clrdevice(g) |
% g is a visadev object
flush(g) |
For more information, see flush.
Set Terminator
These examples show how to set the terminator using the recommended functionality.
| Functionality | Use This Instead |
|---|---|
% g is a gpib object g.Terminator = "CR/LF"; |
% g is a visadev object configureTerminator(g,"CR/LF") |
% g is a gpib object g.Terminator = {"CR/LF" [10]}; |
% g is a visadev object configureTerminator(g,"CR/LF",10) |
For more information, see configureTerminator.
See Also
Topics
- R2021a GPIB Interface Topics (R2021a)