Skip to content

Commit 09c20c9

Browse files
committed
Improve robustness of FOC-Stim connection.
1 parent a4a15d8 commit 09c20c9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

qt_ui/output_widgets/focstim_device.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def stop_device(self):
7777
self.update_timer.stop()
7878

7979
def send_ping(self):
80+
self.old_dict = dict() # re-transmit all params every second to handle packet loss
8081
self.port.write(b'DPING\r\n')
8182

8283
def new_serial_data(self):
@@ -87,10 +88,17 @@ def new_serial_data(self):
8788

8889
if line.startswith(b'$') and line.count(b'$') == 1:
8990
parts = line[1:].split(b' ')
90-
self.sock.sendto(b'\r\n'.join(parts), teleplotAddr)
91+
try:
92+
self.sock.sendto(b'\r\n'.join(parts), teleplotAddr)
93+
except OSError:
94+
pass
9195
break
9296

93-
logger.info(line.decode('utf-8'))
97+
try:
98+
logger.info(line.decode('utf-8'))
99+
except UnicodeDecodeError:
100+
pass
101+
94102
if line == FOCSTIM_BOOT_MARKER:
95103
self.boot_marker_detected = True
96104
self.version_string_detected = False

0 commit comments

Comments
 (0)