Main Content

Transition Your Code to visadev Interface

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

Removed Functionality

The memmap, mempeek, mempoke, memread, memunmap, and memwrite functions and the MappedMemoryBase, MappedMemorySize, MemoryBase, MemoryIncrement, MemorySize, MemorySpace properties will be removed. VISA-VXI register-based communication is not available in the updated interface.

The TriggerFcn, TriggerLine, and TriggerType properties will be removed. You can send a trigger message to VISA-GPIB or VISA-VXI instruments using visatrigger in the updated interface.

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 in the updated interface.

The BytesAvailableFcnCount, BytesAvailableFcnMode, BytesAvailableFcn, BytesAvailable, OutputEmptyFcn, and InterruptFcn 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 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.

Find Existing VISA Device Connections

instrfind and instrfindall will be removed. Use visadevfind instead. (since R2024a)

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");

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

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.

Disconnect VISA Device Connection

The fclose function is not available in the updated interface. To disconnect a VISA device, use clear or delete instead, depending upon whether you are working in a single workspace or multiple workspaces. For details, see the following examples on the visadev reference page:

See Also

Related Topics