From 09b43cc2898c7de7243b2d4d7e849b437e2a1b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20S=C3=BCltrop?= Date: Wed, 25 May 2022 21:49:51 +0200 Subject: [PATCH] EnumerateUnits throws an error if NULL pointer arguments are provided. Providing a buffer that fits 16 serial numbers to get around this issue. --- picoscope/ps3000a.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/picoscope/ps3000a.py b/picoscope/ps3000a.py index cf48b66..8a13251 100644 --- a/picoscope/ps3000a.py +++ b/picoscope/ps3000a.py @@ -180,13 +180,16 @@ def _lowLevelCloseUnit(self): def _lowLevelEnumerateUnits(self): count = c_int16(0) - m = self.lib.ps3000aEnumerateUnits(byref(count), None, None) - self.checkResult(m) # a serial number is rouhgly 8 characters # an extra character for the comma # and an extra one for the space after the comma? # the extra two also work for the null termination - serialLth = c_int16(count.value * (8 + 2)) + # The EnumeratUnits functions returns an error if NULL pointers + # are given as parameters. Thus it is not possible to determine the + # number of devices beforehand - if we assume that there will + # never be more than 16 devices connected, we should get along with + # a buffer that fits 16 serial numbers. + serialLth = c_int16(16 * (8 + 2)) serials = create_string_buffer(serialLth.value + 1) m = self.lib.ps3000aEnumerateUnits(byref(count), serials,