Skip to content

Commit aad5dfa

Browse files
authored
Add set_runtime_environment functionality to nidigital (#1972)
* Update nidigital metadata to add set_runtime_environment functionality * Update CHANGELOG * Fix nidigital unit test failure: set side_effect for for niDigital_SetRuntimeEnvironment
1 parent 5d94f21 commit aad5dfa

File tree

13 files changed

+108
-11
lines changed

13 files changed

+108
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ All notable changes to this project will be documented in this file.
4343
* #### Removed
4444
* ### `nidigital` (NI-Digital Pattern Driver)
4545
* #### Added
46+
* Pass Python interpreter information if the driver runtime version supports it. This is used by NI in order to better understand client usage.
4647
* #### Changed
4748
* #### Removed
4849
* ### `nidmm` (NI-DMM)

docs/nidigital/class.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,12 +1581,12 @@ get_channel_names
15811581
- A range using a hyphen—for example, "0-3"
15821582
- A range using a colon—for example, "0:3 "
15831583
1584-
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.
1584+
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.
15851585
15861586
15871587
15881588
1589-
:type indices: basic sequence types or str or int
1589+
:type indices: basic sequence types, str, or int
15901590
15911591
:rtype: list of str
15921592
:return:

generated/nidigital/nidigital/_grpc_stub_interpreter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ def set_attribute_vi_string(self, channel_name, attribute, value): # noqa: N802
568568
grpc_types.SetAttributeViStringRequest(vi=self._vi, channel_name=channel_name, attribute=attribute, value_raw=value),
569569
)
570570

571+
def set_runtime_environment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
572+
raise NotImplementedError('set_runtime_environment is not supported over gRPC')
573+
571574
def tdr(self, channel_list, apply_offsets): # noqa: N802
572575
response = self._invoke(
573576
self._client.TDR,

generated/nidigital/nidigital/_library.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def __init__(self, ctypes_library):
9898
self.niDigital_SetAttributeViInt64_cfunc = None
9999
self.niDigital_SetAttributeViReal64_cfunc = None
100100
self.niDigital_SetAttributeViString_cfunc = None
101+
self.niDigital_SetRuntimeEnvironment_cfunc = None
101102
self.niDigital_TDR_cfunc = None
102103
self.niDigital_UnloadAllPatterns_cfunc = None
103104
self.niDigital_UnloadSpecifications_cfunc = None
@@ -737,6 +738,14 @@ def niDigital_SetAttributeViString(self, vi, channel_name, attribute, value): #
737738
self.niDigital_SetAttributeViString_cfunc.restype = ViStatus # noqa: F405
738739
return self.niDigital_SetAttributeViString_cfunc(vi, channel_name, attribute, value)
739740

741+
def niDigital_SetRuntimeEnvironment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
742+
with self._func_lock:
743+
if self.niDigital_SetRuntimeEnvironment_cfunc is None:
744+
self.niDigital_SetRuntimeEnvironment_cfunc = self._get_library_function('niDigital_SetRuntimeEnvironment')
745+
self.niDigital_SetRuntimeEnvironment_cfunc.argtypes = [ctypes.POINTER(ViChar), ctypes.POINTER(ViChar), ctypes.POINTER(ViChar), ctypes.POINTER(ViChar)] # noqa: F405
746+
self.niDigital_SetRuntimeEnvironment_cfunc.restype = ViStatus # noqa: F405
747+
return self.niDigital_SetRuntimeEnvironment_cfunc(environment, environment_version, reserved1, reserved2)
748+
740749
def niDigital_TDR(self, vi, channel_list, apply_offsets, offsets_buffer_size, offsets, actual_num_offsets): # noqa: N802
741750
with self._func_lock:
742751
if self.niDigital_TDR_cfunc is None:

generated/nidigital/nidigital/_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 nidigital._library_singleton as _library_singleton
810
import nidigital._visatype as _visatype
911
import nidigital.enums as enums # noqa: F401
@@ -12,6 +14,9 @@
1214
import nidigital.history_ram_cycle_information as history_ram_cycle_information # noqa: F401
1315

1416

17+
_was_runtime_environment_set = None
18+
19+
1520
# Helper functions for creating ctypes needed for calling into the driver DLL
1621
def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None):
1722
if isinstance(value, array.array):
@@ -58,6 +63,21 @@ class LibraryInterpreter(object):
5863
def __init__(self, encoding):
5964
self._encoding = encoding
6065
self._library = _library_singleton.get()
66+
global _was_runtime_environment_set
67+
if _was_runtime_environment_set is None:
68+
try:
69+
runtime_env = platform.python_implementation()
70+
version = platform.python_version()
71+
self.set_runtime_environment(
72+
runtime_env,
73+
version,
74+
'',
75+
''
76+
)
77+
except errors.DriverTooOldError:
78+
pass
79+
finally:
80+
_was_runtime_environment_set = True
6181
# Initialize _vi to 0 for now.
6282
# Session will directly update it once the driver runtime init function has been called and
6383
# we have a valid session handle.
@@ -870,6 +890,15 @@ def set_attribute_vi_string(self, channel_name, attribute, value): # noqa: N802
870890
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
871891
return
872892

