Skip to content

Commit 448825e

Browse files
authored
nirfsg: Enable gRPC support without tests (#2171)
1 parent c328bc3 commit 448825e

22 files changed

+7469
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,7 @@
17061706
- `SCRIPTS` added to enum `LoadOptions`
17071707
- `DO_NOT_DRIVE_SIGNAL` added to enum `PulseModulationSource`
17081708
- `numpy` is now an install dependency
1709+
- gRPC support, enabling remote session management via NI gRPC Device Server
17091710
- Changed
17101711
- Removed
17111712

docs/nirfsg/class.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Session
44
=======
55

6-
.. py:class:: Session(self, resource_name, id_query=False, reset_device=False, options={})
6+
.. py:class:: Session(self, resource_name, id_query=False, reset_device=False, options={}, *, grpc_options=None)
77

88

99

@@ -111,6 +111,16 @@ Session
111111

112112
:type options: dict
113113

114+
:param grpc_options:
115+
116+
117+
MeasurementLink gRPC session options
118+
119+
120+
121+
122+
:type grpc_options: nirfsg.GrpcSessionOptions
123+
114124

115125
Methods
116126
=======

docs/nirfsg/errors.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ SelfTestError
7777
An error due to a failed self-test
7878

7979

80+
RpcError
81+
--------
82+
83+
.. py:currentmodule:: nirfsg.errors
84+
85+
.. exception:: RpcError
86+
87+
An error specific to sessions to the NI gRPC Device Server
88+
89+
8090
DriverWarning
8191
-------------
8292

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
gRPC Support
2+
============
3+
4+
Support for using NI-RFSG over gRPC
5+
6+
.. py:currentmodule:: nirfsg
7+
8+
9+
10+
SessionInitializationBehavior
11+
-----------------------------
12+
13+
.. py:class:: SessionInitializationBehavior
14+
15+
.. py:attribute:: SessionInitializationBehavior.AUTO
16+
17+
18+
The NI gRPC Device Server will attach to an existing session with the specified name if it exists,
19+
otherwise the server will initialize a new session.
20+
21+
.. note:: When using the Session as a context manager and the context exits, the behavior depends on what happened when the constructor
22+
was called. If it resulted in a new session being initialized on the NI gRPC Device Server, then it will automatically close the
23+
server session. If it instead attached to an existing session, then it will detach from the server session and leave it open.
24+
25+
26+
.. py:attribute:: SessionInitializationBehavior.INITIALIZE_SERVER_SESSION
27+
28+
29+
Require the NI gRPC Device Server to initialize a new session with the specified name.
30+
31+
.. note:: When using the Session as a context manager and the context exits, it will automatically close the
32+
server session.
33+
34+
35+
.. py:attribute:: SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION
36+
37+
38+
Require the NI gRPC Device Server to attach to an existing session with the specified name.
39+
40+
.. note:: When using the Session as a context manager and the context exits, it will detach from the server session
41+
and leave it open.
42+
43+
44+
45+
GrpcSessionOptions
46+
------------------
47+
48+
49+
.. py:class:: GrpcSessionOptions(self, grpc_channel, session_name, initialization_behavior=SessionInitializationBehavior.AUTO)
50+
51+
52+
Collection of options that specifies session behaviors related to gRPC.
53+
54+
Creates and returns an object you can pass to a Session constructor.
55+
56+
57+
:param grpc_channel:
58+
59+
60+
Specifies the channel to the NI gRPC Device Server.
61+
62+
63+
64+
:type grpc_channel: grpc.Channel
65+
66+
67+
:param session_name:
68+
69+
70+
User-specified name that identifies the driver session on the NI gRPC Device Server.
71+
72+
This is different from the resource name parameter many APIs take as a separate
73+
parameter. Specifying a name makes it easy to share sessions across multiple gRPC clients.
74+
You can use an empty string if you want to always initialize a new session on the server.
75+
To attach to an existing session, you must specify the session name it was initialized with.
76+
77+
78+
79+
:type session_name: str
80+
81+
82+
:param initialization_behavior:
83+
84+
85+
Specifies whether it is acceptable to initialize a new session or attach to an existing one, or if only one of the behaviors is desired.
86+
87+
The driver session exists on the NI gRPC Device Server.
88+
89+
90+
91+
:type initialization_behavior: :py:data:`nirfsg.SessionInitializationBehavior`

docs/nirfsg/toc.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ API Reference
88
enums
99
errors
1010
examples
11+
grpc_session_options
1112

generated/nirfsg/nirfsg/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from nirfsg.enums import * # noqa: F403,F401,H303
88
from nirfsg.errors import DriverWarning # noqa: F401
99
from nirfsg.errors import Error # noqa: F401
10+
from nirfsg.grpc_session_options import * # noqa: F403,F401,H303
1011
from nirfsg.session import Session # noqa: F401
1112

1213

0 commit comments

Comments
 (0)