@@ -111,7 +111,9 @@ def run(self):
111
111
):
112
112
port = self .config .capture_source
113
113
self .current_capture_source = port
114
- self .start_serial_connection (port )
114
+ if self .start_serial_connection (port ):
115
+ time .sleep (0.3 )
116
+ continue
115
117
elif ViveTracker .is_device_vive_tracker (self .config .capture_source ):
116
118
if self .cv2_camera is not None :
117
119
self .cv2_camera .release ()
@@ -318,31 +320,29 @@ def start_serial_connection(self, port):
318
320
if self .serial_connection is not None and self .serial_connection .is_open :
319
321
# Do nothing. The connection is already open on this port.
320
322
if self .serial_connection .port == port :
321
- return
323
+ return False
322
324
# Otherwise, close the connection before trying to reopen.
323
325
self .serial_connection .close ()
324
326
com_ports = [tuple (p ) for p in list (serial .tools .list_ports .comports ())]
325
327
# Do not try connecting if no such port i.e. device was unplugged.
326
328
if not any (p for p in com_ports if port in p ):
327
- return
329
+ return True
328
330
try :
329
331
rate = 115200 if sys .platform == "darwin" else 3000000 # Higher baud rate not working on macOS
330
332
conn = serial .Serial (baudrate = rate , port = port , xonxoff = False , dsrdtr = False , rtscts = False )
331
333
# Set explicit buffer size for serial. This function is Windows only!
332
334
if os_type == 'Windows' :
333
335
conn .set_buffer_size (rx_size = BUFFER_SIZE , tx_size = BUFFER_SIZE )
334
336
335
- print (
336
- f'{ Fore .CYAN } [{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("info.ETVRConnected" )} { port } { Fore .RESET } '
337
- )
337
+ print (f'{ Fore .CYAN } [{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("info.ETVRConnected" )} { port } { Fore .RESET } ' )
338
338
self .serial_connection = conn
339
339
self .camera_status = CameraState .CONNECTED
340
+ return False
340
341
except Exception as e :
341
- print (
342
- f'{ Fore .CYAN } [{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("info.ETVRFailiure" )} { port } { Fore .RESET } '
343
- )
342
+ print (f'{ Fore .CYAN } [{ lang ._instance .get_string ("log.info" )} ] { lang ._instance .get_string ("info.ETVRFailiure" )} { port } { Fore .RESET } ' )
344
343
print (e )
345
344
self .camera_status = CameraState .DISCONNECTED
345
+ return True
346
346
347
347
def clamp_max_res (self , image : MatLike ) -> MatLike :
348
348
shape = image .shape
0 commit comments