Skip to content

Commit 5d94f21

Browse files
authored
Add set_runtime_environment functionality to nidmm (#1973)
* Update dmm metadata to add set_runtime_environment functionality * Update CHANGELOG
1 parent 5892efb commit 5d94f21

File tree

9 files changed

+94
-5
lines changed

9 files changed

+94
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ All notable changes to this project will be documented in this file.
4747
* #### Removed
4848
* ### `nidmm` (NI-DMM)
4949
* #### Added
50+
* Pass Python interpreter information if the driver runtime version supports it. This is used by NI in order to better understand client usage.
5051
* #### Changed
5152
* #### Removed
5253
* ### `nifgen` (NI-FGEN)

generated/nidmm/nidmm/_grpc_stub_interpreter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ def set_attribute_vi_string(self, channel_name, attribute_id, attribute_value):
360360
grpc_types.SetAttributeViStringRequest(vi=self._vi, channel_name=channel_name, attribute_id=attribute_id, attribute_value_raw=attribute_value),
361361
)
362362

363+
def set_runtime_environment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
364+
raise NotImplementedError('set_runtime_environment is not supported over gRPC')
365+
363366
def unlock(self): # noqa: N802
364367
self._lock.release()
365368

generated/nidmm/nidmm/_library.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(self, ctypes_library):
6363
self.niDMM_SetAttributeViInt32_cfunc = None
6464
self.niDMM_SetAttributeViReal64_cfunc = None
6565
self.niDMM_SetAttributeViString_cfunc = None
66+
self.niDMM_SetRuntimeEnvironment_cfunc = None
6667
self.niDMM_UnlockSession_cfunc = None
6768
self.niDMM_close_cfunc = None
6869
self.niDMM_error_message_cfunc = None
@@ -428,6 +429,14 @@ def niDMM_SetAttributeViString(self, vi, channel_name, attribute_id, attribute_v
428429
self.niDMM_SetAttributeViString_cfunc.restype = ViStatus # noqa: F405
429430
return self.niDMM_SetAttributeViString_cfunc(vi, channel_name, attribute_id, attribute_value)
430431

432+
def niDMM_SetRuntimeEnvironment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
433+
with self._func_lock:
434+
if self.niDMM_SetRuntimeEnvironment_cfunc is None:
435+
self.niDMM_SetRuntimeEnvironment_cfunc = self._get_library_function('niDMM_SetRuntimeEnvironment')
436+
self.niDMM_SetRuntimeEnvironment_cfunc.argtypes = [ctypes.POINTER(ViChar), ctypes.POINTER(ViChar), ctypes.POINTER(ViChar), ctypes.POINTER(ViChar)] # noqa: F405
437+
self.niDMM_SetRuntimeEnvironment_cfunc.restype = ViStatus # noqa: F405
438+
return self.niDMM_SetRuntimeEnvironment_cfunc(environment, environment_version, reserved1, reserved2)
439+
431440
def niDMM_UnlockSession(self, vi, caller_has_lock): # noqa: N802
432441
with self._func_lock:
433442
if self.niDMM_UnlockSession_cfunc is None:

generated/nidmm/nidmm/_library_interpreter.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
import array
55
import ctypes
66
import hightime # noqa: F401
7+
import platform
8+
79
import nidmm._library_singleton as _library_singleton
810
import nidmm._visatype as _visatype
911
import nidmm.enums as enums # noqa: F401
1012
import nidmm.errors as errors
1113

1214

15+
_was_runtime_environment_set = None
16+
17+
1318
# Helper functions for creating ctypes needed for calling into the driver DLL
1419
def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None):
1520
if isinstance(value, array.array):
@@ -56,6 +61,21 @@ class LibraryInterpreter(object):
5661
def __init__(self, encoding):
5762
self._encoding = encoding
5863
self._library = _library_singleton.get()
64+
global _was_runtime_environment_set
65+
if _was_runtime_environment_set is None:
66+
try:
67+
runtime_env = platform.python_implementation()
68+
version = platform.python_version()
69+
self.set_runtime_environment(
70+
runtime_env,
71+
version,
72+
'',
73+
''
74+
)
75+
except errors.DriverTooOldError:
76+
pass
77+
finally:
78+
_was_runtime_environment_set = True
5979
# Initialize _vi to 0 for now.
6080
# Session will directly update it once the driver runtime init function has been called and
6181
# we have a valid session handle.
@@ -491,6 +511,15 @@ def set_attribute_vi_string(self, channel_name, attribute_id, attribute_value):
491511
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
492512
return
493513

514+
def set_runtime_environment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
515+
environment_ctype = ctypes.create_string_buffer(environment.encode(self._encoding)) # case C020
516+
environment_version_ctype = ctypes.create_string_buffer(environment_version.encode(self._encoding)) # case C020
517+
reserved1_ctype = ctypes.create_string_buffer(reserved1.encode(self._encoding)) # case C020
518+
reserved2_ctype = ctypes.create_string_buffer(reserved2.encode(self._encoding)) # case C020
519+
error_code = self._library.niDMM_SetRuntimeEnvironment(environment_ctype, environment_version_ctype, reserved1_ctype, reserved2_ctype)
520+
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
521+
return
522+
494523
def unlock(self): # noqa: N802
495524
vi_ctype = _visatype.ViSession(self._vi) # case S110
496525
error_code = self._library.niDMM_UnlockSession(vi_ctype, None)

