Main Content

visadevfind

Find VISA device connections

Since R2024a

    Description

    example

    V = visadevfind finds existing VISA device connections and returns an array of objects corresponding to each connection.

    example

    V = visadevfind(Name=Value) finds VISA device connections with property values matching those specified by one or more name-value arguments. For instance, V = visadevfind(Tag="Scope") returns existing connections whose Tag property is set to "Scope".

    Examples

    collapse all

    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 subsequently 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

    You can assign a tag to a connection and use that tag with visadevfind to access the connection later. Such tags are useful when you open a connection in one function and use a different function to perform operations on the connection. Tags are also useful for locating and accessing connections in app callbacks. To set the tag value, use the Tag property of the VISA interface object.

    Create two VISA device connections, assigning values to the Tag property.

    scopeResource = "USB0::0x2A8D::0x0386::CN59206154::0::INSTR";
    v1 = visadev(scopeResource,Tag="Scope");
    analyzerResource = "TCPIP0::K-N9040B-91124.dhcp.mathworks.com::inst0::INSTR";
    v2 = visadev(analyzerResource,Tag="Analyzer");

    Find the connection with the tag "Analyzer".

    V = visadevfind(Tag="Analyzer")
    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"
    

    Input Arguments

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: visadevfind(Type="gpib",Tag="Scope") returns existing VISA-GPIB device connections whose Tag property is set to "Scope".

    For visadev, you can use one or more of the interface properties listed on visadev Properties as name-value arguments to specify characteristics of the connections you want to find.

    Output Arguments

    collapse all

    VISA device connections, returned as a VISA interface object (see visadev) or an array of such objects. If you call visadevfind with no Name=Value pairs, V contains all existing connections. Otherwise, V contains all connections whose properties match the values you specify with Name=Value pairs.

    V is empty if:

    • There are no existing VISA device connections.

    • No existing connections match the specified property values. For instance, if you specify Tag="Scope", and there is no existing connection whose Tag property is "Scope", then V is empty.

    • You try to match a property that doesn't exist in visadev Properties. For instance, visadevfind(Speed=14400) returns an empty array, because the VISA interface does not have a Speed property.

    • visadevfind finds existing VISA device interfaces. To get a list of all available devices whether or not connections to them exist, use visadevlist.

    Version History

    Introduced in R2024a