Measurement Development and Usage Best Practices
- Updated2024-10-16
- 3 minute(s) read
Measurement Development and Usage Best Practices
This topic describes patterns that may be useful as you develop or use a measurement.
- For drivers that support cancellation or asynchronous abort, you must still handle the gRPC cancellation and forward it to the driver API.
- For drivers that do not support cancellation or asynchronous abort, break long API calls and waits into shorter iterations and handle cancellation events between iterations.
For best performance, use the Measurement Plug-In API to manage sessions whenever possible. Consult the examples for the latest Measurement Plug-In release to understand how to structure calls to the API and efficiently configure a measurement in TestStand. The following text describes general principles and best practices associated with session management.
Calling the ReserveSessions() method instructs the session management service to block access to a session. If you reserve an instrument session, you must unreserve it before it is accessible to other callers.
- Be sure to handle error cases where an error occurs after a session is reserved but before the session is used.
- Make use of the TimeoutInMilliseconds parameter.
- Do not reserve sessions for pins that your measurement does not use.
- Reserve a session before you attempt to register or unregister it.
- Do not register a session if you did not open it.
- Do not close a session if you did not register the session.
The session management service depends on the NI gRPC Device Server (gRPC-device). Once a gRPC-device session is opened it is cached and subsequent open calls do not create new sessions. Closing a gRPC-device session closes the underlying sessions. For best performance, reuse sessions whenever possible rather than creating new sessions.
For best performance, use the Measurement Plug-In API to manage sessions whenever possible. Consult the examples for the latest Measurement Plug-In release to understand how to structure calls to the API and efficiently configure a measurement in TestStand. The following text describes general principles and best practices associated with session management. Consider the following practices and tips while working with sessions in TestStand.
- Reserve, open, and register all instrument sessions in the ProcessSetup sequence to initialize sessions once and reduce overhead for individual measurements in the test sequence.
- Specify the InstrumentTypeId parameter when calling ReserveSessions() or ReserveAllRegisteredSessions() to limit reserved sessions to a specific instrument type.
- Do not use ReserveAllRegisteredSessions() before opening and registering instrument sessions.
Measurement steps in TestStand cache measurement service connections. If you restart the measurement service while the sequence is open, you may invalidate cached connections and produce a networking error. If a measurement step returns a networking error (such as "connection refused"), the following actions may clear the error:
- Select .
- Refresh the measurement parameters.
Enabling monitoring in TestStand may impact measurement performance. Do not enable monitoring unless it is necessary for your application.