Searching for Resources

From Agilent VISA.NET

Searching for Resources

When you open the default resource manager, you are opening a parent session that knows about all the other resources in the system. Since the resource manager session knows about all resources, it has the ability to search for specific resources and open sessions to these resources. You can, for example, search an interface for devices and open a session with one of the devices found.

Use the viFindRsrc function to search an interface for device resources. This function finds matches and returns the number of matches found and a handle to the resources found. If there are more matches, use the viFindNext function with the handle returned from viFindRsrc to get the next match:

viFindRsrc(sesn, expr, findList, retcnt,instrDesc);
.
.
viFindNext(findList, instrDesc);
.
.
viClose (findList);

The parameters are defined as follows.

Parameter

Description

sesn

The resource manager session.

expr

The expression that identifies what to search (see table below).

findList

A handle that identifies this search. This handle will then be used as an input to the viFindNext function when finding the next match.

retcnt

A pointer to the number of matches found.

instrDesc

A pointer to a string identifying the location of the match. Note that you must allocate storage for this string.

The handle returned from viFindRsrc should be closed to free up all the system resources associated with the search. To close the find object, pass the findList to the viClose function.

Use the expr parameter of  viFindRsrc to specify the interface to search. You can search for devices on the specified interface. Use the following table to determine what to use for your expr parameter.

Interface

expr Parameter

 

GPIB

GPIB[0-9]*::?*INSTR

 

VXI

VXI?*INSTR

 

GPIB-VXI

GPIB-VXI?*INSTR

 

GPIB and GPIB-VXI

GPIB?*INSTR

 

All VXI

?*VXI[0-9]*::?*INSTR

 

ASRL

ASRL[0-9]*::?*INSTR

 

All

?*INSTR

 

Note: Because VISA interprets strings as regular expressions, the string GPIB?*INSTR applies to both GPIB and GPIB-VXI devices.

Example: Searching the VXI Interface for Resources

This code sample searches the VXI interface for resources. The number of matches found is returned in nmatches, and matches points to the string that contains the matches found. The first call returns the first match found, the second call returns the second match found, etc. VI_FIND_BUFLEN is defined in the visa.h declarations file.

ViChar buffer [VI_FIND_BUFLEN];
ViRsrc matches=buffer;
ViUInt32 nmatches;
ViFindList list;
.
.
viFindRsrc(defaultRM, "VXI?*INSTR", &list, &nmatches, matches);
..
.
viFindNext(list, matches);
.
.
viClose(list);