Main Content

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.

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.

FunctionalityUse 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.

FunctionalityUse 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.

FunctionalityUse 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"

For more information, see write or read.

Read Terminated String

This example shows how to perform a terminated string write and read using the recommended functionality.

FunctionalityUse 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'

fgetl reads until the specified terminator is reached and then discards the terminator.

% 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
     '

fgets reads until the specified terminator is reached and then returns the terminator.

For more information, see writeline or readline.

Read and Parse String Data

This example shows how to read and parse string data using the recommended functionality.

FunctionalityUse 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.

FunctionalityUse This Instead
% g is a gpib object
data = query(g,'ctrlcmd')
data =

    'success'
% g is a visadev object
data = writeread(g,"ctrlcmd")
data = 

    "success"

For more information, see writeline or readline.

Write and Read Binblock Data

This example shows how to write data with the IEEE standard binary block protocol using the recommended functionality.

FunctionalityUse 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.

FunctionalityUse 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.

FunctionalityUse 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

Related Topics