From 8db583d3ee101b8081021c3dcaaa082240917dc3 Mon Sep 17 00:00:00 2001 From: Benedikt Moneke <67148916+bmoneke@users.noreply.github.com> Date: Thu, 14 Oct 2021 19:02:50 +0200 Subject: [PATCH] Fix issue with opening by serial number because of wrong data type. --- picoscope/ps3000a.py | 11 ++++++----- picoscope/ps4000.py | 23 ++++++++++++----------- picoscope/ps5000.py | 23 ++++++++++++----------- picoscope/ps5000a.py | 11 ++++++----- picoscope/ps6000.py | 23 ++++++++++++----------- 5 files changed, 48 insertions(+), 43 deletions(-) diff --git a/picoscope/ps3000a.py b/picoscope/ps3000a.py index 4f20794..5d053a3 100644 --- a/picoscope/ps3000a.py +++ b/picoscope/ps3000a.py @@ -151,14 +151,15 @@ def __init__(self, serialNumber=None, connect=True): super(PS3000a, self).__init__(serialNumber, connect) - def _lowLevelOpenUnit(self, sn): + def _lowLevelOpenUnit(self, serialNumber): c_handle = c_int16() - if sn is not None: - serialNullTermStr = byref(create_string_buffer(sn)) + if serialNumber is not None: + serialNumberStr = create_string_buffer(bytes(serialNumber, + encoding='utf-8')) else: - serialNullTermStr = None + serialNumberStr = None # Passing None is the same as passing NULL - m = self.lib.ps3000aOpenUnit(byref(c_handle), serialNullTermStr) + m = self.lib.ps3000aOpenUnit(byref(c_handle), serialNumberStr) self.handle = c_handle.value # copied over from ps5000a: diff --git a/picoscope/ps4000.py b/picoscope/ps4000.py index 3683d8e..cea46a1 100644 --- a/picoscope/ps4000.py +++ b/picoscope/ps4000.py @@ -158,26 +158,27 @@ def __init__(self, serialNumber=None, connect=True): raise NotImplementedError('Timebase functions have not been ' 'written for the ' + unit_number) - def _lowLevelOpenUnit(self, sn): + def _lowLevelOpenUnit(self, serialNumber): c_handle = c_int16() - if sn is not None: - serialNullTermStr = create_string_buffer(sn) + if serialNumber is not None: + serialNumberStr = create_string_buffer(bytes(serialNumber, + encoding='utf-8')) else: - serialNullTermStr = None + serialNumberStr = None # Passing None is the same as passing NULL - m = self.lib.ps4000OpenUnit(byref(c_handle), serialNullTermStr) + m = self.lib.ps4000OpenUnit(byref(c_handle), serialNumberStr) self.checkResult(m) self.handle = c_handle.value - def _lowLevelOpenUnitAsync(self, sn): + def _lowLevelOpenUnitAsync(self, serialNumber): c_status = c_int16() - if sn is not None: - serialNullTermStr = create_string_buffer(sn) + if serialNumber is not None: + serialNumberStr = create_string_buffer(bytes(serialNumber, + encoding='utf-8')) else: - serialNullTermStr = None - + serialNumberStr = None # Passing None is the same as passing NULL - m = self.lib.ps4000OpenUnitAsync(byref(c_status), serialNullTermStr) + m = self.lib.ps4000OpenUnitAsync(byref(c_status), serialNumberStr) self.checkResult(m) return c_status.value diff --git a/picoscope/ps5000.py b/picoscope/ps5000.py index f443fd1..5fcf59a 100644 --- a/picoscope/ps5000.py +++ b/picoscope/ps5000.py @@ -153,26 +153,27 @@ def __init__(self, serialNumber=None, connect=True): super(PS5000, self).__init__(serialNumber, connect) - def _lowLevelOpenUnit(self, sn): + def _lowLevelOpenUnit(self, serialNumber): c_handle = c_int16() - if sn is not None: - serialNullTermStr = create_string_buffer(sn) + if serialNumber is not None: + serialNumberStr = create_string_buffer(bytes(serialNumber, + encoding='utf-8')) else: - serialNullTermStr = None + serialNumberStr = None # Passing None is the same as passing NULL - m = self.lib.ps5000OpenUnit(byref(c_handle), serialNullTermStr) + m = self.lib.ps5000OpenUnit(byref(c_handle), serialNumberStr) self.checkResult(m) self.handle = c_handle.value - def _lowLevelOpenUnitAsync(self, sn): + def _lowLevelOpenUnitAsync(self, serialNumber): c_status = c_int16() - if sn is not None: - serialNullTermStr = create_string_buffer(sn) + if serialNumber is not None: + serialNumberStr = create_string_buffer(bytes(serialNumber, + encoding='utf-8')) else: - serialNullTermStr = None - + serialNumberStr = None # Passing None is the same as passing NULL - m = self.lib.ps5000OpenUnitAsync(byref(c_status), serialNullTermStr) + m = self.lib.ps5000OpenUnitAsync(byref(c_status), serialNumberStr) self.checkResult(m) return c_status.value diff --git a/picoscope/ps5000a.py b/picoscope/ps5000a.py index b84c05f..8d49a03 100644 --- a/picoscope/ps5000a.py +++ b/picoscope/ps5000a.py @@ -143,14 +143,15 @@ def __init__(self, serialNumber=None, connect=True): super(PS5000a, self).__init__(serialNumber, connect) - def _lowLevelOpenUnit(self, sn): + def _lowLevelOpenUnit(self, serialNumber): c_handle = c_int16() - if sn is not None: - serialNullTermStr = create_string_buffer(sn) + if serialNumber is not None: + serialNumberStr = create_string_buffer(bytes(serialNumber, + encoding='utf-8')) else: - serialNullTermStr = None + serialNumberStr = None # Passing None is the same as passing NULL - m = self.lib.ps5000aOpenUnit(byref(c_handle), serialNullTermStr, + m = self.lib.ps5000aOpenUnit(byref(c_handle), serialNumberStr, self.resolution) self.handle = c_handle.value diff --git a/picoscope/ps6000.py b/picoscope/ps6000.py index f7d1cbe..90c847f 100644 --- a/picoscope/ps6000.py +++ b/picoscope/ps6000.py @@ -154,26 +154,27 @@ def __init__(self, serialNumber=None, connect=True): super(PS6000, self).__init__(serialNumber, connect) - def _lowLevelOpenUnit(self, sn): + def _lowLevelOpenUnit(self, serialNumber): c_handle = c_int16() - if sn is not None: - serialNullTermStr = create_string_buffer(sn) + if serialNumber is not None: + serialNumberStr = create_string_buffer(bytes(serialNumber, + encoding='utf-8')) else: - serialNullTermStr = None + serialNumberStr = None # Passing None is the same as passing NULL - m = self.lib.ps6000OpenUnit(byref(c_handle), serialNullTermStr) + m = self.lib.ps6000OpenUnit(byref(c_handle), serialNumberStr) self.checkResult(m) self.handle = c_handle.value - def _lowLevelOpenUnitAsync(self, sn): + def _lowLevelOpenUnitAsync(self, serialNumber): c_status = c_int16() - if sn is not None: - serialNullTermStr = create_string_buffer(sn) + if serialNumber is not None: + serialNumberStr = create_string_buffer(bytes(serialNumber, + encoding='utf-8')) else: - serialNullTermStr = None - + serialNumberStr = None # Passing None is the same as passing NULL - m = self.lib.ps6000OpenUnitAsync(byref(c_status), serialNullTermStr) + m = self.lib.ps6000OpenUnitAsync(byref(c_status), serialNumberStr) self.checkResult(m) return c_status.value