893+
def set_runtime_environment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
894+
environment_ctype = ctypes.create_string_buffer(environment.encode(self._encoding)) # case C020
895+
environment_version_ctype = ctypes.create_string_buffer(environment_version.encode(self._encoding)) # case C020
896+
reserved1_ctype = ctypes.create_string_buffer(reserved1.encode(self._encoding)) # case C020
897+
reserved2_ctype = ctypes.create_string_buffer(reserved2.encode(self._encoding)) # case C020
898+
error_code = self._library.niDigital_SetRuntimeEnvironment(environment_ctype, environment_version_ctype, reserved1_ctype, reserved2_ctype)
899+
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
900+
return
901+
873902
def tdr(self, channel_list, apply_offsets): # noqa: N802
874903
vi_ctype = _visatype.ViSession(self._vi) # case S110
875904
channel_list_ctype = ctypes.create_string_buffer(channel_list.encode(self._encoding)) # case C010

generated/nidigital/nidigital/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,13 +2489,13 @@ def get_channel_names(self, indices):
24892489
Returns a list of channel names for given channel indices.
24902490
24912491
Args:
2492-
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:
2492+
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:
24932493
24942494
- A comma-separated list—for example, "0,2,3,1"
24952495
- A range using a hyphen—for example, "0-3"
24962496
- A range using a colon—for example, "0:3 "
24972497
2498-
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.
2498+
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.
24992499
25002500
25012501
Returns:

generated/nidigital/nidigital/unit_tests/_mock_helper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ def __init__(self):
222222
self._defaults['SetAttributeViReal64']['return'] = 0
223223
self._defaults['SetAttributeViString'] = {}
224224
self._defaults['SetAttributeViString']['return'] = 0
225+
self._defaults['SetRuntimeEnvironment'] = {}
226+
self._defaults['SetRuntimeEnvironment']['return'] = 0
225227
self._defaults['TDR'] = {}
226228
self._defaults['TDR']['return'] = 0
227229
self._defaults['TDR']['actualNumOffsets'] = None
@@ -995,6 +997,11 @@ def niDigital_SetAttributeViString(self, vi, channel_name, attribute, value): #
995997
return self._defaults['SetAttributeViString']['return']
996998
return self._defaults['SetAttributeViString']['return']
997999

1000+
def niDigital_SetRuntimeEnvironment(self, environment, environment_version, reserved1, reserved2): # noqa: N802
1001+
if self._defaults['SetRuntimeEnvironment']['return'] != 0:
1002+
return self._defaults['SetRuntimeEnvironment']['return']
1003+
return self._defaults['SetRuntimeEnvironment']['return']
1004+
9981005
def niDigital_TDR(self, vi, channel_list, apply_offsets, offsets_buffer_size, offsets, actual_num_offsets): # noqa: N802
9991006
if self._defaults['TDR']['return'] != 0:
10001007
return self._defaults['TDR']['return']
@@ -1270,6 +1277,8 @@ def set_side_effects_and_return_values(self, mock_library):
12701277
mock_library.niDigital_SetAttributeViReal64.return_value = 0
12711278
mock_library.niDigital_SetAttributeViString.side_effect = MockFunctionCallError("niDigital_SetAttributeViString")
12721279
mock_library.niDigital_SetAttributeViString.return_value = 0
1280+
mock_library.niDigital_SetRuntimeEnvironment.side_effect = MockFunctionCallError("niDigital_SetRuntimeEnvironment")
1281+
mock_library.niDigital_SetRuntimeEnvironment.return_value = 0
12731282
mock_library.niDigital_TDR.side_effect = MockFunctionCallError("niDigital_TDR")
12741283
mock_library.niDigital_TDR.return_value = 0
12751284
mock_library.niDigital_UnloadAllPatterns.side_effect = MockFunctionCallError("niDigital_UnloadAllPatterns")

generated/nidigital/nidigital/unit_tests/test_nidigital.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def setup_method(self, method):
3939
self.side_effects_helper = _mock_helper.SideEffectsHelper()
4040
self.side_effects_helper.set_side_effects_and_return_values(self.patched_library)
4141

42+
# The side effect must be set for this, because it's called.
43+
# No need to set argument values; the method is tested in nifake unit tests, not here.
44+
self.patched_library.niDigital_SetRuntimeEnvironment.side_effect = self.side_effects_helper.niDigital_SetRuntimeEnvironment
45+
4246
self.patched_library.niDigital_InitWithOptions.side_effect = self.side_effects_helper.niDigital_InitWithOptions
4347
self.side_effects_helper['InitWithOptions']['newVi'] = session_id_for_test
4448

src/nidigital/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-Digital Pattern Driver API metadata version 23.3.0f165
2+
# This file is generated from NI-Digital Pattern Driver API metadata version 23.5.0d80
33
attributes = {
44
1050002: {
55
'access': 'read-write',

src/nidigital/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-Digital Pattern Driver API metadata version 23.3.0f165
2+
# This file is generated from NI-Digital Pattern Driver API metadata version 23.5.0d80
33
config = {
4-
'api_version': '23.3.0f165',
4+
'api_version': '23.5.0d80',
55
'c_function_prefix': 'niDigital_',
66
'close_function': 'close',
77
'context_manager_name': {

0 commit comments

Comments
 (0)