aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJ08nY2023-02-15 17:21:25 +0100
committerJ08nY2023-02-15 17:21:25 +0100
commit6db49a89270b4bf2b062bf1384a425d14ee63f7c (patch)
tree8b202bc3dc4c28bf2fdf909359905a4d95ccb005
parent14c04894992e3def1f0be08849cce8c8014cd96d (diff)
downloadpyecsca-6db49a89270b4bf2b062bf1384a425d14ee63f7c.tar.gz
pyecsca-6db49a89270b4bf2b062bf1384a425d14ee63f7c.tar.zst
pyecsca-6db49a89270b4bf2b062bf1384a425d14ee63f7c.zip
Fix changs in ctypes with Picoscope SDK.
-rw-r--r--pyecsca/sca/scope/picoscope_sdk.py53
1 files changed, 35 insertions, 18 deletions
diff --git a/pyecsca/sca/scope/picoscope_sdk.py b/pyecsca/sca/scope/picoscope_sdk.py
index b673614..8728946 100644
--- a/pyecsca/sca/scope/picoscope_sdk.py
+++ b/pyecsca/sca/scope/picoscope_sdk.py
@@ -109,14 +109,14 @@ class PicoScopeSdk(Scope): # pragma: no cover
def get_variant(self):
if self._variant is not None:
return self._variant
- info = (ctypes.c_int8 * 6)()
+ info = ctypes.create_string_buffer(6)
size = ctypes.c_int16()
assert_pico_ok(
self.__dispatch_call(
- "GetUnitInfo", self.handle, ctypes.byref(info), 6, ctypes.byref(size), 3
+ "GetUnitInfo", self.handle, info, ctypes.c_int16(6), ctypes.byref(size), ctypes.c_uint(3)
)
)
- self._variant = "".join(chr(i) for i in info[: size.value])
+ self._variant = "".join(chr(i) for i in info[: size.value - 1]) # type: ignore
return self._variant
def setup_frequency(
@@ -129,6 +129,12 @@ class PicoScopeSdk(Scope): # pragma: no cover
):
if offset != 0.0:
raise ValueError("Nonzero offset not supported.")
+ if channel not in self.CHANNELS:
+ raise ValueError(f"Channel {channel} not in available channels: {self.CHANNELS.keys()}")
+ if coupling not in self.COUPLING:
+ raise ValueError(f"Coupling {coupling} not in available couplings: {self.COUPLING.keys()}")
+ if range not in self.RANGES:
+ raise ValueError(f"Range {range} not in available ranges: {self.RANGES.keys()}")
assert_pico_ok(
self.__dispatch_call(
"SetChannel",
@@ -335,6 +341,9 @@ class PicoScopeSdk(Scope): # pragma: no cover
assert_pico_ok(self.__dispatch_call("CloseUnit", self.handle))
def __dispatch_call(self, name, *args, **kwargs):
+ """
+ A unit-generic call of a picoscope SDK method.
+ """
method = getattr(self.MODULE, self.PREFIX + name)
if method is None:
raise ValueError
@@ -392,14 +401,14 @@ else: # pragma: no cover
def get_variant(self):
if self._variant is not None:
return self._variant
- info = (ctypes.c_int8 * 6)()
+ info = ctypes.create_string_buffer(6)
size = ctypes.c_int16(6)
assert_pico_ok(
self.__dispatch_call(
- "GetUnitInfo", self.handle, ctypes.byref(info), size, 3
+ "GetUnitInfo", self.handle, ctypes.byref(info), size, ctypes.c_int16(3)
)
)
- self._variant = "".join(chr(i) for i in info[: size.value])
+ self._variant = "".join(chr(i) for i in info[: size.value - 1]) # type: ignore
return self._variant
def set_frequency(
@@ -469,6 +478,8 @@ else: # pragma: no cover
return self._set_freq(
frequency, pretrig, posttrig, 0, 0, 0, 10_000_000, -1
)
+ else:
+ raise ValueError(f"Unknown variant: {variant}")
if isinstance(ps5000, CannotFindPicoSDKError):
@@ -498,18 +509,18 @@ else: # pragma: no cover
}
RANGES = {
- 0.01: 0,
- 0.02: 1,
- 0.05: 2,
- 0.10: 3,
- 0.20: 4,
- 0.50: 5,
- 1.00: 6,
- 2.00: 7,
- 5.00: 8,
- 10.0: 9,
- 20.0: 10,
- 50.0: 11,
+ 0.01: ps5000.PS5000_RANGE["PS5000_10MV"],
+ 0.02: ps5000.PS5000_RANGE["PS5000_20MV"],
+ 0.05: ps5000.PS5000_RANGE["PS5000_50MV"],
+ 0.10: ps5000.PS5000_RANGE["PS5000_100MV"],
+ 0.20: ps5000.PS5000_RANGE["PS5000_200MV"],
+ 0.50: ps5000.PS5000_RANGE["PS5000_500MV"],
+ 1.00: ps5000.PS5000_RANGE["PS5000_1V"],
+ 2.00: ps5000.PS5000_RANGE["PS5000_2V"],
+ 5.00: ps5000.PS5000_RANGE["PS5000_5V"],
+ 10.0: ps5000.PS5000_RANGE["PS5000_10V"],
+ 20.0: ps5000.PS5000_RANGE["PS5000_20V"],
+ 50.0: ps5000.PS5000_RANGE["PS5000_50V"],
}
MAX_ADC_VALUE = 32512
@@ -584,6 +595,12 @@ else: # pragma: no cover
range: float,
offset: float,
):
+ if channel not in self.CHANNELS:
+ raise ValueError(f"Channel {channel} not in available channels: {self.CHANNELS.keys()}")
+ if coupling not in self.COUPLING:
+ raise ValueError(f"Coupling {coupling} not in available couplings: {self.COUPLING.keys()}")
+ if range not in self.RANGES:
+ raise ValueError(f"Range {range} not in available ranges: {self.RANGES.keys()}")
assert_pico_ok(
ps6000.ps6000SetChannel(
self.handle,