Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md files for Measurement Plug-In Client generator #891

Merged
merged 17 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 116 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
- [Developing Measurements: Quick Start](#developing-measurements-quick-start)
- [Installation](#installation)
- [Developing a minimal Python measurement](#developing-a-minimal-python-measurement)
- [Steps to run/debug the measurement service](#steps-to-rundebug-the-measurement-service)
- [Steps to Run/Debug the Measurement Service](#steps-to-rundebug-the-measurement-service)
- [Generating Measurement Clients: Quick Start](#generating-measurement-clients-quick-start)
- [Installation](#installation-1)
- [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)
- [Static Registration of Python Measurements](#static-registration-of-python-measurements)
- [Create a batch file that runs a Python measurement](#create-a-batch-file-that-runs-a-python-measurement)
- [Create Executable for Python Scripts](#create-executable-for-python-scripts)
Expand Down Expand Up @@ -157,11 +161,11 @@ pip install ni-measurement-plugin-sdk-generator
return ["foo", "bar"]
```

4. Run/Debug the created measurement by following the steps discussed in the section ["Steps to run/debug the measurement service".](#steps-to-rundebug-the-measurement-service)
4. Run/Debug the created measurement by following the steps discussed in the section ["Steps to Run/Debug the Measurement Service".](#steps-to-rundebug-the-measurement-service)

---

## Steps to run/debug the measurement service
## Steps to Run/Debug the Measurement Service

1. Start the discovery service if not already started.

Expand Down Expand Up @@ -190,6 +194,115 @@ pip install ni-measurement-plugin-sdk-generator

---

## Generating Measurement Clients: Quick Start

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

### Installation
Install Measurement Plug-In SDK by following the instructions in section ["Measurement Plug-In SDK Installation"](#installation).

### Generating a Minimal Python Measurement Client

1. Install the `ni-measurement-plugin-sdk-generator` package.

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

2. Run the `ni-measurement-plugin-client-generator` tool. Use any of the command line arguments below to create Python measurement clients.

1. Run this command with optional arguments to create measurement clients for specific measurements.

```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:
- `--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**: For multiple measurement client generation, `--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. Run this command to create measurement clients for all registered measurements.

`ni-measurement-plugin-client-generator --all`

> **Note**: `--directory-out` can be provided for this command.

3. Run this command to create measurement clients for any registered measurements interactively.

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

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

> **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 ["Developing a Minimal Python MeasurementClient"](#developing-a-minimal-python-measurement-client) section.

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

``` python
from sample_measurement_client import SampleMeasurementClient

client = SampleMeasurementClient()
outputs = client.measure()
```

2. For streaming measurements, use `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)
output = client.measure()
```
- Alternatively, you can provide a pin map context through the `pin_map_context` property. Similarly, sites can be provided through the `sites` property.

``` python
from sample_measurement_client import SampleMeasurementClient

client = SampleMeasurementClient()
client.pin_map_context = active_pin_map_context
outputs = client.measure()
```

4. Cancel any ongoing `measure` or `stream_measure` calls using the `cancel` method.

``` python
from sample_measurement_client import SampleMeasurementClient

client = SampleMeasurementClient()
thread = threading.Thread(target=client.measure)
thread.start()
client.cancel()
```

---

## Static Registration of Python Measurements

The NI Discovery Service provides a registry of other services, and can discover and activate other services on the system. These features allow the discovery service to distinguish, manage, and describe measurement services on the system.
Expand Down
144 changes: 140 additions & 4 deletions packages/generator/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Measurement Plug-In Code Generator for Python
# 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 Code Generator for Python (`ni-measurement-plugin-sdk-generator`) is a
tool for generating reusable measurement plug-ins using gRPC services.
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.

For installation and usage, see [Measurement Plug-In SDK for Python (`ni-measurement-plugin-sdk-service`)](https://pypi.org/project/ni-measurement-plugin-sdk-service/).
- `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.

---

Expand All @@ -18,3 +27,130 @@ For installation and usage, see [Measurement Plug-In SDK for Python (`ni-measure
- [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 is installed. Install Measurement Plug-In SDK Service for Python using [pip](https://pip.pypa.io/).

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

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

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

### Generating a Minimal Python Measurement Client

1. Install the `ni-measurement-plugin-sdk-generator` package.

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

2. Run the `ni-measurement-plugin-client-generator` tool. Use any of the command line arguments below to create Python measurement clients.

1. Run this command with optional arguments to create measurement clients for specific measurements.

```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:
- `--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**: For multiple measurement client generation, `--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. Run this command to create measurement clients for all registered measurements.

`ni-measurement-plugin-client-generator --all`

> **Note**: `--directory-out` can be provided for this command.

3. Run this command to create measurement clients for any registered measurements interactively.

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

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

> **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 ["Developing a Minimal Python MeasurementClient"](#developing-a-minimal-python-measurement-client) section.

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

``` python
from sample_measurement_client import SampleMeasurementClient

client = SampleMeasurementClient()
outputs = client.measure()
```

2. For streaming measurements, use `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)
output = client.measure()
```
- Alternatively, you can provide a pin map context through the `pin_map_context` property. Similarly, sites can be provided through the `sites` property.

``` python
from sample_measurement_client import SampleMeasurementClient

client = SampleMeasurementClient()
client.pin_map_context = active_pin_map_context
outputs = client.measure()
```

4. Cancel any ongoing `measure` or `stream_measure` calls using the `cancel` method.

``` python
from sample_measurement_client import SampleMeasurementClient

client = SampleMeasurementClient()
thread = threading.Thread(target=client.measure)
thread.start()
client.cancel()
```

---