| Using VISA.NET > API Structure > Resource Managers and the GRM |
Given a resource descriptor uniquely identifying the hardware resource to which a program needs to connect, a resource manager class creates a corresponding session to enable communication with that resource. A resource manager can also provide additional information about connected resources.
The IResourceManager interface, defined in the Ivi.Visa namespace, consists of three methods:
The Keysight ResourceManager class can find, parse, and open resource descriptors for all of the resources that are configured on the system. The list of resource descriptors found by the resource manager depends on which instruments and interfaces are discovered by the Instrument Discovery Service: Refer to the IO Libraries Suite help for details on how the Discovery Service finds and reports connected resources. A resource must be shown in Keysight Connection Expert for VISA.NET to open a connection to it.
![]() |
Keysight VISA.NET, including the resource manager, does most of its work by delegating to the Keysight VISA implementation. VISA.NET delegates all of the low-level communication with an instrument or other resource to Keysight VISA. The significant exception is that all of the formatting, parsing, and buffer management related to Formatted I/O is implemented in the IVI provided Formatted I/O class, Ivi.Visa.FormattedIO, which uses Keysight VISA.NET Raw (unformatted) I/O to send and receive data from a resource. Formatting is not delegated to VISA, although Keysight VISA.NET Raw I/O does delegate to Keysight VISA. For 32-bit operation, VISA.NET delegates to the Keysight VISA DLL in the standard 32-bit Windows system directory. For 64-bit operation, VISA.NET delegates to the Keysight VISA DLL in the standard 64-bit Windows system directory. |
Use the Open method to open a connection to an instrument and get a reference to the session. The first argument to Open is the resource descriptor. Other arguments include the access mode (related to locking and access control), a default timeout, and as an output, a status argument that reports conditions related to a successful completion of the method call. The following code snippet shows an Open call for the instrument aliased by MyInstr.
| Open with Keysight ResourceManager |
Copy Code |
|---|---|
2000); | |
In this case the instrument must be connected via GPIB, or the constructor will fail. Assuming that the alias MyInstr is mapped to a GPIB instrument, we know that any returned session will derive from IGpibSession, and that the cast will work. (Refer to the discussion of session types in Resources and Sessions.)
If your alias refers to a USB, LAN, or serial connection, you must change the sample by casting the IVisaSession reference returned by Open to UsbSession, TcpipSession, or SerialSession respectively. You can find the address of a connected instrument and create an alias for the instrument in the Keysight Connection Expert utility.
In addition to the Keysight.Visa.ResourceManager class, VISA.NET also provides the Ivi.Visa.GlobalResourceManager class. The global resource manager (or GRM) consults all installed VISA.NET implementations to do its work. The GRM provides a way of opening and using a session while only referencing the Ivi.Visa namespace; this is important if you want your program to be portable across different vendors' VISA.NET implementations.
Here is what the Open call looks like when using the GRM.
| Open with GRM |
Copy Code |
|---|---|
IGpibSession session = (IGpibSession)GlobalResourceManager.Open("MyInstr", Ivi.Visa.AccessModes.None, 2000); | |
This example shows an Open call with exactly the same parameters as the previous example, but note these key differences:
MyInstr. If it finds an implementation that can make the connection, it asks that implementation for a session to the instrument, and returns that session to the calling program. In this case, since we know that the alias MyInstr is mapped to a GPIB instrument, we are guaranteed that any returned session will derive from IGpibSession, and that the cast will work (refer to the discussion of session types in Resources and Sessions). In other words, the IVI GRM provides an additional level of indirection that allows the second example to work with a variety of VISA.NET implementations, including Keysight VISA.NET.
If more than one installed VISA.NET implementation is able to make a connection to an instrument at the specified address (which would be the norm for instruments connected via USB or LAN, for example), then the GRM Open method uses a conflict resolution process to specify which implementation is preferred. You can specify the preferred VISA.NET for USB or LAN using the VISA Conflict Manager in Keysight Connection Expert, which is also installed with Keysight IO Libraries Suite.
The sample code assumes a GPIB connection. If your alias (MyInstr) refers to a USB, LAN, or serial connection, you must change the sample by casting the IVisaSession reference returned by Open to IUsbSession, ITcpipSession, or ISerialSession respectively. You can find the address of a connected instrument and create an alias for the instrument in the Keysight Connection Expert utility.
The above code samples are specific to particular hardware interface types. Assuming that MyInstr aliases a GPIB instrument, the samples demonstrate casting the session returned by the Open call to either GpibSession in the Keysight resource manager case, or IGpibSession in the GRM case. However, since GPIB, USB, LAN, and serial sessions are all message-based sessions, and since the sample only uses generic message-based features of the sessions, it could easily be made even more general by casting to IMessageBasedSession. Here is what the Open call looks like when using the GRM and casting to IMessageBasedSession.
| Open cast to IMessageBasedSession |
Copy Code |
|---|---|
IMessageBasedSession session = (IMessageBasedSession)GlobalResourceManager.Open("MyInstr", Ivi.Visa.AccessModes.None, 2000); | |