Understanding the Driver Session Management Service

Driver session management, session access control, and pin map integration for supported NI driver software.

The Measurement Plug-Ins session management service manages driver sessions and controls access to those sessions for supported NI driver software.

The session management service uses driver or channel information from a pin map to identify the appropriate sessoins for NI driver software. This approach enables pin-aware measurements and avoids direct references to I/O channels.

The session management service tracks session registration and controls access to driver sessions. This behavior ensures that only one measurement service accesses a driver session at a time.

This section describes the behavior and data flow for session management in Measurement Plug-Ins. The Measurement Plug-Ins API simplifies session management and provides the recommended method for managing sessions for supported NI driver software.

Figure 2. Pin Map, Session, and Instrument Call Data Flow


  1. The software application registers the pin map with the NI Pin Map Service pin map service.
  2. The software application calls the Measurement Plug-Ins session management service to instantiate required instrument driver sessions. The application reserves, opens, registers, and finally unreserves the driver sessions.
  3. The application calls your measurement service, which executes the measurement logic.
  4. The measurement service calls the Measurement Plug-Ins session management service to reserve a required driver session. For GPIB, serial, or LXI instruments, use NI-VISA to perform session management. The Measurement Plug-Ins session management service returns session information, including session status.
  5. The measurement service initializes instrument driver sessions, either by creating new sessions on the NI gRPC Device Server or attaching to an existing session.
  6. Your measurement service makes instrument calls via NI instrument drivers that support gRPC.
    • If a driver does not provide a gRPC interface you can use gRPC directly to communicate with your instrument. In Python, use the grpcio module. In LabVIEW, use grpc-labview (available in github). Refer to the examples for NI gRPC Device Server for additional implementation details.
    • For GPIB, serial, or LXI instruments, use NI-VISA to control your instrument.
  7. Your measurement service performs data analysis and updates the measurement UI.
  8. The measurement service closes or detaches instrument driver sessions.
  9. Your measurement service calls the Measurement Plug-Ins session management service to unreserve the instrument driver session once the measurement completes.
  10. Your measurement service completes execution and returns values to the software application.
  11. The software application reserves, closes, unregisters, and unreserves the instrument driver sessions.

Controlling Access to Driver Sessions

The Measurement Plug-Ins session management service provides a reservation mechanism to ensure that only one measurement at a time has access to each driver session. This prevents measurements from changing the state of an instrument that is in use by another measurement.

The Measurement Plug-Ins session management service reserves each driver session when a measurement retrieves driver session information via the ReserveSessions() or ReserveAllRegisteredSessions() methods. If a driver session is already reserved by another measurement, these methods wait until either the driver session becomes unreserved or the timeout expires.

Accessing Open Driver Sessions

The Measurement Plug-Ins session management service ensures that only one measurement at a time has access to each driver session. This prevents measurements from changing the state of an instrument that is in use by another measurement.

To attach to a driver session within your measurement logic, first ensure that you have sessions registered with the Session Management service. Refer to Using Driver Sessions in TestStand for more information.

Within your measurement logic, use the ReserveSessions() method to access the driver session information.

Some measurements must use the session_exists Boolean to determine whether to perform one-time setup.

  • NI-DAQmx—Create or add channels to the task only when initializing a new task on the server (and session_exists is False).
  • NI-Digital Pattern Driver—Loading files (for example, specifications, patterns, or pin maps) into the session will produce an error if the files were previously loaded. Checking that session_exists is False is a good way to avoid loading files multiple times. You can also explicitly unload files.
  • Table 12. Boolean value descriptions for session_exists
    Value of session_exists Description Notes
    false The driver session has not been initialized. Your measurement logic should initialize (and later close) the driver session.
    true The driver session has been initialized. Your measurement logic should not attach or detach to the driver session.

    Be sure to call the UnreserveSessions() method when your measurement is finished using a driver session. You must call this method even when an exception or error causes your measurement to exit to ensure that sessions are not reserved indefinitely. If you are using LabVIEW, the Measurement Plug-Ins LabVIEW API handles this requirement automatically.

    If a measurement service crashes or closes while it has reserved a driver session, subsequent reservations will trigger the specified reserve session timeout behavior. In order to recover, you must restart the discovery service as well as any manually-launched measurements.

    Supply a TimeoutInMilliseconds parameter to a reserve method to specify a behavior while waiting for the reservation to succeed:

    Table 13. Reserve Session Timeout Behavior
    Value Behavior
    -1 Specifies no timeout. The measurement will wait indefinitely until the session can be reserved.
    0 (default) Specifies that an exception occurs immediately if the session cannot be reserved.
    Any positive numeric value Specifies a timeout, in milliseconds, after which an exception occurs if the session cannot be reserved.

    Sharing Driver Sessions between Multiple Measurement Services

    This topic describes generally how a measurement service should connect to an instrument session depending on the instrument or instrument driver in use.

    Measurement Plug-Ins supports session management for a subset of NI driver software. The following figure lists those drivers and their support for gRPC, including:

    • Whether a driver is supported by NI gRPC Device Server
    • Whether a driver provides a native gRPC interface for a supported software language

    Use the criteria in this table to determine the suitability of any driver for your application. Drivers which do not provide native gRPC support must make explicit gRPC calls to the NI gRPC Device Server.

    Table 14. gRPC support in target drivers (as of 2024 Q1, earliest supported driver versions listed for each feature)
    Supported NI driver software Driver supported by NI gRPC Device Server Driver version implements native gRPC interface (Python) Driver version implements native gRPC interface (LabVIEW)
    NI-DAQmx 2023 Q3
    NI-DCPower 2023 Q1 2023 Q1
    NI-Digital Pattern Driver 2023 Q1 2023 Q2
    NI-DMM 2023 Q1 2023 Q2
    NI-FGEN 2023 Q1 2023 Q2
    NI-SCOPE 2023 Q1 2023 Q2
    NI-SWITCH 2023 Q1
    NI-VISA (GPIB, serial, LXI interfaces) ✔ (as of 2024 Q1)

    NI-DCPower, NI-Digital Pattern Driver, NI-DMM, NI-FGEN, NI-SCOPE, NI-SWITCH

    Measurement services must make gRPC calls to the NI gRPC Device Server in order to create or attach to a session, perform the measurement, and destroy or detach from the session. Use the Measurement Plug-Ins API to handle session management calls for these drivers.

    1. In Python, the driver API will make the gRPC calls for you if you specify the grpc_options parameter for the Session constructor.
    2. In LabVIEW, the driver API will make the gRPC calls for you if you use the gRPC-specific Initialize/Attach VIs.

    NI-DAQmx

    Measurement services should make explicit gRPC calls to the NI gRPC Device Server in order to create or attach to a task, perform the measurement, and destroy or detach from the task.

    NI-VISA

    Instruments connected via GPIB, serial, or LXI interfaces can use NI-VISA for session management. Registering the session ensures that only one measurement service communicates with the instrument at any given time. For an example, refer to the Keysight 34401A DMM Measurement example files.