Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if len(ports) == 0:
raise TockLoaderException('No serial ports found. Is the board connected?')
logging.info('No serial port with device name "{}" found.'.format(device_name))
logging.info('Found {} serial port{}.'.format(len(ports), ('s', '')[len(ports) == 1]))
if len(ports) == 1:
index = 0
else:
index = helpers.menu(ports,
return_type='index',
title='Multiple serial port options found. Which would you like to use?')
logging.info('Using "{}".'.format(ports[index]))
port = ports[index][0]
helpers.set_terminal_title_from_port_info(ports[index])
# Open the actual serial port
self.sp = serial.Serial()
self.sp.port = port
self.sp.baudrate = 115200
self.sp.parity=serial.PARITY_NONE
self.sp.stopbits=1
self.sp.xonxoff=0
self.sp.rtscts=0
self.sp.timeout=0.5
# Try to set initial conditions, but not all platforms support them.
# https://github.com/pyserial/pyserial/issues/124#issuecomment-227235402
self.sp.dtr = 0
self.sp.rts = 0