The Measurement Plug-In architecture is built on a microservices model, with each component functioning as a gRPC service. As a network-based protocol, gRPC enables these components to be language-agnostic, allowing seamless interoperability across diverse programming environments. This approach ensures that any feature extensions or customizations can also be implemented as gRPC services.
A user-defined gRPC service is a custom service in which you specify service methods and message
types in a .proto
file, generate client and server code, and implement the server logic.
Registering this service with the NI Discovery Service enables various clients to access and
communicate with it over gRPC, simplifying integration across technology stacks.
This repository includes a sample logger service that demonstrates how a typical data logger can be made into a gRPC service. By registering this gRPC-based logger with the NI Discovery Service, the provided examples showcase seamless integration, enabling all measurement plug-ins, regardless of language (e.g., Python, LabVIEW, or C#), to access the logger service and record measurement during execution.
- InstrumentStudio 2024 Q4 or later
- TestStand 2021 SP1 or later (recommended)
- LabVIEW 2021 SP1 or later
- Python 3.9 or later
Package dependencies:
- Measurement Plug-In SDK Service for LabVIEW 3.1.0.6 or later
- Measurement Plug-In SDK Service for Python 2.1.0 or later
-
The flowchart below outlines the steps for creating a custom gRPC service and registering it with the NI Discovery service.
- Define the gRPC Service and implement the Server:
- Begin by defining a
.proto
file to specify the service structure and data types, following the instructions provided here. - Generate the client and server code based on the
.proto
file. - Implement the gRPC server using the generated code.
- Refer to the repository for an example of gRPC server initialization here.
- Begin by defining a
- Register the Service with the NI Discovery Service:
- Use the discovery client from the Python or LabVIEW service package to register the user-defined service with the NI Discovery Service, providing its location details. This registration enables the service to be accessed and utilized within measurement plug-ins.
- See the example implementation of the logger service for reference.
- It is recommended to use the NI Discovery Service for dynamic service location resolution instead of relying on a static port number. Static port numbers can lead to conflicts and are less adaptable to changes in the network environment.
- Dynamically resolving the service's port number allows for services to be relocated or scaled across multiple machines without the need to modify client configurations. This approach results in more robust and maintainable deployments.
-
The flowchart below details the steps necessary to integrate a user-defined service into the measurement service.
- Generate the client stubs for the user-defined service.
- Refer to the instructions provided here to create a stub.
- Create a client module to establish a connection with the user-defined service from the python measurements.
- Define Service Interface and Service Class Names inside the module.
- Create a class that abstracts the methods from the generated client stubs to interact with the service.
- Resolve the service location using the discovery client.
- Establish a gRPC channel to the service and create a stub for making API calls.
- Define methods in the client class to call the service methods, constructing and sending requests as needed.
- Example: logger_service_client.py.
-
Install gRPC and LabVIEW gRPC Server and Client tool packages.
- Refer to this document for installation instructions.
-
Generate client interfaces from the
.proto
file to communicate with the service methods using thegRPC Server-Client [2] - Code Generator
. -
Establish the connection to communicate with the service methods.
-
Create client VIs under a common class to interact with the user-defined service from LabVIEW measurements.
-
Develop a client VI to initially establish a connection between the service and the measurement.
-
In addition to establishing the connection, create a VI to call the service APIs using the gRPC ID obtained from the output of the previous VI.
-
Finally, Create a VI to ensure that the client is properly closed without any open connections and all associated resources are released for the client.