Skip to content

Commit 0cbc2bd

Browse files
committed
Make black and pydocstyle happy
1 parent 0b169d9 commit 0cbc2bd

File tree

5 files changed

+86
-27
lines changed

5 files changed

+86
-27
lines changed

PSL/digital_channel.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Objects related to the PSLab's digital input channels.
2-
"""
1+
"""Objects related to the PSLab's digital input channels."""
32

43
import numpy as np
54

PSL/logic_analyzer.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,11 @@ def _capture_four(self, e2e_time: float):
404404
self._device.send_byte(self._prescaler)
405405

406406
try:
407-
trigger = {0: 4, 1: 8, 2: 16,}[
408-
self._trigger_channel.number
409-
] | self._trigger_mode
407+
trigger = {
408+
0: 4,
409+
1: 8,
410+
2: 16,
411+
}[self._trigger_channel.number] | self._trigger_mode
410412
except KeyError:
411413
e = "Triggering is only possible on LA1, LA2, or LA3."
412414
raise NotImplementedError(e)
@@ -592,7 +594,7 @@ def _get_initial_states_and_progress(self) -> Tuple[Dict[str, bool], List[int]]:
592594
return initial_states, progress
593595

594596
def configure_trigger(self, trigger_channel: str, trigger_mode: str):
595-
"""Setup trigger channel and trigger condition.
597+
"""Set up trigger channel and trigger condition.
596598
597599
Parameters
598600
----------
@@ -618,17 +620,20 @@ def _configure_trigger(self, channels: int):
618620
"sixteen rising": 5,
619621
}[self.trigger_mode]
620622
elif channels == 2:
621-
self._trigger_mode = {"disabled": 0, "falling": 3, "rising": 1,}[
622-
self.trigger_mode
623-
]
623+
self._trigger_mode = {
624+
"disabled": 0,
625+
"falling": 3,
626+
"rising": 1,
627+
}[self.trigger_mode]
624628
elif channels == 4:
625-
self._trigger_mode = {"disabled": 0, "falling": 1, "rising": 3,}[
626-
self.trigger_mode
627-
]
629+
self._trigger_mode = {
630+
"disabled": 0,
631+
"falling": 1,
632+
"rising": 3,
633+
}[self.trigger_mode]
628634

629635
def stop(self):
630-
"""Stop a running :meth:`capture` function.
631-
"""
636+
"""Stop a running :meth:`capture` function."""
632637
self._device.send_byte(CP.TIMING)
633638
self._device.send_byte(CP.STOP_LA)
634639
self._device.get_ack()
@@ -657,7 +662,7 @@ def get_states(self) -> Dict[str, bool]:
657662
def count_pulses(
658663
self, channel: str, interval: float = 1, block: bool = True
659664
) -> Union[int, None]:
660-
""" Count pulses on a digital input.
665+
"""Count pulses on a digital input.
661666
662667
The counter is 16 bits, so it will roll over after 65535 pulses. This method
663668
can be used at the same time as the oscilloscope.

PSL/oscilloscope.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ def __init__(self, device: packet_handler.Handler = None):
4545
self._trigger_enabled = False
4646
self._trigger_channel = "CH1"
4747

