ni_measurementlink_service
releases/1.0
  • API Reference
    • ni_measurementlink_service
      • Subpackages
        • ni_measurementlink_service.measurement
      • Submodules
        • ni_measurementlink_service.session_management
      • Package Contents
        • Classes
          • DataType
            • DataType.Int32
            • DataType.Int64
            • DataType.UInt32
            • DataType.UInt64
            • DataType.Float
            • DataType.Double
            • DataType.Boolean
            • DataType.String
            • DataType.Pin
            • DataType.Path
            • DataType.Int32Array1D
            • DataType.Int64Array1D
            • DataType.UInt32Array1D
            • DataType.UInt64Array1D
            • DataType.FloatArray1D
            • DataType.DoubleArray1D
            • DataType.BooleanArray1D
            • DataType.StringArray1D
            • DataType.PinArray1D
            • DataType.PathArray1D
          • MeasurementInfo
            • MeasurementInfo.display_name
            • MeasurementInfo.version
            • MeasurementInfo.ui_file_paths
          • ServiceInfo
            • ServiceInfo.service_class
            • ServiceInfo.description_url
          • MeasurementService
            • MeasurementService.register_measurement()
            • MeasurementService.configuration()
            • MeasurementService.output()
            • MeasurementService.host_service()
            • MeasurementService.close_service()
            • MeasurementService.__enter__()
            • MeasurementService.__exit__()
            • MeasurementService.get_channel()
          • DataType
            • Int32
            • Int64
            • UInt32
            • UInt64
            • Float
            • Double
            • Boolean
            • String
            • Pin
            • Path
            • Int32Array1D
            • Int64Array1D
            • UInt32Array1D
            • UInt64Array1D
            • FloatArray1D
            • DoubleArray1D
            • BooleanArray1D
            • StringArray1D
            • PinArray1D
            • PathArray1D
          • MeasurementInfo
          • ServiceInfo
          • MeasurementService
ni_measurementlink_service
  • API Reference
  • ni_measurementlink_service
  • Edit on GitHub

ni_measurementlink_service

MeasurementLink Support for Python.

Subpackages

  • ni_measurementlink_service.measurement
    • ni_measurementlink_service.measurement.info
    • ni_measurementlink_service.measurement.service

Submodules

  • ni_measurementlink_service.session_management

Package Contents

Classes

DataType

Enum that represents the supported data types.

MeasurementInfo

Class that represents the measurement information.

ServiceInfo

Class the represents the service information.

MeasurementService

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

class ni_measurementlink_service.DataType[source]

Bases: enum.Enum

Enum that represents the supported data types.

Int32
Int64
UInt32
UInt64
Float
Double
Boolean
String
Pin
Path
Int32Array1D
Int64Array1D
UInt32Array1D
UInt64Array1D
FloatArray1D
DoubleArray1D
BooleanArray1D
StringArray1D
PinArray1D
PathArray1D
class ni_measurementlink_service.MeasurementInfo[source]

Bases: NamedTuple

Class that represents the measurement information.

Attributes

display_name (str): The measurement display name for client to display to user.

version (str): The measurement version that helps to maintain versions of a measurement in future.

ui_file_paths (list): Absolute paths of the UI file(s) linked to the measurement.

display_name :str
version :str
ui_file_paths :List[pathlib.Path]
class ni_measurementlink_service.ServiceInfo[source]

Bases: NamedTuple

Class the represents the service information.

Attributes

service_class (str): Service class that the measurement belongs to. Measurements under same service class expected to perform same logic. For e.g., different version of measurement can come under same service class.

description_url (str): Description URL of the measurement.

service_class :str
description_url :str
class ni_measurementlink_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.