Skip to content

Commit

Permalink
Add serial number to CWScope (#166)
Browse files Browse the repository at this point in the history
* Add serial number to CWScope

Allow the use of multiple scopes connected to the same computer.
  • Loading branch information
wsxrdv authored Oct 16, 2023
1 parent e3a7774 commit 90d30b0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions scaaml/capture/scope/cw_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
"""Context manager for the scope."""

from typing import Optional

import chipwhisperer as cw
from chipwhisperer.capture.scopes.cwnano import CWNano

Expand All @@ -22,8 +24,14 @@
class CWScope(AbstractSScope):
"""Scope context manager."""

def __init__(self, gain: int, samples: int, offset: int, clock: int,
sample_rate: str, **_):
def __init__(self,
gain: int,
samples: int,
offset: int,
clock: int,
sample_rate: str,
cw_scope_serial_number: Optional[str] = None,
**_) -> None:
"""Create scope context.
Args:
Expand All @@ -32,6 +40,9 @@ def __init__(self, gain: int, samples: int, offset: int, clock: int,
offset: Number of samples to wait before starting recording data.
clock: CLKGEN output frequency (in Hz).
sample_rate: Clock source for cw.ClockSettings.adc_src.
cw_scope_serial_number (Optional[str]): Serial number of the
ChipWhisperer. Can be obtained by calling cw.list_devices() (the
key "sn"). Defaults to None -- used when there is only one device.
_: CWScope is expected to be initialized using the capture_info
dictionary which may contain extra keys (additional information
about the capture; the capture_info dictionary is saved in the
Expand All @@ -51,6 +62,7 @@ def __init__(self, gain: int, samples: int, offset: int, clock: int,
# Use the scope object.
"""
super().__init__(samples=samples, offset=offset)

self._gain = gain
self._clock = clock
self._sample_rate = sample_rate
Expand All @@ -59,6 +71,7 @@ def __init__(self, gain: int, samples: int, offset: int, clock: int,
self._freq_ctr_src = "clkgen"
self._presamples = 0
self._scope = None
self._sn = cw_scope_serial_number

def __enter__(self):
"""Create scope context.
Expand All @@ -67,7 +80,7 @@ def __enter__(self):
"""
assert self._scope is None # Do not allow nested with.

scope = cw.scope()
scope = cw.scope(sn=self._sn)
assert not isinstance(scope, CWNano)
self._scope = scope

Expand Down

0 comments on commit 90d30b0

Please sign in to comment.