|
4 | 4 | import array |
5 | 5 | import ctypes |
6 | 6 | import hightime # noqa: F401 |
| 7 | +import platform |
| 8 | + |
7 | 9 | import nidigital._library_singleton as _library_singleton |
8 | 10 | import nidigital._visatype as _visatype |
9 | 11 | import nidigital.enums as enums # noqa: F401 |
|
12 | 14 | import nidigital.history_ram_cycle_information as history_ram_cycle_information # noqa: F401 |
13 | 15 |
|
14 | 16 |
|
| 17 | +_was_runtime_environment_set = None |
| 18 | + |
| 19 | + |
15 | 20 | # Helper functions for creating ctypes needed for calling into the driver DLL |
16 | 21 | def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None): |
17 | 22 | if isinstance(value, array.array): |
@@ -58,6 +63,21 @@ class LibraryInterpreter(object): |
58 | 63 | def __init__(self, encoding): |
59 | 64 | self._encoding = encoding |
60 | 65 | 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 |
61 | 81 | # Initialize _vi to 0 for now. |
62 | 82 | # Session will directly update it once the driver runtime init function has been called and |
63 | 83 | # we have a valid session handle. |
@@ -870,6 +890,15 @@ def set_attribute_vi_string(self, channel_name, attribute, value): # noqa: N802 |
870 | 890 | errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False) |
871 | 891 | return |
872 | 892 |
|
| 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 | + |
873 | 902 | def tdr(self, channel_list, apply_offsets): # noqa: N802 |
874 | 903 | vi_ctype = _visatype.ViSession(self._vi) # case S110 |
875 | 904 | channel_list_ctype = ctypes.create_string_buffer(channel_list.encode(self._encoding)) # case C010 |
|
0 commit comments