Using Driver Sessions in TestStand
- Updated2024-10-16
- 3 minute(s) read
Using Driver Sessions in TestStand
The session management service manages instrument driver sessions that are associated with the pin map. Because this action relies on the pin map, you must first register your pin map with the pin map service.
Use the ProcessSetup and ProcessCleanup sequence file callbacks to efficiently initialize and close driver sessions for the steps that run as part of your MainSequence sequence. In the ProcessSetup sequence instrument sessions are reserved, opened, registered, and then unreserved. You must unreserve the sessions to make them available to individual measurements. In the ProcessCleanup sequence all registered sessions are reserved, closed, unregistered, and finally unreserved.
Accessing Sequence File Callbacks
Complete the following steps in TestStand to open the Sequences list and ensure the appropriate sequence file callbacks are visible.
- Select to open the Sequences tab.
- In the Sequences tab, right-click and select Sequence File Callbacks. The Select Callbacks dialog box appears.
- In the list of callbacks, select the ProcessSetup and ProcessCleanup callbacks.
- Click OK. The selected callbacks are listed in the Sequences tab.
- Click a sequence to select it for editing.
Creating the ProcessSetup
Sequence
In the ProcessSetup sequence, you must register your pin map with the pin map service. The Measurement Plug-In session manager service relies on pin map information to manage sessions and communicates directly with the pin map service to access a registered pin map and determine session requirements.
Use the Update Pin Map custom step to register the pin map with the pin map service. Complete the following steps to register your pin map:
- Double-click the Update Pin Map step in the Insertion Palette. An update pin map step is added to your sequence.
- Select the Update Pin Map step in the sequence and select the Update Pin Map tab to configure the pin map path.
- Specify the Pin Map Path. Type the path directly or click Browse and select the pin map file.
Complete the following steps to instantiate sessions for use by individual measurement steps:
- In a code module in the ProcessSetup sequence file callback, call the ReserveSessions() method to reserve all sessions. Specify an empty string for the pin_or_relay_names and instrument_type inputs to return session information for all pins connected to resources in the registered pin map file.
- Open the instrument sessions and detach the sessions. Use the session
information from the previous step to call the Initialize Measurement Plug-In APIs to open sessions for each instrument.
- In LabVEW, call Attach gRPC Session followed by Close Sessions.
- In Python, initialize the sessions with the initialization behavior set to ATTACH_TO_SESSION_THEN_CLOSE.
Note You must generally use grpc-enabled NI driver APIs to create driver sessions that can be shared between measurement services. - Call the RegisterSessions() method to signal to the session management service that you have initialized the driver sessions. This will enable future calls to the Session Management API to provide information to you about whether the sessions are currently open, and will allow you to later request a list of all open sessions.
- Call the UnreserveSessions() method to unreserve the sessions so that they can be reserved by individual measurement steps.
Creating the ProcessCleanup Sequence
- In a code module in the TestStand ProcessCleanup sequence file callback, call the ReserveAllRegisteredSessions() method to retrieve a list of open instrument sessions and reserve those sessions for closure.
- Close and detach the instrument sessions. You can iterate through the list
of driver sessions and use the Measurement Plug-In API to
close each session.
- In LabVEW, call Attach gRPC Session followed by Close Sessions.
- In Python, initialize the sessions with the initialization behavior set to ATTACH_TO_SESSION_THEN_CLOSE.
- Call UnregisterSessions() to unregister the sessions.
- Call the UnreserveSessions() method to unreserve the sessions so that they are free for other clients.