ni_measurementlink_service
releases/1.4
  • API Reference
    • ni_measurementlink_service
      • Subpackages
        • ni_measurementlink_service.discovery
        • ni_measurementlink_service.grpc
        • ni_measurementlink_service.measurement
          • Submodules
            • ni_measurementlink_service.measurement.info
            • ni_measurementlink_service.measurement.service
              • Module Contents
                • Classes
                • Attributes
                  • SupportedEnumType
                  • MeasurementContext
                    • MeasurementContext.grpc_context
                    • MeasurementContext.pin_map_context
                    • MeasurementContext.time_remaining
                    • MeasurementContext.add_cancel_callback()
                    • MeasurementContext.cancel()
                    • MeasurementContext.abort()
                    • MeasurementContext.reserve_session()
                    • MeasurementContext.reserve_sessions()
                  • MeasurementService
                    • MeasurementService.measurement_info
                    • MeasurementService.service_info
                    • MeasurementService.context
                    • MeasurementService.channel_pool
                    • MeasurementService.discovery_client
                    • MeasurementService.configuration_parameter_list
                    • MeasurementService.grpc_service
                    • MeasurementService.measure_function
                    • MeasurementService.output_parameter_list
                    • MeasurementService.service_location
                    • MeasurementService.session_management_client
                    • MeasurementService.register_measurement()
                    • MeasurementService.configuration()
                    • MeasurementService.output()
                    • MeasurementService.host_service()
                    • MeasurementService.close_service()
                    • MeasurementService.__enter__()
                    • MeasurementService.__exit__()
                    • MeasurementService.get_channel()
        • ni_measurementlink_service.session_management
      • 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.

MeasurementService

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

Attributes

SupportedEnumType

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

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

property grpc_context: grpc.ServicerContext

Get the context for the RPC.

Return type:

grpc.ServicerContext

property pin_map_context: ni_measurementlink_service.session_management.PinMapContext

Get the pin map context for the RPC.

Return type:

ni_measurementlink_service.session_management.PinMapContext

property time_remaining: float

Get the time remaining for the RPC.

Return type:

float

add_cancel_callback(cancel_callback)[source]

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

Parameters:

cancel_callback (Callable[[], None]) –

Return type:

None

cancel()[source]

Cancel the RPC.

Return type:

None

abort(code, details)[source]

Aborts the RPC.

Parameters:
  • code (grpc.StatusCode) –

  • details (str) –

Return type:

None

reserve_session(pin_or_relay_names, timeout=0.0)[source]

Reserve a single session.

Reserve the session matching the given pins, sites, and instrument type ID and return the information needed to create or access the session.

Parameters:
  • pin_or_relay_names (Union[str, Iterable[str]]) – One or multiple pins, pin groups, relays, or relay groups to use for the measurement.

  • timeout (Optional[float]) –

    Timeout in seconds.

    Allowed values: 0 (non-blocking, fails immediately if resources cannot be reserved), -1 (infinite timeout), or any other positive numeric value (wait for that number of seconds)

Returns:

A reservation object with which you can query information about the session and unreserve it.

Return type:

ni_measurementlink_service.session_management.SingleSessionReservation

reserve_sessions(pin_or_relay_names, timeout=0.0)[source]

Reserve multiple sessions.

Reserve sessions matching the given pins, sites, and instrument type ID and return the information needed to create or access the sessions.

Parameters:
  • pin_or_relay_names (Union[str, Iterable[str]]) – One or multiple pins, pin groups, relays, or relay groups to use for the measurement.

  • timeout (Optional[float]) –

    Timeout in seconds.

    Allowed values: 0 (non-blocking, fails immediately if resources cannot be reserved), -1 (infinite timeout), or any other positive numeric value (wait for that number of seconds)

Returns:

A reservation object with which you can query information about the sessions and unreserve them.

Return type:

ni_measurementlink_service.session_management.MultiSessionReservation

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.

