Contenido principal

visadev

R2026b

Create connection to device using VISA

    Description

    A visadev object represents a connection to a device or instrument using the VISA interface. The following interface types are supported: TCP/IP (using VXI11 and HiSLIP), TCP/IP Socket, USB, GPIB, Serial, VXI, and PXI. Identify devices available to connect to using visadevlist. Then, connect to the device or instrument using visadev.

    Creation

    Description

    deviceObj = visadev(resourceName) creates a connection to a device using its VISA resource name. Establish a connection using an installed VISA driver. If you have multiple VISA drivers installed, MATLAB® uses the preferred VISA set in your VISA vendor's configuration utility software.

    example

    deviceObj = visadev(resourceAlias) creates a connection to a device using its VISA alias, if it has one. If the configuration utility does not yet recognize the device, you cannot connect using the alias and must use the resource name.

    example

    deviceObj = visadev(resourceName,Identification=identificationCommand) sends a custom identification command to query the device instead of the standard *IDN? query. Use this syntax for devices that use a proprietary identification command. (since R2026b)

    example

    Input Arguments

    expand all

    VISA resource name, specified as a character vector or string scalar. You can identify the name of the resource you want to connect to using the information returned by visadevlist. This input sets the ResourceName property.

    Example: gpibdev = visadev("GPIB0::5::INSTR") connects to the GPIB device specified by the VISA resource name GPIB0::5::INSTR.

    Data Types: char | string

    VISA alias associated with a resource, specified as a character vector or string scalar. Identify the alias of the resource you want to connect to using the information returned by visadevlist. You can use an alias only if an alias is assigned using the VISA vendor’s configuration utility software. This input sets the Alias property.

    Example: serialdev = visadev("COM4") connects to the serial device specified by the VISA resource alias COM4.

    Data Types: char | string

    Identification command sent to the device during connection, specified as a string scalar or character vector. The device responds to this command, and the response populates the Vendor and Model properties.

    Some instruments use a proprietary identification command instead of the IEEE 488.2 standard *IDN? query. Use this argument to specify the correct command for your device.

    Specify an empty string ("") to skip identification entirely. When you skip identification, Vendor and Model properties are empty. The device object is still fully connected and you can perform read and write operations regardless of the identification setting.

    When you specify a custom identification command, the function bypasses the cached resource information and queries the device directly.

    Example: v = visadev("GPIB0::5::INSTR",Identification="ID?") connects to the device and uses the ID? command to identify it.

    Data Types: char | string

    Output Arguments

    expand all

    VISA device connection, returned as a visadev object. The object type depends on the interface of the connected device, such as GPIB, USB, TCPIP, or Serial.

    Properties

    See visadev Properties for a full list of properties.

    Object Functions

    readRead data from VISA resource
    readlineRead line of ASCII string data from VISA resource
    readbinblockRead one binblock of data from VISA resource
    writeWrite data to VISA resource
    writelineWrite line of ASCII data to VISA resource
    writebinblockWrite one binblock of data to VISA resource
    writereadWrite command to VISA resource and read response
    configureTerminatorSet terminator for ASCII string communication with VISA resource
    flushClear buffers for communication with VISA resource
    visastatusCheck status of VISA resource
    visatriggerSend trigger to GPIB or VXI instruments
    setDTRSet serial DTR pin
    setRTSSet serial RTS pin
    getpinstatusGet serial pin status

    Examples

    collapse all

    Search for and establish a connection to your VISA resource.

    Search for available VISA resources.

    resourceList = visadevlist
    resourceList =
    
      6×6 table
    
                            ResourceName                         Alias                  Vendor               Model       SerialNumber     Type 
             __________________________________________    _________________    ______________________    ___________    ____________    ______
    
        1    "USB0::0x0699::0x036A::CU010105::0::INSTR"    "NI_SCOPE_4CH"       "TEKTRONIX"               "TDS 2024B"    "CU010105"      usb   
        2    "TCPIP0::169.254.2.20::inst0::INSTR"          "Keysight_33210A"    "Agilent Technologies"    "33210A"       "MY57003523"    tcpip 
        3    "ASRL1::INSTR"                                "COM1"               ""                        ""             ""              serial
        4    "ASRL3::INSTR"                                "COM3"               ""                        ""             ""              serial
        5    "GPIB0::5::INSTR"                             "FGEN_2CH"           "Agilent Technologies"    "33522B"       "MY52800145"    gpib  
        6    "GPIB0::11::INSTR"                            "OSCOPE_2CH"         "TEKTRONIX"               "TDS 1002"     "0"             gpib  
    

    Create a connection to the first resource over the VISA-USB interface using the resource name.

    usbdev = visadev("USB0::0x0699::0x036A::CU010105::0::INSTR")
    usbdev = 
    
      USB with properties:
    
             ResourceName: "USB0::0x0699::0x036A::CU010105::0::INSTR"
                    Alias: "NI_SCOPE_4CH"
                   Vendor: "TEKTRONIX"
                    Model: "TDS 2024B"
    
      Show all properties, functions
    

    Alternatively, you can connect to a device using its alias.

    serialdev = visadev("COM1")
    serialdev = 
    
      Serial with properties:
    
             ResourceName: "ASRL1::INSTR"
                    Alias: "COM1"
                     Port: "ASRL1"
                 BaudRate: 9600
    
      Show all properties, functions
    

    When you use visadev in a script or at the MATLAB command line, the result is a connection represented by an object in the MATLAB workspace.

    analyzerResource = "TCPIP0::K-N9040B-91124.dhcp.mathworks.com::inst0::INSTR";
    V = visadev(analyzerResource);
    V = 
    
      TCPIP with properties:
    
             ResourceName: "TCPIP0::K-N9040B-91124.dhcp.mathworks.com::inst0::INSTR"
                    Alias: ""
                   Vendor: "Keysight Technologies"
                    Model: "N9040B"
                  LANName: "inst0"
        InstrumentAddress: "172.31.173.155"
                      Tag: ""
    

    When no references to the same connection exist in other variables, you can disconnect the device by clearing the workspace variable.

    clear(V)

    Use visadevfind to confirm that the connection is closed.

    visadevfind
    ans =
    
         []

    When you have a visadev connection that exists in the MATLAB workspace or is saved as a class property or app property, the visadev object might not be accessible in a different function or app callback. In this case, you can use visadevfind to find and delete the connection.

    V = visadevfind
    V = 
    
      TCPIP with properties:
    
             ResourceName: "TCPIP0::K-N9040B-91124.dhcp.mathworks.com::inst0::INSTR"
                    Alias: ""
                   Vendor: "Keysight Technologies"
                    Model: "N9040B"
                  LANName: "inst0"
        InstrumentAddress: "172.31.173.155"
                      Tag: "Analyzer"
    

    To close this connection, delete V.

    delete(V)

    This command deletes the visadev object and disconnects the device. If you want to reconnect to the device, you must create a new connection with visadev.

    After the deletion, calling visadevfind confirms that there are no existing connections.

    visadevfind
    ans =
    
         []

    Note that the variable V is still present in the workspace, but it is now an invalid handle.

    V
    V = 
    
      handle to deleted TCPIP

    The variable persists after deletion of the interface because visadev is a handle object. (For more information about this type of object, see Handle Object Behavior.) You can use clear to remove the invalid handle from the workspace.

    clear V

    Since R2026b

    Connect to a device that uses a proprietary identification command instead of the standard *IDN? query.

    Connect to a GPIB device using a custom identification command.

    v = visadev("GPIB0::5::INSTR",Identification="ID?")
    v =
    
      GPIB with properties:
    
             ResourceName: "GPIB0::5::INSTR"
                    Alias: "FGEN_2CH"
                   Vendor: "Agilent Technologies"
                    Model: "33522B"
    
      Show all properties, functions
    

    Alternatively, skip identification to connect without querying the device.

    v = visadev("GPIB0::5::INSTR",Identification="")
    v =
    
      GPIB with properties:
    
             ResourceName: "GPIB0::5::INSTR"
                    Alias: ""
                   Vendor: ""
                    Model: ""
    
      Show all properties, functions
    

    Version History

    Introduced in R2021a

    expand all