48-
def capture(self, channels: int, samples: int, timegap: float,) -> np.ndarray:
48+
def capture(
49+
self,
50+
channels: int,
51+
samples: int,
52+
timegap: float,
53+
) -> np.ndarray:
4954
"""Capture an oscilloscope trace from the specified input channels.
5055
5156
This is a blocking call.

PSL/packet_handler.py

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def _list_ports() -> List[str]: # Promote to public?
7777
return [p.device for p in list_ports.comports()]
7878

7979
def connect(
80-
self, port: str = None, baudrate: int = 1000000, timeout: float = 1.0,
80+
self,
81+
port: str = None,
82+
baudrate: int = 1000000,
83+
timeout: float = 1.0,
8184
):
8285
"""Connect to PSLab.
8386
@@ -100,7 +103,10 @@ def connect(
100103
"""
101104
# serial.Serial opens automatically if port is not None.
102105
self.interface = serial.Serial(
103-
port=port, baudrate=baudrate, timeout=timeout, write_timeout=timeout,
106+
port=port,
107+
baudrate=baudrate,
108+
timeout=timeout,
109+
write_timeout=timeout,
104110
)
105111

106112
if self.interface.is_open:
@@ -132,7 +138,10 @@ def disconnect(self):
132138
self.interface.close()
133139

134140
def reconnect(
135-
self, port: str = None, baudrate: int = None, timeout: float = None,
141+
self,
142+
port: str = None,
143+
baudrate: int = None,
144+
timeout: float = None,
136145
):
137146
"""Reconnect to PSLab.
138147
@@ -151,7 +160,10 @@ def reconnect(
151160
timeout = self.interface.timeout if timeout is None else timeout
152161

153162
self.interface = serial.Serial(
154-
port=port, baudrate=baudrate, timeout=timeout, write_timeout=timeout,
163+
port=port,
164+
baudrate=baudrate,
165+
timeout=timeout,
166+
write_timeout=timeout,
155167
)
156168
self.connect()
157169

@@ -265,11 +277,34 @@ def _receive(self, size: int) -> int:
265277
return retval
266278

267279
def read(self, number_of_bytes: int) -> bytes:
280+
"""Log incoming bytes.
281+
282+
Wrapper for Serial.read().
283+
284+
Parameters
285+
----------
286+
number_of_bytes : int
287+
Number of bytes to read from the serial port.
288+
289+
Returns
290+
-------
291+
bytes
292+
Bytes read from the serial port.
293+
"""
268294
data = self.interface.read(number_of_bytes)
269295
self._write_log(data, "RX")
270296
return data
271297

272298
def write(self, data: bytes):
299+
"""Log outgoing bytes.
300+
301+
Wrapper for Serial.write().
302+
303+
Parameters
304+
----------
305+
data : int
306+
Bytes to write to the serial port.
307+
"""
273308
self.interface.write(data)
274309
self._write_log(data, "TX")
275310

@@ -351,47 +386,63 @@ class MockHandler(Handler):
351386
VERSION = "PSLab vMOCK"
352387

353388
def __init__(
354-
self, port: str = None, baudrate: int = 1000000, timeout: float = 1.0,
389+
self,
390+
port: str = None,
391+
baudrate: int = 1000000,
392+
timeout: float = 1.0,
355393
):
356394
self._in_buffer = b""
357395
super().__init__(port, baudrate, timeout)
358396

359397
def connect(
360-
self, port: str = None, baudrate: int = 1000000, timeout: float = 1.0,
398+
self,
399+
port: str = None,
400+
baudrate: int = 1000000,
401+
timeout: float = 1.0,
361402
):
403+
"""See :meth:`Handler.connect`."""
362404
self.version = self.get_version()
363405

364406
def disconnect(self):
407+
"""See :meth:`Handler.disconnect`."""
365408
pass
366409

367410
def reconnect(
368-
self, port: str = None, baudrate: int = None, timeout: float = None,
411+
self,
412+
port: str = None,
413+
baudrate: int = None,
414+
timeout: float = None,
369415
):
416+
"""See :meth:`Handler.reconnect`."""
370417
pass
371418

372419
def get_version(self, *args) -> str:
420+
"""Return mock version."""
373421
return self.VERSION
374422

375423
def read(self, number_of_bytes: int) -> bytes:
376424
"""Mimic the behavior of the serial bus by returning recorded RX traffic.
377425
378426
The returned data depends on how :meth:`write` was called prior to calling
379427
:meth:`read`.
428+
429+
See also :meth:`Handler.read`.
380430
"""
381431
read_bytes = self._in_buffer[:number_of_bytes]
382432
self._in_buffer = self._in_buffer[number_of_bytes:]
383433
return read_bytes
384434

385435
def write(self, data: bytes):
386436
"""Add recorded RX data to buffer if written data equals recorded TX data.
437+
438+
See also :meth:`Handler.write`.
387439
"""
388440
tx, rx = next(RECORDED_TRAFFIC)
389441
if tx == data:
390442
self._in_buffer += rx
391443

392444
def wait_for_data(self, timeout: float = 0.2) -> bool:
393-
"""Return True if there is data in buffer, or return False after timeout.
394-
"""
445+
"""Return True if there is data in buffer, or return False after timeout."""
395446
if self._in_buffer:
396447
return True
397448
else:

tests/test_logic_analyzer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def la(handler, request):
4040

4141

4242
def enable_pwm(psl: sciencelab.ScienceLab, test_name: str):
43-
"""Enable PWM output for integration testing.
44-
"""
43+
"""Enable PWM output for integration testing."""
4544
low_frequency_tests = (
4645
"test_capture_four_low_frequency",
4746
"test_capture_four_lower_frequency",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy