Skip to content

Commit b9dee47

Browse files
examples: remove PinMapClient class from _helpers.py (#550)
* examples: remove PinMapClient from helpers * fix: update doc for get_active_pin_map_id API * examples: Update nivisa_dmm_measurement _helpers.py to match the others --------- Co-authored-by: Brad Keryan <brad.keryan@ni.com>
1 parent 0fd0531 commit b9dee47

11 files changed

Lines changed: 14 additions & 417 deletions

File tree

examples/game_of_life/_helpers.py

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,10 @@
66

77
import click
88
import grpc
9-
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pinmap.v1 import (
10-
pin_map_service_pb2,
11-
pin_map_service_pb2_grpc,
12-
)
139
from ni_measurementlink_service.discovery import DiscoveryClient
1410
from ni_measurementlink_service.measurement.service import GrpcChannelPool
1511

1612

17-
class PinMapClient(object):
18-
"""Class that communicates with the pin map service."""
19-
20-
def __init__(self, *, grpc_channel: grpc.Channel):
21-
"""Initialize pin map client."""
22-
self._client: pin_map_service_pb2_grpc.PinMapServiceStub = (
23-
pin_map_service_pb2_grpc.PinMapServiceStub(grpc_channel)
24-
)
25-
26-
def update_pin_map(self, pin_map_path: str) -> str:
27-
"""Update registered pin map contents.
28-
29-
Create and register a pin map if a pin map resource for the specified pin map id is not
30-
found.
31-
32-
Args:
33-
pin_map_path: The file path of the pin map to register as a pin map resource.
34-
35-
Returns:
36-
The resource id of the pin map that is registered to the pin map service.
37-
"""
38-
pin_map_path_obj = pathlib.Path(pin_map_path)
39-
# By convention, the pin map id is the .pinmap file path.
40-
request = pin_map_service_pb2.UpdatePinMapFromXmlRequest(
41-
pin_map_id=pin_map_path, pin_map_xml=pin_map_path_obj.read_text(encoding="utf-8")
42-
)
43-
response: pin_map_service_pb2.PinMap = self._client.UpdatePinMapFromXml(request)
44-
return response.pin_map_id
45-
46-
4713
class GrpcChannelPoolHelper(GrpcChannelPool):
4814
"""Class that manages gRPC channel lifetimes."""
4915

@@ -77,26 +43,15 @@ def __init__(self, sequence_context: Any) -> None:
7743
self._sequence_context = sequence_context
7844

7945
def get_active_pin_map_id(self) -> str:
80-
"""Get the active pin map id from the NI.MeasurementLink.PinMapId temporary global variable.
46+
"""Get the active pin map id from the NI.MeasurementLink.PinMapId runtime variable.
8147
8248
Returns:
8349
The resource id of the pin map that is registered to the pin map service.
8450
"""
85-
return self._sequence_context.Engine.TemporaryGlobals.GetValString(
51+
return self._sequence_context.Execution.RunTimeVariables.GetValString(
8652
"NI.MeasurementLink.PinMapId", 0x0
8753
)
8854

89-
def set_active_pin_map_id(self, pin_map_id: str) -> None:
90-
"""Set the NI.MeasurementLink.PinMapId temporary global variable to the specified id.
91-
92-
Args:
93-
pin_map_id:
94-
The resource id of the pin map that is registered to the pin map service.
95-
"""
96-
self._sequence_context.Engine.TemporaryGlobals.SetValString(
97-
"NI.MeasurementLink.PinMapId", 0x1, pin_map_id
98-
)
99-
10055
def resolve_file_path(self, file_path: str) -> str:
10156
"""Resolve the absolute path to a file using the TestStand search directories.
10257

examples/nidaqmx_analog_input/_helpers.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,10 @@
66

77
import click
88
import grpc
9-
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pinmap.v1 import (
10-
pin_map_service_pb2,
11-
pin_map_service_pb2_grpc,
12-
)
139
from ni_measurementlink_service.discovery import DiscoveryClient
1410
from ni_measurementlink_service.measurement.service import GrpcChannelPool
1511

1612

17-
class PinMapClient(object):
18-
"""Class that communicates with the pin map service."""
19-
20-
def __init__(self, *, grpc_channel: grpc.Channel):
21-
"""Initialize pin map client."""
22-
self._client: pin_map_service_pb2_grpc.PinMapServiceStub = (
23-
pin_map_service_pb2_grpc.PinMapServiceStub(grpc_channel)
24-
)
25-
26-
def update_pin_map(self, pin_map_path: str) -> str:
27-
"""Update registered pin map contents.
28-
29-
Create and register a pin map if a pin map resource for the specified pin map id is not
30-
found.
31-
32-
Args:
33-
pin_map_path: The file path of the pin map to register as a pin map resource.
34-
35-
Returns:
36-
The resource id of the pin map that is registered to the pin map service.
37-
"""
38-
pin_map_path_obj = pathlib.Path(pin_map_path)
39-
# By convention, the pin map id is the .pinmap file path.
40-
request = pin_map_service_pb2.UpdatePinMapFromXmlRequest(
41-
pin_map_id=pin_map_path, pin_map_xml=pin_map_path_obj.read_text(encoding="utf-8")
42-
)
43-
response: pin_map_service_pb2.PinMap = self._client.UpdatePinMapFromXml(request)
44-
return response.pin_map_id
45-
46-
4713
class GrpcChannelPoolHelper(GrpcChannelPool):
4814
"""Class that manages gRPC channel lifetimes."""
4915

@@ -77,7 +43,7 @@ def __init__(self, sequence_context: Any) -> None:
7743
self._sequence_context = sequence_context
7844

7945
def get_active_pin_map_id(self) -> str:
80-
"""Get the active pin map id from the NI.MeasurementLink.PinMapId temporary global variable.
46+
"""Get the active pin map id from the NI.MeasurementLink.PinMapId runtime variable.
8147
8248
Returns:
8349
The resource id of the pin map that is registered to the pin map service.

examples/nidcpower_source_dc_voltage/_helpers.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,10 @@
66

77
import click
88
import grpc
9-
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pinmap.v1 import (
10-
pin_map_service_pb2,
11-
pin_map_service_pb2_grpc,
12-
)
139
from ni_measurementlink_service.discovery import DiscoveryClient
1410
from ni_measurementlink_service.measurement.service import GrpcChannelPool
1511

1612

17-
class PinMapClient(object):
18-
"""Class that communicates with the pin map service."""
19-
20-
def __init__(self, *, grpc_channel: grpc.Channel):
21-
"""Initialize pin map client."""
22-
self._client: pin_map_service_pb2_grpc.PinMapServiceStub = (
23-
pin_map_service_pb2_grpc.PinMapServiceStub(grpc_channel)
24-
)
25-
26-
def update_pin_map(self, pin_map_path: str) -> str:
27-
"""Update registered pin map contents.
28-
29-
Create and register a pin map if a pin map resource for the specified pin map id is not
30-
found.
31-
32-
Args:
33-
pin_map_path: The file path of the pin map to register as a pin map resource.
34-
35-
Returns:
36-
The resource id of the pin map that is registered to the pin map service.
37-
"""
38-
pin_map_path_obj = pathlib.Path(pin_map_path)
39-
# By convention, the pin map id is the .pinmap file path.
40-
request = pin_map_service_pb2.UpdatePinMapFromXmlRequest(
41-
pin_map_id=pin_map_path, pin_map_xml=pin_map_path_obj.read_text(encoding="utf-8")
42-
)
43-
response: pin_map_service_pb2.PinMap = self._client.UpdatePinMapFromXml(request)
44-
return response.pin_map_id
45-
46-
4713
class GrpcChannelPoolHelper(GrpcChannelPool):
4814
"""Class that manages gRPC channel lifetimes."""
4915

@@ -77,7 +43,7 @@ def __init__(self, sequence_context: Any) -> None:
7743
self._sequence_context = sequence_context
7844

7945
def get_active_pin_map_id(self) -> str:
80-
"""Get the active pin map id from the NI.MeasurementLink.PinMapId temporary global variable.
46+
"""Get the active pin map id from the NI.MeasurementLink.PinMapId runtime variable.
8147
8248
Returns:
8349
The resource id of the pin map that is registered to the pin map service.

examples/nidigital_spi/_helpers.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,10 @@
66

77
import click
88
import grpc
9-
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pinmap.v1 import (
10-
pin_map_service_pb2,
11-
pin_map_service_pb2_grpc,
12-
)
139
from ni_measurementlink_service.discovery import DiscoveryClient
1410
from ni_measurementlink_service.measurement.service import GrpcChannelPool
1511

1612

17-
class PinMapClient(object):
18-
"""Class that communicates with the pin map service."""
19-
20-
def __init__(self, *, grpc_channel: grpc.Channel):
21-
"""Initialize pin map client."""
22-
self._client: pin_map_service_pb2_grpc.PinMapServiceStub = (
23-
pin_map_service_pb2_grpc.PinMapServiceStub(grpc_channel)
24-
)
25-
26-
def update_pin_map(self, pin_map_path: str) -> str:
27-
"""Update registered pin map contents.
28-
29-
Create and register a pin map if a pin map resource for the specified pin map id is not
30-
found.
31-
32-
Args:
33-
pin_map_path: The file path of the pin map to register as a pin map resource.
34-
35-
Returns:
36-
The resource id of the pin map that is registered to the pin map service.
37-
"""
38-
pin_map_path_obj = pathlib.Path(pin_map_path)
39-
# By convention, the pin map id is the .pinmap file path.
40-
request = pin_map_service_pb2.UpdatePinMapFromXmlRequest(
41-
pin_map_id=pin_map_path, pin_map_xml=pin_map_path_obj.read_text(encoding="utf-8")
42-
)
43-
response: pin_map_service_pb2.PinMap = self._client.UpdatePinMapFromXml(request)
44-
return response.pin_map_id
45-
46-
4713
class GrpcChannelPoolHelper(GrpcChannelPool):
4814
"""Class that manages gRPC channel lifetimes."""
4915

@@ -77,7 +43,7 @@ def __init__(self, sequence_context: Any) -> None:
7743
self._sequence_context = sequence_context
7844

7945
def get_active_pin_map_id(self) -> str:
80-
"""Get the active pin map id from the NI.MeasurementLink.PinMapId temporary global variable.
46+
"""Get the active pin map id from the NI.MeasurementLink.PinMapId runtime variable.
8147
8248
Returns:
8349
The resource id of the pin map that is registered to the pin map service.

examples/nidmm_measurement/_helpers.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,10 @@
66

77
import click
88
import grpc
9-
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pinmap.v1 import (
10-
pin_map_service_pb2,
11-
pin_map_service_pb2_grpc,
12-
)
139
from ni_measurementlink_service.discovery import DiscoveryClient
1410
from ni_measurementlink_service.measurement.service import GrpcChannelPool
1511

1612

17-
class PinMapClient(object):
18-
"""Class that communicates with the pin map service."""
19-
20-
def __init__(self, *, grpc_channel: grpc.Channel):
21-
"""Initialize pin map client."""
22-
self._client: pin_map_service_pb2_grpc.PinMapServiceStub = (
23-
pin_map_service_pb2_grpc.PinMapServiceStub(grpc_channel)
24-
)
25-
26-
def update_pin_map(self, pin_map_path: str) -> str:
27-
"""Update registered pin map contents.
28-
29-
Create and register a pin map if a pin map resource for the specified pin map id is not
30-
found.
31-
32-
Args:
33-
pin_map_path: The file path of the pin map to register as a pin map resource.
34-
35-
Returns:
36-
The resource id of the pin map that is registered to the pin map service.
37-
"""
38-
pin_map_path_obj = pathlib.Path(pin_map_path)
39-
# By convention, the pin map id is the .pinmap file path.
40-
request = pin_map_service_pb2.UpdatePinMapFromXmlRequest(
41-
pin_map_id=pin_map_path, pin_map_xml=pin_map_path_obj.read_text(encoding="utf-8")
42-
)
43-
response: pin_map_service_pb2.PinMap = self._client.UpdatePinMapFromXml(request)
44-
return response.pin_map_id
45-
46-
4713
class GrpcChannelPoolHelper(GrpcChannelPool):
4814
"""Class that manages gRPC channel lifetimes."""
4915

@@ -77,7 +43,7 @@ def __init__(self, sequence_context: Any) -> None:
7743
self._sequence_context = sequence_context
7844

7945
def get_active_pin_map_id(self) -> str:
80-
"""Get the active pin map id from the NI.MeasurementLink.PinMapId temporary global variable.
46+
"""Get the active pin map id from the NI.MeasurementLink.PinMapId runtime variable.
8147
8248
Returns:
8349
The resource id of the pin map that is registered to the pin map service.

examples/nifgen_standard_function/_helpers.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,10 @@
66

77
import click
88
import grpc
9-
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pinmap.v1 import (
10-
pin_map_service_pb2,
11-
pin_map_service_pb2_grpc,
12-
)
139
from ni_measurementlink_service.discovery import DiscoveryClient
1410
from ni_measurementlink_service.measurement.service import GrpcChannelPool
1511

1612

17-
class PinMapClient(object):
18-
"""Class that communicates with the pin map service."""
19-
20-
def __init__(self, *, grpc_channel: grpc.Channel):
21-
"""Initialize pin map client."""
22-
self._client: pin_map_service_pb2_grpc.PinMapServiceStub = (
23-
pin_map_service_pb2_grpc.PinMapServiceStub(grpc_channel)
24-
)
25-
26-
def update_pin_map(self, pin_map_path: str) -> str:
27-
"""Update registered pin map contents.
28-
29-
Create and register a pin map if a pin map resource for the specified pin map id is not
30-
found.
31-
32-
Args:
33-
pin_map_path: The file path of the pin map to register as a pin map resource.
34-
35-
Returns:
36-
The resource id of the pin map that is registered to the pin map service.
37-
"""
38-
pin_map_path_obj = pathlib.Path(pin_map_path)
39-
# By convention, the pin map id is the .pinmap file path.
40-
request = pin_map_service_pb2.UpdatePinMapFromXmlRequest(
41-
pin_map_id=pin_map_path, pin_map_xml=pin_map_path_obj.read_text(encoding="utf-8")
42-
)
43-
response: pin_map_service_pb2.PinMap = self._client.UpdatePinMapFromXml(request)
44-
return response.pin_map_id
45-
46-
4713
class GrpcChannelPoolHelper(GrpcChannelPool):
4814
"""Class that manages gRPC channel lifetimes."""
4915

@@ -77,7 +43,7 @@ def __init__(self, sequence_context: Any) -> None:
7743
self._sequence_context = sequence_context
7844

7945
def get_active_pin_map_id(self) -> str:
80-
"""Get the active pin map id from the NI.MeasurementLink.PinMapId temporary global variable.
46+
"""Get the active pin map id from the NI.MeasurementLink.PinMapId runtime variable.
8147
8248
Returns:
8349
The resource id of the pin map that is registered to the pin map service.

examples/niscope_acquire_waveform/_helpers.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,10 @@
66

77
import click
88
import grpc
9-
from ni_measurementlink_service._internal.stubs.ni.measurementlink.pinmap.v1 import (
10-
pin_map_service_pb2,
11-
pin_map_service_pb2_grpc,
12-
)
139
from ni_measurementlink_service.discovery import DiscoveryClient
1410
from ni_measurementlink_service.measurement.service import GrpcChannelPool
1511

1612

17-
class PinMapClient(object):
18-
"""Class that communicates with the pin map service."""
19-
20-
def __init__(self, *, grpc_channel: grpc.Channel):
21-
"""Initialize pin map client."""
22-
self._client: pin_map_service_pb2_grpc.PinMapServiceStub = (
23-
pin_map_service_pb2_grpc.PinMapServiceStub(grpc_channel)
24-
)
25-
26-
def update_pin_map(self, pin_map_path: str) -> str:
27-
"""Update registered pin map contents.
28-
29-
Create and register a pin map if a pin map resource for the specified pin map id is not
30-
found.
31-
32-
Args:
33-
pin_map_path: The file path of the pin map to register as a pin map resource.
34-
35-
Returns:
36-
The resource id of the pin map that is registered to the pin map service.
37-
"""
38-
pin_map_path_obj = pathlib.Path(pin_map_path)
39-
# By convention, the pin map id is the .pinmap file path.
40-
request = pin_map_service_pb2.UpdatePinMapFromXmlRequest(
41-
pin_map_id=pin_map_path, pin_map_xml=pin_map_path_obj.read_text(encoding="utf-8")
42-
)
43-
response: pin_map_service_pb2.PinMap = self._client.UpdatePinMapFromXml(request)
44-
return response.pin_map_id
45-
46-
4713
class GrpcChannelPoolHelper(GrpcChannelPool):
4814
"""Class that manages gRPC channel lifetimes."""
4915

@@ -77,7 +43,7 @@ def __init__(self, sequence_context: Any) -> None:
7743
self._sequence_context = sequence_context
7844

7945
def get_active_pin_map_id(self) -> str:
80-
"""Get the active pin map id from the NI.MeasurementLink.PinMapId temporary global variable.
46+
"""Get the active pin map id from the NI.MeasurementLink.PinMapId runtime variable.
8147
8248
Returns:
8349
The resource id of the pin map that is registered to the pin map service.

0 commit comments

Comments
 (0)