Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions soti/umsats_soti/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def __init__(self):
def run(self):
try:
self.loop.run()
except KeyboardInterrupt:
pass
finally:
self.current_screen.on_exit(self.loop)

Expand Down
56 changes: 32 additions & 24 deletions soti/umsats_soti/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,28 @@ def _run(self):
print(f"[SerialDevice: {self.port}] Failed to open serial port: {e}")
return

while True:
try:
msg = self._write_queue.get_nowait()
if msg is None: # Check for termination sentinel
break # Exit process
ser.write(msg.serialize())
except queue.Empty:
pass

# Read if bytes are available
if ser.in_waiting >= MSG_SIZE:
data = ser.read(MSG_SIZE)
try:
while True:
try:
msg = Message.deserialize(data)
self._read_queue.put(msg)
except Exception as e:
print(f"[SerialDevice: {self.port}] Deserialization error: {e}")
msg = self._write_queue.get_nowait()
if msg is None: # Check for termination sentinel
break # Exit process
ser.write(msg.serialize())
except queue.Empty:
pass

# Read if bytes are available
if ser.in_waiting >= MSG_SIZE:
data = ser.read(MSG_SIZE)
try:
msg = Message.deserialize(data)
self._read_queue.put(msg)
except KeyboardInterrupt:
raise
except Exception as e:
print(f"[SerialDevice: {self.port}] Deserialization error: {e}")
except KeyboardInterrupt:
pass

ser.close()

Expand All @@ -81,11 +86,14 @@ class VirtualDevice(Device):
"""For when no device is selected."""
def _run(self):
# Echo messages back to the user.
while True:
try:
msg = self._write_queue.get_nowait()
if msg is None: # Check for termination sentinel
break # Exit process
self._read_queue.put(msg)
except queue.Empty:
pass
try:
while True:
try:
msg = self._write_queue.get_nowait()
if msg is None: # Check for termination sentinel
break # Exit process
self._read_queue.put(msg)
except queue.Empty:
pass
except KeyboardInterrupt:
pass
Loading