Why Use Instrument Sessions?
- Updated2025-03-28
- 2 minute(s) read
Why Use Instrument Sessions?
Instrument sessions are useful when you must share instrument API handles within a single process among loosely coupled software components. A test management system is an example of a system that can benefit from instrument sessions.
Using named instrument sessions can include the following advantages:
- Reduced Coupling—You do not have to pass instrument handle variables among software components. Instead, each component specifies a logical instrument name to obtain a session. Components then acquire the API handle from the session. Because you specify a logical instrument name to access a session, components that are not explicitly connected to each other can access the same session and thereby share an API handle. Because the session initializes and closes the API handle as needed, components that use the session do not need to be aware of the relative order in which they execute.
- Reduced Programming Language Barriers—Code modules written in different languages can share the same session without passing handles that might not easily convert among languages.
- Lifetime Control—Because instrument sessions are ActiveX objects with reference counts, you can tie the lifetime of the session to the lifetime of an ActiveX reference variable and eliminate the need to explicitly close the instrument in languages that support ActiveX reference variables. Multiple variables can reference the same session. The session closes when its last reference releases. Because a session lives as long as a reference to it exists, you do not have to coordinate the lifetime of the session among multiple threads or processes that use it.
- Efficiency and Correctness—A session initializes the API handle only when necessary. For example, if a component uses a logical instrument name and calls a subcomponent that uses the same logical name, the subcomponent can share the session that its caller initializes. Sharing the session avoids the overhead of initializing a second API handle. By sharing a session, you also avoid the possibility of using a second API handle with the same instrument resource, which might invalidate the internal state of the first API handle.
-
Virtual Instrument Selection—You can query Session Manager to obtain a list of logical and/or virtual instrument names from which to make a selection. You can also narrow the query to a subset of the available session names. For example, you might make one of the following queries:
- All virtual instrument and/or logical names for sessions that provide an instrument API handle to an IVI Switch class driver.
- All virtual instrument and/or logical names for sessions that provide an instrument API handle for a specific VXIplug&play driver.
Note
Although instrument sessions are ActiveX objects, the underlying instrument handles, specifically VISA, VXIplug&play, IVI C, and NI Switch Executive, are not valid across processes. For example, you cannot use an IVI C-based handle that a step in the TestStand process creates in a VI code module that executes using the LabVIEW development system process.