Parameters:
  • service_config_path (pathlib.Path) –

  • version (str) –

  • ui_file_paths (List[pathlib.Path]) –

  • service_class (Optional[str]) –

measurement_info

Measurement info

Type:

info.MeasurementInfo

service_info

Service Info

Type:

info.ServiceInfo

context

Accessor for context-local state.

Type:

MeasurementContext

property channel_pool: ni_measurementlink_service.grpc.channelpool.GrpcChannelPool

Pool of gRPC channels used by the service.

Return type:

ni_measurementlink_service.grpc.channelpool.GrpcChannelPool

property discovery_client: ni_measurementlink_service.discovery.DiscoveryClient

Client for accessing the MeasurementLink discovery service.

Return type:

ni_measurementlink_service.discovery.DiscoveryClient

property configuration_parameter_list: List[Any]

List of configuration parameters.

Return type:

List[Any]

property grpc_service: ni_measurementlink_service._internal.service_manager.GrpcService | None

The gRPC service object. This is a private implementation detail.

Return type:

Optional[ni_measurementlink_service._internal.service_manager.GrpcService]

property measure_function: Callable

Registered measurement function.

Return type:

Callable

property output_parameter_list: List[Any]

List of output parameters.

Return type:

List[Any]

property service_location: ni_measurementlink_service.discovery.ServiceLocation

The location of the service on the network.

Return type:

ni_measurementlink_service.discovery.ServiceLocation

property session_management_client: ni_measurementlink_service.session_management.SessionManagementClient

Client for accessing the MeasurementLink session management service.

Return type:

ni_measurementlink_service.session_management.SessionManagementClient

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()

Parameters:

measurement_function (_F) –

Return type:

_F

configuration(display_name, type, default_value, *, instrument_type='', enum_type=None)[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()

Parameters:
  • 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 (Optional[str]) –

    Filter pins by instrument type. This is only supported when configuration type is DataType.Pin.

    For NI instruments, use instrument type id constants defined by ni_measurementlink_service.session_management, such as INSTRUMENT_TYPE_NI_DCPOWER or INSTRUMENT_TYPE_NI_DMM.

    For custom instruments, use the instrument type id defined in the pin map file.

  • enum_type (Optional[SupportedEnumType]) – Defines the enum type associated with this configuration parameter. This is only supported when configuration type is DataType.Enum or DataType.EnumArray1D.

Returns:

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

Return type:

Callable

output(display_name, type, *, enum_type=None)[source]

Add an 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 function.

See also: register_measurement()

Parameters:
  • display_name (str) – Display name of the output.

  • type (DataType) – Data type of the output.

  • (Optional[SupportedEnumType] (enum_type) – Defines the enum type associated with this configuration parameter. This is only supported when configuration type is DataType.Enum or DataType.EnumArray1D.

  • enum_type (Optional[SupportedEnumType]) –

Returns:

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

Return type:

Callable

host_service()[source]

Host the registered measurement method as a gRPC measurement service.

Returns:

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

Return type:

MeasurementService

Raises:

Exception – If register measurement methods not available.

close_service()[source]

Stop the gRPC measurement service.

This method stops the gRPC server, unregisters with the discovery service, and cleans up the cached discovery client and gRPC channel pool.

After calling close_service(), you may call host_service() again.

Exiting the measurement service’s runtime context automatically calls close_service().

Return type:

None

__enter__()[source]

Enter the runtime context related to the measurement service.

Return type:

Self

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

Exit the runtime context related to the measurement service.

Parameters:
  • exc_type (Optional[Type[BaseException]]) –

  • exc_val (Optional[BaseException]) –

  • traceback (Optional[types.TracebackType]) –

Return type:

Literal[False]

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

Return gRPC channel to specified service.

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

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

Returns:

A channel to the gRPC service.

Return type:

grpc.Channel

Raises:

Exception – If service_class is not specified and there is more than one matching service registered.

Previous Next

© Copyright 2024, National Instruments. Revision 2ba12c60.

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