ni_measurement_plugin_sdk_generator


Nameni_measurement_plugin_sdk_generator JSON
Version 2.1.0 PyPI version JSON
download
home_pagehttps://github.com/ni/measurementlink-python/
SummaryMeasurement Plug-In Code Generator for Python
upload_time2024-10-10 20:10:37
maintainerNone
docs_urlNone
authorNI
requires_python<4.0,>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Measurement Plug-In SDK Generator for Python

- [Measurement Plug-In SDK Generator for Python](#measurement-plug-in-sdk-generator-for-python)
  - [Introduction](#introduction)
  - [Dependencies](#dependencies)
  - [Developing Measurements: Quick Start](#developing-measurements-quick-start)
  - [Generating Measurement Clients: Quick Start](#generating-measurement-clients-quick-start)
    - [Installation](#installation)
    - [Generating a Minimal Python Measurement Client](#generating-a-minimal-python-measurement-client)
  - [Steps to Run/Debug the Measurement Client](#steps-to-rundebug-the-measurement-client)

---

## Introduction

Measurement Plug-In SDK Generator for Python (`ni-measurement-plugin-sdk-generator`) is a Python package containing tools for generating reusable measurement plug-ins and clients.

- `ni-measurement-plugin-generator` is a command for generating measurement plug-ins using gRPC services.
- `ni-measurement-plugin-client-generator` is a command for generating plug-in clients to interact with the measurement plug-ins.

---

## Dependencies

- Python >= 3.8 [(3.9 recommended)](https://www.python.org/downloads/release/python-3913/)
- [mako >= 1.2.1, < 2.x](https://pypi.org/project/Mako/1.2.1/)
- [click >= 8.1.3](https://pypi.org/project/click/8.1.3/)

---

## Developing Measurements: Quick Start

For installation and usage, see [Measurement Plug-In SDK Service for Python - Developing Measurements: Quick Start](https://pypi.org/project/ni_measurement_plugin_sdk_service/#developing-measurements-quick-start) section.

---

## Generating Measurement Clients: Quick Start

This section provides instructions to generate custom measurement clients in Python using Measurement Plug-In SDK for Python.

### Installation

Make sure the system has the recommended Python version installed. Install Measurement Plug-In SDK for Python using [pip](https://pip.pypa.io/).

``` cmd
REM Activate the required virtual environment if any.
pip install ni-measurement-plugin-sdk
```

Check if you have installed the expected version of Measurement Plug-In SDK for Python installed by running the below command:

```cmd
pip show ni-measurement-plugin-sdk
```

### Generating a Minimal Python Measurement Client

Run the `ni-measurement-plugin-client-generator` tool.

1. To create measurement clients for specific measurements, use this command with optional arguments:

    ```ni-measurement-plugin-client-generator --measurement-service-class "ni.examples.SampleMeasurement_Python" [--module-name "sample_measurement_client"]  [--class-name "SampleMeasurementClient"] [--directory-out <new_path_for_created_files>]```

    - `--measurement-service-class` specifies the measurement service class for which the client is being generated.

    - Optional arguments:
        - `--module-name` and `--class-name` define the module and class names of the generated client. If not specified, they are derived from the measurement service class name.

        - `--directory-out` specifies the output directory for the generated files. If not specified, files are placed in the current directory.
        
    > **Note**: When generating multiple measurement clients, `--module-name` and `--class-name` are ignored and derived from the service class of each measurement. So, ensure that the measurement service class name adheres to proper naming conventions.

2. To create measurement clients for all registered measurements, use this command:

    `ni-measurement-plugin-client-generator --all [--directory-out <new_path_for_created_files>]`

3. To interactively create measurement clients for any registered measurements, use this command:

    `ni-measurement-plugin-client-generator --interactive`

The generated client includes four APIs: `measure`, `stream_measure`, `register_pin_map`, and `cancel`. The usage of these APIs is discussed in the ["Steps to Run/Debug the Measurement Client"](#steps-to-rundebug-the-measurement-client) section.

> **Note**:
> - The Measurement Plug-In Client is compatible with all datatypes supported by the Measurement Plug-In.
> - The Double XY datatype is not supported for measurement configurations (inputs).
> - For Enum datatypes, the generated enum class names will be the measurement parameter name suffixed with 'Enum'. For instance, if the measurement parameter name is 'Enum In', the generated enum in the client will be `EnumInEnum'.
> - Ring control in LabVIEW measurements will be represented as numeric datatypes in the generated client.

---

## Steps to Run/Debug the Measurement Client

1. Make sure the required measurement service is running before interacting with it via the client.

2. Use the client APIs from the ["Generating a Minimal Python Measurement Client"](#generating-a-minimal-python-measurement-client) section.

    1. For non-streaming measurements, use the `measure` method.

        ``` python
        from sample_measurement_client import SampleMeasurementClient
        
        client = SampleMeasurementClient()
        outputs = client.measure()
        print(outputs)
        ```

    2. For streaming measurements, use the `stream_measure` method.

        ``` python
        from sample_measurement_client import SampleMeasurementClient
        
        client = SampleMeasurementClient()
        outputs_itr = client.stream_measure()
        for index, outputs in enumerate(outputs_itr):
            print(f"outputs[{index}] = {outputs}")
        ```

    3. If a measurement requires a pin map, it can be registered using the `register_pin_map` method. By default, `sites` is set to [0].

        ``` python
        from sample_measurement_client import SampleMeasurementClient
        
        client = SampleMeasurementClient()
        client.register_pin_map(pin_map_path)
        outputs = client.measure()
        print(outputs)
        ```
        - Alternatively, when calling a measurement service from another measurement, you can pass the first measurement's pin map context to the second measurement's pin map context through the `pin_map_context` property. Sites can also be provided through the `sites` property.

        ``` python
        from sample_measurement_client import SampleMeasurementClient
        
        client = SampleMeasurementClient()
        client.pin_map_context = available_pin_map_context
        client.sites = [0, 1]
        outputs = client.measure()
        print(outputs)
        ```

    4. Cancel an ongoing `measure` or `stream_measure` call using the `cancel` method.

        ``` python
        from concurrent.futures import ThreadPoolExecutor
        from sample_measurement_client import SampleMeasurementClient
        
        client = SampleMeasurementClient()
        with ThreadPoolExecutor() as executor:
            future = executor.submit(client.measure)
            client.cancel()
            outputs = future.result()  # Raises grpc.RpcException with status code "CANCELLED" 
        ```

---

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ni/measurementlink-python/",
    "name": "ni_measurement_plugin_sdk_generator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "NI",
    "author_email": "opensource@ni.com",
    "download_url": "https://files.pythonhosted.org/packages/7b/a3/2c72f119c759ca2f8664018bac703c6856046ec5c43449a7a6edcd3fa59d/ni_measurement_plugin_sdk_generator-2.1.0.tar.gz",
    "platform": null,
    "description": "# Measurement Plug-In SDK Generator for Python\n\n- [Measurement Plug-In SDK Generator for Python](#measurement-plug-in-sdk-generator-for-python)\n  - [Introduction](#introduction)\n  - [Dependencies](#dependencies)\n  - [Developing Measurements: Quick Start](#developing-measurements-quick-start)\n  - [Generating Measurement Clients: Quick Start](#generating-measurement-clients-quick-start)\n    - [Installation](#installation)\n    - [Generating a Minimal Python Measurement Client](#generating-a-minimal-python-measurement-client)\n  - [Steps to Run/Debug the Measurement Client](#steps-to-rundebug-the-measurement-client)\n\n---\n\n## Introduction\n\nMeasurement Plug-In SDK Generator for Python (`ni-measurement-plugin-sdk-generator`) is a Python package containing tools for generating reusable measurement plug-ins and clients.\n\n- `ni-measurement-plugin-generator` is a command for generating measurement plug-ins using gRPC services.\n- `ni-measurement-plugin-client-generator` is a command for generating plug-in clients to interact with the measurement plug-ins.\n\n---\n\n## Dependencies\n\n- Python >= 3.8 [(3.9 recommended)](https://www.python.org/downloads/release/python-3913/)\n- [mako >= 1.2.1, < 2.x](https://pypi.org/project/Mako/1.2.1/)\n- [click >= 8.1.3](https://pypi.org/project/click/8.1.3/)\n\n---\n\n## Developing Measurements: Quick Start\n\nFor installation and usage, see [Measurement Plug-In SDK Service for Python - Developing Measurements: Quick Start](https://pypi.org/project/ni_measurement_plugin_sdk_service/#developing-measurements-quick-start) section.\n\n---\n\n## Generating Measurement Clients: Quick Start\n\nThis section provides instructions to generate custom measurement clients in Python using Measurement Plug-In SDK for Python.\n\n### Installation\n\nMake sure the system has the recommended Python version installed. Install Measurement Plug-In SDK for Python using [pip](https://pip.pypa.io/).\n\n``` cmd\nREM Activate the required virtual environment if any.\npip install ni-measurement-plugin-sdk\n```\n\nCheck if you have installed the expected version of Measurement Plug-In SDK for Python installed by running the below command:\n\n```cmd\npip show ni-measurement-plugin-sdk\n```\n\n### Generating a Minimal Python Measurement Client\n\nRun the `ni-measurement-plugin-client-generator` tool.\n\n1. To create measurement clients for specific measurements, use this command with optional arguments:\n\n    ```ni-measurement-plugin-client-generator --measurement-service-class \"ni.examples.SampleMeasurement_Python\" [--module-name \"sample_measurement_client\"]  [--class-name \"SampleMeasurementClient\"] [--directory-out <new_path_for_created_files>]```\n\n    - `--measurement-service-class` specifies the measurement service class for which the client is being generated.\n\n    - Optional arguments:\n        - `--module-name` and `--class-name` define the module and class names of the generated client. If not specified, they are derived from the measurement service class name.\n\n        - `--directory-out` specifies the output directory for the generated files. If not specified, files are placed in the current directory.\n        \n    > **Note**: When generating multiple measurement clients, `--module-name` and `--class-name` are ignored and derived from the service class of each measurement. So, ensure that the measurement service class name adheres to proper naming conventions.\n\n2. To create measurement clients for all registered measurements, use this command:\n\n    `ni-measurement-plugin-client-generator --all [--directory-out <new_path_for_created_files>]`\n\n3. To interactively create measurement clients for any registered measurements, use this command:\n\n    `ni-measurement-plugin-client-generator --interactive`\n\nThe generated client includes four APIs: `measure`, `stream_measure`, `register_pin_map`, and `cancel`. The usage of these APIs is discussed in the [\"Steps to Run/Debug the Measurement Client\"](#steps-to-rundebug-the-measurement-client) section.\n\n> **Note**:\n> - The Measurement Plug-In Client is compatible with all datatypes supported by the Measurement Plug-In.\n> - The Double XY datatype is not supported for measurement configurations (inputs).\n> - For Enum datatypes, the generated enum class names will be the measurement parameter name suffixed with 'Enum'. For instance, if the measurement parameter name is 'Enum In', the generated enum in the client will be `EnumInEnum'.\n> - Ring control in LabVIEW measurements will be represented as numeric datatypes in the generated client.\n\n---\n\n## Steps to Run/Debug the Measurement Client\n\n1. Make sure the required measurement service is running before interacting with it via the client.\n\n2. Use the client APIs from the [\"Generating a Minimal Python Measurement Client\"](#generating-a-minimal-python-measurement-client) section.\n\n    1. For non-streaming measurements, use the `measure` method.\n\n        ``` python\n        from sample_measurement_client import SampleMeasurementClient\n        \n        client = SampleMeasurementClient()\n        outputs = client.measure()\n        print(outputs)\n        ```\n\n    2. For streaming measurements, use the `stream_measure` method.\n\n        ``` python\n        from sample_measurement_client import SampleMeasurementClient\n        \n        client = SampleMeasurementClient()\n        outputs_itr = client.stream_measure()\n        for index, outputs in enumerate(outputs_itr):\n            print(f\"outputs[{index}] = {outputs}\")\n        ```\n\n    3. If a measurement requires a pin map, it can be registered using the `register_pin_map` method. By default, `sites` is set to [0].\n\n        ``` python\n        from sample_measurement_client import SampleMeasurementClient\n        \n        client = SampleMeasurementClient()\n        client.register_pin_map(pin_map_path)\n        outputs = client.measure()\n        print(outputs)\n        ```\n        - Alternatively, when calling a measurement service from another measurement, you can pass the first measurement's pin map context to the second measurement's pin map context through the `pin_map_context` property. Sites can also be provided through the `sites` property.\n\n        ``` python\n        from sample_measurement_client import SampleMeasurementClient\n        \n        client = SampleMeasurementClient()\n        client.pin_map_context = available_pin_map_context\n        client.sites = [0, 1]\n        outputs = client.measure()\n        print(outputs)\n        ```\n\n    4. Cancel an ongoing `measure` or `stream_measure` call using the `cancel` method.\n\n        ``` python\n        from concurrent.futures import ThreadPoolExecutor\n        from sample_measurement_client import SampleMeasurementClient\n        \n        client = SampleMeasurementClient()\n        with ThreadPoolExecutor() as executor:\n            future = executor.submit(client.measure)\n            client.cancel()\n            outputs = future.result()  # Raises grpc.RpcException with status code \"CANCELLED\" \n        ```\n\n---\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Measurement Plug-In Code Generator for Python",
    "version": "2.1.0",
    "project_urls": {
        "Homepage": "https://github.com/ni/measurementlink-python/",
        "Repository": "https://github.com/ni/measurementlink-python/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7b64c4116b163b03b6fac5f707eafc35411d047f2a25bbde3bd686cd48eb66c9",
                "md5": "c5e5bf67336183e0f1c26b45fad63ffb",
                "sha256": "67bc4cc5a4c0dac41d49d9082673fcf4204f5c4bc07745508ac906418286f744"
            },
            "downloads": -1,
            "filename": "ni_measurement_plugin_sdk_generator-2.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c5e5bf67336183e0f1c26b45fad63ffb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 23613,
            "upload_time": "2024-10-10T20:10:36",
            "upload_time_iso_8601": "2024-10-10T20:10:36.309299Z",
            "url": "https://files.pythonhosted.org/packages/7b/64/c4116b163b03b6fac5f707eafc35411d047f2a25bbde3bd686cd48eb66c9/ni_measurement_plugin_sdk_generator-2.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7ba32c72f119c759ca2f8664018bac703c6856046ec5c43449a7a6edcd3fa59d",
                "md5": "4f46ce3264324f703cd11e07b3bd0a70",
                "sha256": "7686d3b1b9cfc5105321632db56e86a2979055fbb7e315e13830ef0e18eb0962"
            },
            "downloads": -1,
            "filename": "ni_measurement_plugin_sdk_generator-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4f46ce3264324f703cd11e07b3bd0a70",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 19748,
            "upload_time": "2024-10-10T20:10:37",
            "upload_time_iso_8601": "2024-10-10T20:10:37.719337Z",
            "url": "https://files.pythonhosted.org/packages/7b/a3/2c72f119c759ca2f8664018bac703c6856046ec5c43449a7a6edcd3fa59d/ni_measurement_plugin_sdk_generator-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-10 20:10:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ni",
    "github_project": "measurementlink-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ni_measurement_plugin_sdk_generator"
}
        
NI
Elapsed time: 0.38293s