|
4 | 4 | import array |
5 | 5 | import ctypes |
6 | 6 | import hightime # noqa: F401 |
| 7 | +import platform |
| 8 | + |
7 | 9 | import niscope._library_singleton as _library_singleton |
8 | 10 | import niscope._visatype as _visatype |
9 | 11 | import niscope.enums as enums # noqa: F401 |
|
14 | 16 | import niscope.measurement_stats as measurement_stats # noqa: F401 |
15 | 17 |
|
16 | 18 |
|
| 19 | +_was_runtime_environment_set = None |
| 20 | + |
| 21 | + |
17 | 22 | # Helper functions for creating ctypes needed for calling into the driver DLL |
18 | 23 | def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None): |
19 | 24 | if isinstance(value, array.array): |
@@ -60,6 +65,21 @@ class LibraryInterpreter(object): |
60 | 65 | def __init__(self, encoding): |
61 | 66 | self._encoding = encoding |
62 | 67 | 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 |
63 | 83 | # Initialize _vi to 0 for now. |
64 | 84 | # Session will directly update it once the driver runtime init function has been called and |
65 | 85 | # we have a valid session handle. |
@@ -650,6 +670,15 @@ def set_attribute_vi_string(self, channel_list, attribute_id, value): # noqa: N |
650 | 670 | errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False) |
651 | 671 | return |
652 | 672 |
|
| 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 | + |
653 | 682 | def unlock(self): # noqa: N802 |
654 | 683 | vi_ctype = _visatype.ViSession(self._vi) # case S110 |
655 | 684 | error_code = self._library.niScope_UnlockSession(vi_ctype, None) |
|
0 commit comments