Main Content

Transition Your Code to visadev Interface

The visa function, its object functions, and its properties will be removed. Use visadev instead.

visa Interfacevisadev InterfaceExample
instrhwinfovisadevlistDiscover VISA Devices
visavisadevConnect to VISA Device
fwrite and freadwrite and readWrite and Read Binary or String Data
fprintfwritelineRead Terminated String
fscanf, fgetl, and fgetsreadlineRead Terminated String
Read and Parse String Data
querywritereadWrite and Read Back Data
binblockwrite and binblockreadwritebinblock and readbinblockWrite and Read Binblock Data
flushinput, flushoutput, and clrdeviceflushFlush Data from Memory
TerminatorconfigureTerminatorSet Terminator
BytesAvailableFcnCount, BytesAvailableFcnMode, BytesAvailableFcn, and BytesAvailableconfigureCallbackSet Up Callback Function
spollvisastatus 
triggervisatrigger 
memmap, mempeek, mempoke, memread, memunmap, memwriteNot supported 
visa Propertiesvisadev Properties 

Discover VISA Devices

This example shows how to discover VISA devices using the recommended functionality.

FunctionalityUse This Instead
instrhwinfo('visa','ni')
visadevlist

For more information, see visadevlist.

Connect to VISA Device

These examples show how to connect to a VISA device and disconnect from it using the recommended functionality.

FunctionalityUse This Instead
v = visa('ni','GPIB::1::0::INSTR')
fopen(v)
v = visadev("GPIB::1::0::INSTR");
fclose(v)
delete(v)
clear v
clear v

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
% v is a visa object
fwrite(v,1:5)
data = fread(v,5)
data =

     1
     2
     3
     4
     5
% v is a visadev object
write(v,1:5)
data = read(v,5)
data =

     1     2     3     4     5
% v is a visa object
fwrite(v,"hello","char")
length = 5;
data = fread(v,length,"char")
data =

   104
   101
   108
   108
   111
data = char(data)'
data =

    'hello'
% v is a visadev object
write(v,"hello","string")
length = 5;
data = read(v,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
% v is a visa object
v.Terminator = "CR";
fprintf(v,"hello")
data = fscanf(v)
data =

    'hello
     '
% v is a visadev object
configureTerminator(v,"CR")
writeline(v,"hello")
data = readline(v)
a = 

    "hello"
% v is a visa object
v.Terminator = "CR";
fprintf(v,"hello")
data = fgetl(v)
data =

    'hello'

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

% v is a visa object
v.Terminator = "CR";
fprintf(v,"hello")
data = fgets(v)
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
% v is a visa object
data = scanstr(v,';')
data =

  3×1 cell array

    {'a'}
    {'b'}
    {'c'}
% v is a visadev object
data = readline(v)
data = 

    "a;b;c"
data = strsplit(v,";")
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
% v is a visa object
data = query(v,'ctrlcmd')
data =

    'success'
% v is a visadev object
data = writeread(v,"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
% v is a visa object
binblockwrite(v,1:5);
data = binblockread(v)
data =

     1
     2
     3
     4
     5
% v is a visadev object
writebinblock(v,1:5)
data = readbinblock(v)
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
% v is a visa object
flushinput(v)
clrdevice(v)
% v is a visadev object
flush(v,"input")
% v is a visa object
flushoutput(v)
clrdevice(v)
% v is a visadev object
flush(v,"output")
% v is a visa object
flushinput(v)
flushoutput(v)
clrdevice(v)
% v is a visadev object
flush(v)

For more information, see flush.

Set Terminator

These examples show how to set the terminator using the recommended functionality.

FunctionalityUse This Instead
% v is a visa object
v.Terminator = "CR/LF";
% v is a visadev object
configureTerminator(v,"CR/LF")
% v is a visa object
v.Terminator = {"CR/LF" [10]};
% v is a visadev object
configureTerminator(v,"CR/LF",10)

For more information, see configureTerminator.

Set Up Callback Function

These examples show how to set up a callback function using the recommended functionality.

FunctionalityUse This Instead
% v is a visa object
v.BytesAvailableFcnCount = 5
v.BytesAvailableFcnMode = "byte"
v.BytesAvailableFcn = @mycallback

function mycallback(src,evt)
   data = fread(src,src.BytesAvailableFcnCount);
   disp(evt)
   disp(evt.Data)
end
    Type: 'BytesAvailable'
    Data: [1×1 struct]

    AbsTime: [2019 12 21 16 35 9.7032]
% v is a visadev object
configureCallback(v,"byte",5,@mycallback);
function mycallback(src,evt)
   data = read(src,src.BytesAvailableFcnCount);
   disp(evt)
end
  ByteAvailableInfo with properties:

    BytesAvailableFcnCount: 5
                   AbsTime: 21-Dec-2019 12:23:01
% v is a visa object
v.Terminator = "CR"
v.BytesAvailableFcnMode = "terminator"
v.BytesAvailableFcn = @mycallback

function mycallback(src,evt)
   data = fscanf(src);
   disp(evt)
   disp(evt.Data)
end
    Type: 'BytesAvailable'
    Data: [1×1 struct]

    AbsTime: [2019 12 21 16 35 9.7032]
% v is a visadev object
configureTerminator(v,"CR")
configureCallback(v,"terminator",@mycallback)

function mycallback(src,evt)
   data = readline(src);
   disp(evt)
end
  TerminatorAvailableInfo with properties:

                   AbsTime: 21-Dec-2019 12:23:01

For more information, see configureCallback.

See Also

Related Topics