ni_measurementlink_service
releases/1.0
  • API Reference
    • ni_measurementlink_service
      • Subpackages
        • ni_measurementlink_service.measurement
          • Submodules
            • ni_measurementlink_service.measurement.info
            • ni_measurementlink_service.measurement.service
              • Module Contents
                • Classes
                  • MeasurementContext
                    • MeasurementContext.grpc_context()
                    • MeasurementContext.pin_map_context()
                    • MeasurementContext.add_cancel_callback()
                    • MeasurementContext.cancel()
                    • MeasurementContext.time_remaining()
                    • MeasurementContext.abort()
                  • GrpcChannelPool
                    • GrpcChannelPool.__enter__()
                    • GrpcChannelPool.__exit__()
                    • GrpcChannelPool.get_channel()
                    • GrpcChannelPool.close()
                  • MeasurementService
                    • MeasurementService.register_measurement()
                    • MeasurementService.configuration()
                    • MeasurementService.output()
                    • MeasurementService.host_service()
                    • MeasurementService.close_service()
                    • MeasurementService.__enter__()
                    • MeasurementService.__exit__()
                    • MeasurementService.get_channel()
                  • MeasurementContext
                    • grpc_context
                    • pin_map_context
                    • add_cancel_callback
                    • cancel
                    • time_remaining
                    • abort
                  • GrpcChannelPool
                    • __enter__
                    • __exit__
                    • get_channel
                    • close
                  • MeasurementService
      • Submodules
      • Package Contents
ni_measurementlink_service
  • API Reference
  • ni_measurementlink_service
  • ni_measurementlink_service.measurement
  • ni_measurementlink_service.measurement.service
  • Edit on GitHub

ni_measurementlink_service.measurement.service

Framework to host measurement service.

Module Contents

Classes

MeasurementContext

Proxy for the Measurement Service's context-local state.

GrpcChannelPool

Class that manages gRPC channel lifetimes.

MeasurementService

Class that supports registering and hosting a python function as a gRPC service.

class ni_measurementlink_service.measurement.service.MeasurementContext[source]

Proxy for the Measurement Service’s context-local state.

property grpc_context

Get the context for the RPC.

property pin_map_context

Get the pin map context for the RPC.

add_cancel_callback(cancel_callback)[source]

Add a callback which is invoked when the RPC is canceled.

cancel()[source]

Cancel the RPC.

property time_remaining

Get the time remaining for the RPC.

abort(code, details)[source]

Aborts the RPC.

class ni_measurementlink_service.measurement.service.GrpcChannelPool[source]

Bases: object

Class that manages gRPC channel lifetimes.

__enter__()[source]

Enter the runtime context of the GrpcChannelPool.

__exit__(exc_type, exc_value, traceback)[source]

Exit the runtime context of the GrpcChannelPool.

get_channel(target)[source]

Return a gRPC channel.

Parameters:

target (str) – The server address

close()[source]

Close channels opened by get_channel().

class ni_measurementlink_service.measurement.service.MeasurementService(service_config_path, version, ui_file_paths, service_class=None)[source]

Class that supports registering and hosting a python function as a gRPC service.

Attributes

measurement_info (info.MeasurementInfo): Measurement info

service_info(info.ServiceInfo) : Service Info

configuration_parameter_list (List): List of configuration parameters.

output_parameter_list (list): List of output parameters.

measure_function (Callable): Registered measurement function.

context (MeasurementContext): Accessor for context-local state.

discovery_client (DiscoveryClient): Client for accessing the MeasurementLink discovery

service.

channel_pool (GrpcChannelPool): Pool of gRPC channels used by the service.

register_measurement(measurement_function)[source]

Register a function as the measurement function for a measurement service.

To declare a measurement function, use this idiom:

``` @measurement_service.register_measurement @measurement_service.configuration(“Configuration 1”, …) @measurement_service.configuration(“Configuration 2”, …) @measurement_service.output(“Output 1”, …) @measurement_service.output(“Output 2”, …) def measure(configuration1, configuration2):

… return (output1, output2)

```

See also: configuration(), output()

configuration(display_name, type, default_value, *, instrument_type='')[source]

Add a configuration parameter to a measurement function.

This decorator maps the measurement service’s configuration parameters to Python positional parameters. To add multiple configuration parameters to the same measurement function, use this decorator multiple times. The order of decorator calls must match the order of positional parameters.

See also: register_measurement()

Args

display_name (str): Display name of the configuration.

type (DataType): Data type of the configuration.

default_value (Any): Default value of the configuration.

instrument_type (str): Optional. Filter pins by instrument type. This is only supported when configuration type is DataType.Pin. Pin maps have built in instrument definitions using the NI driver based instrument type ids. These can be found as constants in nims.session_management. For example, for an NI DCPower instrument the instrument type is nims.session_management.INSTRUMENT_TYPE_NI_DCPOWER. For custom instruments the user defined instrument type id is defined in the pin map file.

Returns

Callable: Callable that takes in Any Python Function and returns the same python function.

output(display_name, type)[source]

Add a output parameter to a measurement function.

This decorator maps the measurement service’s output parameters to the elements of the tuple returned by the measurement function. To add multiple output parameters to the same measurement function, use this decorator multiple times. The order of decorator calls must match the order of elements returned by the measurement fuction.

See also: register_measurement()

Args

display_name (str): Display name of the output.

type (DataType): Data type of the output.

Returns

Callable: Callable that takes in Any Python Function and returns the same python function.

host_service()[source]

Host the registered measurement method as gRPC measurement service.

Returns

MeasurementService: Context manager that can be used with a with-statement to close the service.

Raises

Exception: If register measurement methods not available.

close_service()[source]

Close the Service after un-registering with discovery service and cleanups.

__enter__()[source]

Enter the runtime context related to the measurement service.

__exit__(exc_type, exc_value, traceback)[source]

Exit the runtime context related to the measurement service.

get_channel(provided_interface, service_class='')[source]

Return gRPC channel to specified service.

Args

provided_interface (str): The gRPC Full Name of the service.

service_class (str): The service “class” that should be matched.

Returns

grpc.Channel: A channel to the gRPC service.

Raises
Exception: If service_class is not specified and there is more than one matching service

registered.

Previous Next

© Copyright 2023, National Instruments. Revision 299ad6c0.

Built with Sphinx using a theme provided by Read the Docs.