ni_measurementlink_service.measurement.service
Framework to host measurement service.
Module Contents
Classes
Proxy for the Measurement Service's context-local state. |
|
Class that manages gRPC channel lifetimes. |
|
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.
- property time_remaining
Get the time remaining for the RPC.
- class ni_measurementlink_service.measurement.service.GrpcChannelPool[source]
Bases:
objectClass that manages gRPC channel lifetimes.
- 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.
- __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.