mirror of
https://github.com/jonathanhogg/scopething
synced 2025-07-13 18:52:10 +01:00
Historic bug; saner method naming; linter fix
This commit is contained in:
4
scope.py
4
scope.py
@ -39,8 +39,8 @@ class Scope(vm.VirtualMachine):
|
||||
|
||||
async def connect(self, url=None):
|
||||
if url is None:
|
||||
for port in streams.SerialStream.ports_matching(vid=0x0403, pid=0x6001):
|
||||
url = f'file:{port.device}'
|
||||
for device in streams.SerialStream.devices_matching(vid=0x0403, pid=0x6001):
|
||||
url = f'file:{device}'
|
||||
break
|
||||
else:
|
||||
raise RuntimeError("No matching serial device found")
|
||||
|
11
streams.py
11
streams.py
@ -20,22 +20,22 @@ LOG = logging.getLogger(__name__)
|
||||
class SerialStream:
|
||||
|
||||
@classmethod
|
||||
def ports_matching(cls, vid=None, pid=None, serial=None):
|
||||
def devices_matching(cls, vid=None, pid=None, serial=None):
|
||||
for port in comports():
|
||||
if (vid is None or vid == port.vid) and (pid is None or pid == port.pid) and (serial is None or serial == port.serial_number):
|
||||
yield port
|
||||
yield port.device
|
||||
|
||||
@classmethod
|
||||
def stream_matching(cls, vid=None, pid=None, serial=None, **kwargs):
|
||||
for port in cls.devices_matching(vid, pid, serial):
|
||||
return SerialStream(port.device, **kwargs)
|
||||
for device in cls.devices_matching(vid, pid, serial):
|
||||
return SerialStream(device, **kwargs)
|
||||
raise RuntimeError("No matching serial device")
|
||||
|
||||
def __init__(self, device, use_threads=None, loop=None, **kwargs):
|
||||
self._device = device
|
||||
self._use_threads = sys.platform == 'win32' if use_threads is None else use_threads
|
||||
self._connection = serial.Serial(self._device, **kwargs) if self._use_threads else \
|
||||
serial.Serial(self._device, timeout=0, write_timeout=0, **kwargs)
|
||||
serial.Serial(self._device, timeout=0, write_timeout=0, **kwargs)
|
||||
LOG.debug(f"Opened SerialStream on {device}")
|
||||
self._loop = loop if loop is not None else asyncio.get_event_loop()
|
||||
self._output_buffer = bytes()
|
||||
@ -138,4 +138,3 @@ class SerialStream:
|
||||
while len(data) < n:
|
||||
data += await self.read(n-len(data))
|
||||
return data
|
||||
|
||||
|
Reference in New Issue
Block a user