Skip to content

Commit 6083f85

Browse files
authored
Add set_runtime_environment functionality to niscope (#1975)
* Update niscope metadata to add set_runtime_environment functionality * Update CHANGELOG
1 parent eb7f396 commit 6083f85

File tree

12 files changed

+158
-83
lines changed

12 files changed

+158
-83
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ All notable changes to this project will be documented in this file.
6060
* ### `niscope` (NI-SCOPE)
6161
* #### Added
6262
* `get_channel_names()`
63+
* Pass Python interpreter information if the driver runtime version supports it. This is used by NI in order to better understand client usage.
6364
* #### Changed
6465
* Fix [#1770](https://github.com/ni/nimi-python/issues/1770): fetch(), read(), and friends return wrong data when called with channel ranges on multi-instrument session.
6566
* #### Removed

docs/niscope/class.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,12 +1916,12 @@ get_channel_names
19161916
- A range using a hyphen—for example, "0-3"
19171917
- A range using a colon—for example, "0:3 "
19181918
1919-
You can combine comma-separated lists and ranges that use a hyphen or colon. Both out-of-order and repeated indices are supported ("2,3,0," "1,2,2,3"). White space characters, including spaces, tabs, feeds, and carriage returns, are allowed between characters. Ranges can be incrementing or decrementing.
1919+
You can combine comma-separated lists and ranges that use a hyphen or colon. Both out-of-order and repeated indices are supported ("2,3,0", "1,2,2,3"). White space characters, including spaces, tabs, feeds, and carriage returns, are allowed between characters. Ranges can be incrementing or decrementing.
19201920
19211921
19221922
19231923
1924-
:type indices: basic sequence types or str or int
1924+
:type indices: basic sequence types, str, or int
19251925
19261926
:rtype: list of str
19271927
:return:

generated/niscope/niscope/_grpc_stub_interpreter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ def set_attribute_vi_string(self, channel_list, attribute_id, value): # noqa: N
425425
grpc_types.SetAttributeViStringRequest(vi=self._vi, channel_list=channel_list, attribute_id=attribute_id, value_raw=value),
426426
)
427427

428+
def set_runtime_environment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
429+
raise NotImplementedError('set_runtime_environment is not supported over gRPC')
430+
428431
def unlock(self): # noqa: N802
429432
self._lock.release()
430433

generated/niscope/niscope/_library.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def __init__(self, ctypes_library):
8080
self.niScope_SetAttributeViInt64_cfunc = None
8181
self.niScope_SetAttributeViReal64_cfunc = None
8282
self.niScope_SetAttributeViString_cfunc = None
83+
self.niScope_SetRuntimeEnvironment_cfunc = None
8384
self.niScope_UnlockSession_cfunc = None
8485
self.niScope_close_cfunc = None
8586
self.niScope_error_message_cfunc = None
@@ -549,6 +550,14 @@ def niScope_SetAttributeViString(self, vi, channel_list, attribute_id, value):
549550
self.niScope_SetAttributeViString_cfunc.restype = ViStatus # noqa: F405
550551
return self.niScope_SetAttributeViString_cfunc(vi, channel_list, attribute_id, value)
551552

553+
def niScope_SetRuntimeEnvironment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
554+
with self._func_lock:
555+
if self.niScope_SetRuntimeEnvironment_cfunc is None:
556+
self.niScope_SetRuntimeEnvironment_cfunc = self._get_library_function('niScope_SetRuntimeEnvironment')
557+
self.niScope_SetRuntimeEnvironment_cfunc.argtypes = [ctypes.POINTER(ViChar), ctypes.POINTER(ViChar), ctypes.POINTER(ViChar), ctypes.POINTER(ViChar)] # noqa: F405
558+
self.niScope_SetRuntimeEnvironment_cfunc.restype = ViStatus # noqa: F405
559+
return self.niScope_SetRuntimeEnvironment_cfunc(environment, environment_version, reserved1, reserved2)
560+
552561
def niScope_UnlockSession(self, vi, caller_has_lock): # noqa: N802
553562
with self._func_lock:
554563
if self.niScope_UnlockSession_cfunc is None:

generated/niscope/niscope/_library_interpreter.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import array
55
import ctypes
66
import hightime # noqa: F401
7+
import platform
8+
79
import niscope._library_singleton as _library_singleton
810
import niscope._visatype as _visatype
911
import niscope.enums as enums # noqa: F401
@@ -14,6 +16,9 @@
1416
import niscope.measurement_stats as measurement_stats # noqa: F401
1517

1618

19+
_was_runtime_environment_set = None
20+
21+
1722
# Helper functions for creating ctypes needed for calling into the driver DLL
1823
def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None):
1924
if isinstance(value, array.array):
@@ -60,6 +65,21 @@ class LibraryInterpreter(object):
6065
def __init__(self, encoding):
6166
self._encoding = encoding
6267
self._library = _library_singleton.get()
68+
global _was_runtime_environment_set
69+
if _was_runtime_environment_set is None:
70+
try:
71+
runtime_env = platform.python_implementation()
72+
version = platform.python_version()
73+
self.set_runtime_environment(
74+
runtime_env,
75+
version,
76+
'',
77+
''
78+
)
79+
except errors.DriverTooOldError:
80+
pass
81+
finally:
82+
_was_runtime_environment_set = True
6383
# Initialize _vi to 0 for now.
6484
# Session will directly update it once the driver runtime init function has been called and
6585
# we have a valid session handle.
@@ -650,6 +670,15 @@ def set_attribute_vi_string(self, channel_list, attribute_id, value): # noqa: N
650670
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
651671
return
652672

673+
def set_runtime_environment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
674+
environment_ctype = ctypes.create_string_buffer(environment.encode(self._encoding)) # case C020
675+
environment_version_ctype = ctypes.create_string_buffer(environment_version.encode(self._encoding)) # case C020
676+
reserved1_ctype = ctypes.create_string_buffer(reserved1.encode(self._encoding)) # case C020
677+
reserved2_ctype = ctypes.create_string_buffer(reserved2.encode(self._encoding)) # case C020
678+
error_code = self._library.niScope_SetRuntimeEnvironment(environment_ctype, environment_version_ctype, reserved1_ctype, reserved2_ctype)
679+
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
680+
return
681+
653682
def unlock(self): # noqa: N802
654683
vi_ctype = _visatype.ViSession(self._vi) # case S110
655684
error_code = self._library.niScope_UnlockSession(vi_ctype, None)

generated/niscope/niscope/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4857,13 +4857,13 @@ def get_channel_names(self, indices):
48574857
Returns a list of channel names for given channel indices.
48584858
48594859
Args:
4860-
indices (basic sequence types or str or int): Index list for the channels in the session. Valid values are from zero to the total number of channels in the session minus one. The index string can be one of the following formats:
4860+
indices (basic sequence types, str, or int): Index list for the channels in the session. Valid values are from zero to the total number of channels in the session minus one. The index string can be one of the following formats:
48614861
48624862
- A comma-separated list—for example, "0,2,3,1"
48634863
- A range using a hyphen—for example, "0-3"
48644864
- A range using a colon—for example, "0:3 "
48654865
4866-
You can combine comma-separated lists and ranges that use a hyphen or colon. Both out-of-order and repeated indices are supported ("2,3,0," "1,2,2,3"). White space characters, including spaces, tabs, feeds, and carriage returns, are allowed between characters. Ranges can be incrementing or decrementing.
4866+
You can combine comma-separated lists and ranges that use a hyphen or colon. Both out-of-order and repeated indices are supported ("2,3,0", "1,2,2,3"). White space characters, including spaces, tabs, feeds, and carriage returns, are allowed between characters. Ranges can be incrementing or decrementing.
48674867
48684868
48694869
Returns:

generated/niscope/niscope/unit_tests/_mock_helper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def __init__(self):
167167
self._defaults['SetAttributeViReal64']['return'] = 0
168168
self._defaults['SetAttributeViString'] = {}
169169
self._defaults['SetAttributeViString']['return'] = 0
170+
self._defaults['SetRuntimeEnvironment'] = {}
171+
self._defaults['SetRuntimeEnvironment']['return'] = 0
170172
self._defaults['UnlockSession'] = {}
171173
self._defaults['UnlockSession']['return'] = 0
172174
self._defaults['UnlockSession']['callerHasLock'] = None
@@ -781,6 +783,11 @@ def niScope_SetAttributeViString(self, vi, channel_list, attribute_id, value):
781783
return self._defaults['SetAttributeViString']['return']
782784
return self._defaults['SetAttributeViString']['return']
783785

786+
def niScope_SetRuntimeEnvironment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
787+
if self._defaults['SetRuntimeEnvironment']['return'] != 0:
788+
return self._defaults['SetRuntimeEnvironment']['return']
789+
return self._defaults['SetRuntimeEnvironment']['return']
790+
784791
def niScope_UnlockSession(self, vi, caller_has_lock): # noqa: N802
785792
if self._defaults['UnlockSession']['return'] != 0:
786793
return self._defaults['UnlockSession']['return']
@@ -950,6 +957,8 @@ def set_side_effects_and_return_values(self, mock_library):
950957
mock_library.niScope_SetAttributeViReal64.return_value = 0
951958
mock_library.niScope_SetAttributeViString.side_effect = MockFunctionCallError("niScope_SetAttributeViString")
952959
mock_library.niScope_SetAttributeViString.return_value = 0
960+
mock_library.niScope_SetRuntimeEnvironment.side_effect = MockFunctionCallError("niScope_SetRuntimeEnvironment")
961+
mock_library.niScope_SetRuntimeEnvironment.return_value = 0
953962
mock_library.niScope_UnlockSession.side_effect = MockFunctionCallError("niScope_UnlockSession")
954963
mock_library.niScope_UnlockSession.return_value = 0
955964
mock_library.niScope_close.side_effect = MockFunctionCallError("niScope_close")

src/niscope/metadata/attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# This file is generated from NI-SCOPE API metadata version 23.1.0f21
2+
# This file is generated from NI-SCOPE API metadata version 23.5.0d118
33
attributes = {
44
1050005: {
55
'access': 'read-write',

src/niscope/metadata/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
# This file is generated from NI-SCOPE API metadata version 23.1.0f21
2+
# This file is generated from NI-SCOPE API metadata version 23.5.0d118
33
config = {
4-
'api_version': '23.1.0f21',
4+
'api_version': '23.5.0d118',
55
'c_function_prefix': 'niScope_',
66
'close_function': 'close',
77
'context_manager_name': {

src/niscope/metadata/enums.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# This file is generated from NI-SCOPE API metadata version 23.1.0f21
2+
# This file is generated from NI-SCOPE API metadata version 23.5.0d118
33
enums = {
44
'5900AccessoryInAScopeSessionValues': {
55
'values': [
@@ -346,13 +346,13 @@
346346
'name': 'NISCOPE_VAL_ATTRIBUTE_RETRIEVAL_MODE_COERCED',
347347
'value': 0
348348
},
349-
{
350-
'name': 'NISCOPE_VAL_ATTRIBUTE_RETRIEVAL_MODE_DEFAULT',
351-
'value': 2
352-
},
353349
{
354350
'name': 'NISCOPE_VAL_ATTRIBUTE_RETRIEVAL_MODE_DESIRED',
355351
'value': 1
352+
},
353+
{
354+
'name': 'NISCOPE_VAL_ATTRIBUTE_RETRIEVAL_MODE_DEFAULT',
355+
'value': 2
356356
}
357357
]
358358
},

0 commit comments

Comments
 (0)