Developing a Measurement Plug-In Client with Python

This section outlines the required steps for developing a measurement plug-in client in Python. Use the Python examples in github and the remaining topics in this manual to understand how to develop a working measurement plug-in client for your application.

Creating a Python Measurement Plug-In Client using Batch Mode

The client can be created using a one-line command by configuring the necessary options in Batch Mode.

  1. Open a command prompt.
  2. Enter the following command, specifying the name of the measurement service class: ni_measurement_plugin_client_generator --measurement-service-class measurement_service_class_name
  3. Optional: You can specify additional parameters when running this command. For more details, refer to Python Measurement Plug-In Client Generator Batch Mode Parameters. If no further parameters are required, run the command.
    A Python file containing the client class will be generated for the specified measurement service class. For details on using Python plug-in clients, refer to Python Measurement Plug-In Client Usage

Python Measurement Plug-In Client Generator Batch Mode Parameters

The ni_measurement_plugin_client_generator tool requires the measurement plug-in service class as the first parameter. This parameter can be specified multiple times to create multiple plug-in clients.

The tool accepts the following named parameters in any order using the --name value syntax:
Parameter NameDefault ValueDescription
-s, --measurement-service-class-Creates a Python Measurement Plug-In Client for the given measurement service.
Note This parameter should not be used with the --all parameter.
-a, --allFalseCreates a Python Measurement Plug-In Client for all the registered measurement services.
-m, --module-nameConstructed from service className for the Python Measurement Plug-In Client module. This value is ignored if --all is chosen.
-c, --classConstructed from service className for the Python Measurement Plug-In Client class in the generated module. This value is ignored if --all is chosen.
-o, --directory-outcurrent_directory/module_name.pyOutput directory for Measurement Plug-In Client files.

Creating a Python Measurement Plug-In Client using Interactive Mode

Measurement plug-in clients can be created individually by providing the necessary inputs via the command line in interactive mode.

  1. Open a command prompt.
  2. Run the following command to list the registered and active measurements on the machine: ni_measurement_plugin_client_generator --interactive
    This command displays a numbered list of all registered measurement services.
    1. Measurement A
    2. Measurement B
    3. Measurement C
  3. Enter the number corresponding to the measurement you want to create a client module for. To create a client module for Measurement B from the example above, you would enter 2.
  4. Enter the name of the measurement client module and class, ensuring that the name follows Python's module naming conventions.
    A Python file containing the client class will be generated for the specified measurement service class. For more details, refer to Python Measurement Plug-In Client Usage.

Python Measurement Plug-In Client Usage

The generated Python file will contain a class and public methods for the specified measurement. Before you can interact with a measurement via the plug-in client, the Measurement Service must be running. Refer to the following section for descriptions of the public methods you can use to interact with a measurement service:

  • register_pin_map— Registers the pin map with the pin map service.
  • measure— Interacts with non-streaming data measurements by accepting the actual input configured in the measurement and returning the measurement output.
  • stream_measure— Same as measure, but used specifically for interacting with streaming data measurements.
  • cancel— Aborts any ongoing measure or stream_measure call.
    Note This API can only be used from a separate thread.