generated/nidmm/nidmm/unit_tests/_mock_helper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def __init__(self):
138138
self._defaults['SetAttributeViReal64']['return'] = 0
139139
self._defaults['SetAttributeViString'] = {}
140140
self._defaults['SetAttributeViString']['return'] = 0
141+
self._defaults['SetRuntimeEnvironment'] = {}
142+
self._defaults['SetRuntimeEnvironment']['return'] = 0
141143
self._defaults['UnlockSession'] = {}
142144
self._defaults['UnlockSession']['return'] = 0
143145
self._defaults['UnlockSession']['callerHasLock'] = None
@@ -581,6 +583,11 @@ def niDMM_SetAttributeViString(self, vi, channel_name, attribute_id, attribute_v
581583
return self._defaults['SetAttributeViString']['return']
582584
return self._defaults['SetAttributeViString']['return']
583585

586+
def niDMM_SetRuntimeEnvironment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
587+
if self._defaults['SetRuntimeEnvironment']['return'] != 0:
588+
return self._defaults['SetRuntimeEnvironment']['return']
589+
return self._defaults['SetRuntimeEnvironment']['return']
590+
584591
def niDMM_UnlockSession(self, vi, caller_has_lock): # noqa: N802
585592
if self._defaults['UnlockSession']['return'] != 0:
586593
return self._defaults['UnlockSession']['return']
@@ -724,6 +731,8 @@ def set_side_effects_and_return_values(self, mock_library):
724731
mock_library.niDMM_SetAttributeViReal64.return_value = 0
725732
mock_library.niDMM_SetAttributeViString.side_effect = MockFunctionCallError("niDMM_SetAttributeViString")
726733
mock_library.niDMM_SetAttributeViString.return_value = 0
734+
mock_library.niDMM_SetRuntimeEnvironment.side_effect = MockFunctionCallError("niDMM_SetRuntimeEnvironment")
735+
mock_library.niDMM_SetRuntimeEnvironment.return_value = 0
727736
mock_library.niDMM_UnlockSession.side_effect = MockFunctionCallError("niDMM_UnlockSession")
728737
mock_library.niDMM_UnlockSession.return_value = 0
729738
mock_library.niDMM_close.side_effect = MockFunctionCallError("niDMM_close")

src/nidmm/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-DMM API metadata version 23.0.0f147
2+
# This file is generated from NI-DMM API metadata version 23.5.0d140
33
attributes = {
44
1050005: {
55
'access': 'read-write',

src/nidmm/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-DMM API metadata version 23.0.0f147
2+
# This file is generated from NI-DMM API metadata version 23.5.0d140
33
config = {
4-
'api_version': '23.0.0f147',
4+
'api_version': '23.5.0d140',
55
'c_function_prefix': 'niDMM_',
66
'close_function': 'close',
77
'context_manager_name': {

src/nidmm/metadata/enums.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-DMM API metadata version 23.0.0f147
2+
# This file is generated from NI-DMM API metadata version 23.5.0d140
33
enums = {
44
'ADCCalibration': {
55
'values': [

src/nidmm/metadata/functions.py

Lines changed: 39 additions & 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-DMM API metadata version 23.0.0f147
2+
# This file is generated from NI-DMM API metadata version 23.5.0d140
33
functions = {
44
'Abort': {
55
'documentation': {
@@ -2093,6 +2093,44 @@
20932093
],
20942094
'returns': 'ViStatus'
20952095
},
2096+
'SetRuntimeEnvironment': {
2097+
'codegen_method': 'private',
2098+
'documentation': {
2099+
'description': 'TBD'
2100+
},
2101+
'included_in_proto': False,
2102+
'method_templates': [
2103+
{
2104+
'documentation_filename': 'none',
2105+
'library_interpreter_filename': 'default_method',
2106+
'method_python_name_suffix': '',
2107+
'session_filename': 'none'
2108+
}
2109+
],
2110+
'parameters': [
2111+
{
2112+
'direction': 'in',
2113+
'name': 'environment',
2114+
'type': 'ViConstString'
2115+
},
2116+
{
2117+
'direction': 'in',
2118+
'name': 'environmentVersion',
2119+
'type': 'ViConstString'
2120+
},
2121+
{
2122+
'direction': 'in',
2123+
'name': 'reserved1',
2124+
'type': 'ViConstString'
2125+
},
2126+
{
2127+
'direction': 'in',
2128+
'name': 'reserved2',
2129+
'type': 'ViConstString'
2130+
}
2131+
],
2132+
'returns': 'ViStatus'
2133+
},
20962134
'UnlockSession': {
20972135
'documentation': {
20982136
'description': '\nThis function releases a lock that you acquired on an instrument session\nusing niDMM_LockSession. Refer to niDMM_LockSession for additional\ninformation on session locks.\n'

0 commit comments

Comments
 (0)