ni_measurement_plugin_sdk_service.measurement.service ===================================================== .. py:module:: ni_measurement_plugin_sdk_service.measurement.service .. autoapi-nested-parse:: Framework to host measurement service. Attributes ---------- .. autoapisummary:: ni_measurement_plugin_sdk_service.measurement.service.SupportedEnumType Classes ------- .. autoapisummary:: ni_measurement_plugin_sdk_service.measurement.service.MeasurementContext ni_measurement_plugin_sdk_service.measurement.service.MeasurementService Module Contents --------------- .. py:data:: SupportedEnumType .. py:class:: MeasurementContext Proxy for the Measurement Service's context-local state. .. py:property:: grpc_context :type: grpc.ServicerContext Get the context for the RPC. .. py:property:: pin_map_context :type: ni.measurementlink.sessionmanagement.v1.client.PinMapContext Get the pin map context for the RPC. .. py:method:: add_cancel_callback(cancel_callback) Add a callback which is invoked when the RPC is canceled. .. py:method:: cancel() Cancel the RPC. .. py:property:: time_remaining :type: float Get the time remaining for the RPC. .. py:method:: abort(code, details) Aborts the RPC. .. py:method:: reserve_session(pin_or_relay_names, timeout = 0.0) 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. :param pin_or_relay_names: One or multiple pins, pin groups, relays, or relay groups to use for the measurement. :param timeout: 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. .. py:method:: reserve_sessions(pin_or_relay_names, timeout = 0.0) 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. :param pin_or_relay_names: One or multiple pins, pin groups, relays, or relay groups to use for the measurement. :param timeout: 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. .. py:class:: MeasurementService(service_config_path, version = '', ui_file_paths = [], service_class = None) Class that supports registering and hosting a python function as a gRPC service. .. py:attribute:: measurement_info :type: ni_measurement_plugin_sdk_service.measurement.info.MeasurementInfo Information about the measurement performed by this service. .. py:attribute:: service_info :type: ni.measurementlink.discovery.v1.client.ServiceInfo Information about this service. .. py:attribute:: context :type: MeasurementContext Accessor for context-local state. .. py:property:: channel_pool :type: ni_grpc_extensions.channelpool.GrpcChannelPool Pool of gRPC channels used by the service. .. py:property:: discovery_client :type: ni.measurementlink.discovery.v1.client.DiscoveryClient Client for accessing the NI Discovery Service. .. py:property:: configuration_parameter_list :type: list[Any] List of configuration parameters. .. py:property:: grpc_service :type: ni_measurement_plugin_sdk_service._internal.service_manager.GrpcService | None The gRPC service object. This is a private implementation detail. .. py:property:: measure_function :type: Callable Registered measurement function. .. py:property:: output_parameter_list :type: list[Any] List of output parameters. .. py:property:: service_location :type: ni.measurementlink.discovery.v1.client.ServiceLocation The location of the service on the network. .. py:property:: session_management_client :type: ni.measurementlink.sessionmanagement.v1.client.SessionManagementClient Client for accessing the measurement plug-in session management service. .. py:method:: register_measurement(measurement_function) 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: :func:`.configuration`, :func:`.output` .. py:method:: configuration(display_name, type, default_value, *, instrument_type = '', enum_type = None) 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: :func:`.register_measurement` :param display_name: Display name of the configuration. :param type: Data type of the configuration. :param default_value: Default value of the configuration. :param instrument_type: Filter pins by instrument type. This is only supported when configuration type is DataType.IOResource or DataType.Pin (deprecated). For NI instruments, use instrument type id constants defined by :py:mod:`ni_measurement_plugin_sdk_service.session_management`, such as :py:const:`~ni_measurement_plugin_sdk_service.session_management.INSTRUMENT_TYPE_NI_DCPOWER` or :py:const:`~ni_measurement_plugin_sdk_service.session_management.INSTRUMENT_TYPE_NI_DMM`. For custom instruments, use the instrument type id defined in the pin map file. :param enum_type: 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. .. py:method:: output(display_name, type, *, enum_type = None) 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: :func:`.register_measurement` :param display_name: Display name of the output. :param type: Data type of the output. :param enum_type: 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. .. py:method:: host_service() 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. :rtype: MeasurementService :raises Exception: If register measurement methods not available. .. py:method:: close_service() 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(). .. py:method:: __enter__() Enter the runtime context related to the measurement service. .. py:method:: __exit__(exc_type, exc_val, traceback) Exit the runtime context related to the measurement service. .. py:method:: get_channel(provided_interface, service_class = '') Return gRPC channel to specified service. :param provided_interface: The gRPC Full Name of the service. :type provided_interface: str :param service_class: The service "class" that should be matched. :type service_class: str :returns: A channel to the gRPC service. :rtype: grpc.Channel :raises Exception: If service_class is not specified and there is more than one matching service registered.