Measurement Development and Usage Best Practices

This topic describes patterns that may be useful as you develop or use a measurement.

  • Cancellation—Not all drivers handle cancellation in the same way.
    • 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.
  • Progressive UI Updates—For best performance with continuously running measurements, maximize the time between UI measurement data updates. Continuous, rapid UI updates while a measurement runs may reduce measurement performance.
  • Python Decorators—Decorators must be listed in the same order as the measurement function signature parameters and return values.
  • Session Management

    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.
    Calling the RegisterSessions() method indicates that the instrument driver session is open. This information is used by other callers to determine if they should close the instrument session when they are done with it.
    • 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.
    In general, you should not register or unregister sessions within your measurement logic. Instead, you should normally register and unregister sessions as part of the setup or cleanup phases of your execution framework. For example, refer to Using Driver Sessions in TestStand.

    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.

  • TestStand Best Practices

    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 File » Unload All Modules.
    • Refresh the measurement parameters.

    Enabling monitoring in TestStand may impact measurement performance. Do not enable monitoring unless it is necessary for your application.

  • Log Files—Log files can be found in C:\ProgramData\National Instruments\MeasurementPlugin\Logs.