Skip to content

MeasurementLink Support for Python v1.3.0

Compare
Choose a tag to compare
@dixonjoel dixonjoel released this 12 Jan 17:38
· 1 commit to releases/1.3 since this release
ed1f7c7

What's Changed

  • Simplified session management (#386 #389 #402 #426 #429 #432 #433 #436 #438 #440 #442 #446 #466 #469 #480 #481 #482)
    • The MeasurementContext class now provides reserve_session(s) methods, eliminating the need to explicitly instantiate a SessionManagementClient and pass measurement_service.context.pin_map_context to it. Example:
      with measurement_service.context.reserve_sessions(pin_names) as reservation:
          ...
    • The reserve_session(s) methods now accept a single pin name in addition to a list of pin names.
    • The reservation classes now provide initialize_${driver}_session(s) methods for initializing modular instrument sessions. These methods are designed to be used in a with block. They yield one or multiple SessionInformation objects, which now contain a reference to the session object.
      Example:
      with reservation.initialize_nidcpower_sessions() as session_infos:
          for session_info in session_infos:
              session_info.session.channels[session_info.channel_list].initiate()
    • The reservation classes now provide get_${driver}_connection(s) methods for querying connections between pins and instrument channels. These methods return one or multiple Connection objects, which also contain a reference to the instrument session object.
      Example:
      vdd_connection = reservation.get_nidcpower_connection("Vdd")
      measurement = vdd_connection.session.channels[vdd_connection.channel_name].measure_multiple()
    • The reservation classes also provide:
      • create_nidaqmx_task(s) and get_nidaqmx_connection(s) methods for NI-DAQmx.
      • Generic initialize_session(s) and get_connection(s) methods for custom session types, such as instrument drivers based on VISA.
    • The new reservation methods have type hints, which enable LSP-enabled text editors such as VS Code and PyCharm to auto-complete references to driver-specific session objects. For example, reservation.get_nidmm_connection(pin).session. should auto-complete by displaying the methods for the nidmm.Session class. To support these type hints, the new methods use generic protocol classes TypedSessionInformation[TSession] and TypedConnection[TSession].
    • The reservation.session_info property now includes the session object(s) in the returned SessionInformation objects, if they have been created. However, clients are encouraged to use the type-safe TypedSessionInformation[TSession] objects returned from reservation.initialize_${driver}_session(s).
    • TestStand code modules can also use the new initialize_${driver}_sessions methods. These methods accept an optional initialization_behavior enum parameter, which has INITIALIZE_SESSION_THEN_DETACH and ATTACH_TO_SESSION_THEN_CLOSE enum values designed for this use case.
    • The example measurements and TestStand code modules have been updated to use the new session management API. As such, most of the examples now require ni-measurementlink-service version 1.3.0 or later. For example measurements that work with previous versions, use the examples zip file provided with that release on GitHub.
  • Configuration via .env files (#421 #425 #441)
    • You can now configure ni-measurementlink-service settings by setting environment variables or creating a .env file.
      • A .env file is a text file containing environment variables in the form VAR=value.
      • The .env may be located in the measurement service's current working directory or one of its parent directories. For example, you can place a .env file at the root of this GitHub repo, in the examples/nidcpower_source_dc_voltage directory, or in C:\ProgramData\National Instruments\MeasurementLink for configuring statically registered services.
      • If the current working directory and its parents do not contain a .env file, the search falls back to the script/EXE path (if there is one) or the path of the Python module calling into ni-measurementlink-service (to support TestStand code modules).
      • Support for parsing the .env file is implemented by the 3rd party python-decouple package.
    • The modular instrument initialize_${driver}_sessions(s) methods allow you to use .env settings to override the IVI option string and specify simulation options.
      Example:
      # Add this to your .env file to enable NI-DCPower simulation with PXIe-4141 instruments.
      MEASUREMENTLINK_NIDCPOWER_SIMULATE=1
      MEASUREMENTLINK_NIDCPOWER_BOARD_TYPE=PXIe
      MEASUREMENTLINK_NIDCPOWER_MODEL=4141
      
    • The example measurements no longer have a hardcoded USE_SIMULATION constant that you must edit to enable/disable simulation. To enable simulation for all example measurements, copy .env.simulation to .env in the 'examples' directory of this Git repo.
    • The VISA example measurements use python-decouple directly to read MEASUREMENTLINK_VISA_DMM_SIMULATE from the .env file.
    • There are a few other .env settings for overriding the NI gRPC Device Server configuration and enabling feature toggles. For a complete reference, see .env.sample in the 'examples' directory of this Git repo.
  • Make gRPC extensions public (#545)
    • The GrpcChannelPool class is now provided by the ni_measurementlink_service.grpc.channelpool module. It is still aliased into ni_measurementlink_service.measurement.service for compatibility with existing code.
    • The ClientLogger and ServerLogger interceptor classes are now provided by the ni_measurementlink_service.grpc.loggers module. GrpcChannelPool automatically adds a ClientLogger and MeasurementService automatically adds a ServerLogger, but these helper classes may be useful to clients in other situations.
  • Python 3.12 support (#427)
    • ni-measurementlink-service is now tested with Python 3.12.
    • No code changes were required, so previous releases should work with Python 3.12 as well.
  • Bug fixes
    • Some cosmetic issues with example measurement UI panels have been fixed. (#420 #424 #435)
    • Copying an example measurement into a separate Git repo no longer causes ni-python-styleguide to reorder its import directives. (#374 #443)
    • ServerCallLogger no longer incorrectly logs OK when the call is canceled. (#370 #462)
    • Fixed several APIs that leak internal types. (#375 #394 #396 #437)
      • The DiscoveryClient class is now publicly available via the ni_measurement_service.discovery sub-package.
      • The DiscoveryClient.register_measurement_service method has been deprecated in favor of a more general register_service API that supports other service types and registering multiple services.
      • In several public and internal classes, attributes and properties that should not be public have been deprecated and will be removed in a future release.
      • Deprecated attributes, methods, and properties generate deprecation warnings, which are enabled by default for pytest tests but not for standalone Python scripts.
    • In the examples and generator templates, start.bat now assumes you are using an in-project virtualenv. (#416 #417)
    • The DiscoveryClient class now reads the MeasurementLink installation directories from the Windows registry instead of environment variables, eliminating the need to use passenv when testing with Tox. (#483 )
    • DeprecationWarning raised due to Pathlib.Path (#514)
    • Fix deserialization of large messages (>= ~30 fields) (#554)
  • Example improvements
    • The VISA examples now have a visa_dmm instrument driver rather than using VISA directly. (#439, #447)
    • The reservation timeout and instrument type ID parameters have been removed from the examples because the defaults are sufficient. (#393)
    • Update example TestStand sequences to use the new Update Pin Map custom step (#538 #539 #540 #541 #547 #551 #550 #553)
      • MeasurementLink 2024Q1 introduces a new TestStand step, Update Pin Map, which sets the active pin map for the sequence execution.
      • The teststand_pin_map.py code module and related code in _helpers.py have been deleted.
      • The example TestStand sequences now require MeasurementLink 2024 Q1 or later and will not work with older versions.
      • Existing TestStand sequences should continue to work with MeasurementLink 2024 Q1 or later.
    • Add gRPC support to VISA examples (#525)
    • Remove streaming-specific examples (#536)
      • Remove sample_streaming_measurement and ui_progress_updates because the Game of Life example demonstrates this feature.
      • Add cancellation to the Game of Life example.

New Contributors

For More Details, see Version 1.3.0 Changes

Full Changelog: 1.2.0...1.3.0