def _check_serial(self, board, board_data, ext_serial_port): if 'usb' not in board_data: raise Exception('Missing board configuration: usb') usb_data = board_data.get('usb') hwid = '{0}:{1}'.format(usb_data.get('vid'), usb_data.get('pid')) # Match the discovered serial ports serial_ports = util.get_serial_ports() if len(serial_ports) == 0: # Board not available raise Exception('board ' + board + ' not available') for serial_port_data in serial_ports: port = serial_port_data.get('port') if ext_serial_port and ext_serial_port != port: # If the --device options is set but it doesn't match # the detected port, skip the port. continue if hwid.lower() in serial_port_data.get('hwid').lower(): if 'tinyprog' in board_data and \ not self._check_tinyprog(board_data, port): # If the board uses tinyprog use its port detection # to double check the detected port. # If the port is not detected, skip the port. continue # If the hwid and the description pattern matches # with the detected port return the port. return port
def _check_serial(self, board, board_data, ext_serial_port): if 'usb' not in board_data: raise Exception('Missing board configuration: usb') usb_data = board_data.get('usb') hwid = '{0}:{1}'.format( usb_data.get('vid'), usb_data.get('pid') ) # Match the discovered serial ports serial_ports = util.get_serial_ports() if len(serial_ports) == 0: # Board not available raise Exception('board ' + board + ' not available') for serial_port_data in serial_ports: port = serial_port_data.get('port') if ext_serial_port and ext_serial_port != port: # If the --device options is set but it doesn't match # the detected port, skip the port. continue if hwid.lower() in serial_port_data.get('hwid').lower(): if 'tinyprog' in board_data and \ not self._check_tinyprog(board_data, port): # If the board uses tinyprog use its port detection # to double check the detected port. # If the port is not detected, skip the port. continue # If the hwid and the description pattern matches # with the detected port return the port. return port
def lsserial(self): returncode = 0 serial_ports = util.get_serial_ports() click.secho( 'Number of Serial devices found: {}\n'.format(len(serial_ports))) for serial_port in serial_ports: port = serial_port.get('port') description = serial_port.get('description') hwid = serial_port.get('hwid') click.secho(port, fg='cyan') click.secho('Description: {}'.format(description)) click.secho('Hardware info: {}\n'.format(hwid)) return returncode
def _check_serial(self, board_data, ext_serial_port): if 'usb' not in board_data: raise Exception('Missing board configuration: usb') usb_data = board_data.get('usb') desc_pattern = '^' + (usb_data.get('desc') or '.*') + '$' hwid = '{0}:{1}'.format(usb_data.get('vid'), usb_data.get('pid')) # Match the discovered serial ports for serial_port_data in util.get_serial_ports(): port = serial_port_data.get('port') if ext_serial_port and ext_serial_port != port: # If the --device options is set but it doesn't match # with the detected port, skip the port. continue if hwid in serial_port_data.get('hwid') and \ re.match(desc_pattern, serial_port_data.get('description')): # If the hwid and the description pattern matches # return the device for the port. return port