Skip to content

Commit b457e2c

Browse files
committed
ganglion: better detect if disconnects, timeout 1s
1 parent 29b9976 commit b457e2c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

open_bci_ganglion.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class OpenBCIBoard(object):
6060
"""
6161

6262
def __init__(self, port=None, baud=0, filter_data=False,
63-
scaled_output=True, daisy=False, log=True, timeout=-1, max_packets_to_skip=20):
63+
scaled_output=True, daisy=False, log=True, timeout=1, max_packets_to_skip=20):
6464
# unused, for compatibility with Cyton v3 API
6565
self.daisy = False
6666

@@ -222,8 +222,12 @@ def start_streaming(self, callback, lapse=-1):
222222
callback = [callback]
223223

224224
while self.streaming:
225-
# at most we will get one sample per packet
226-
self.gang.waitForNotifications(1./self.getSampleRate())
225+
# should the board get disconnected and we could not wait for notification anymore, a reco should be attempted through timeout mechanism
226+
try:
227+
# at most we will get one sample per packet
228+
self.gang.waitForNotifications(1./self.getSampleRate())
229+
except Exception as e:
230+
print("Something went wrong while waiting for a new sample: " + str(e))
227231
# retrieve current samples on the stack
228232
samples = self.delegate.getSamples()
229233
self.packets_dropped = self.delegate.getMaxPacketsDropped()

0 commit comments

Comments
 (0)