Returns a tuple representation of the port and serial number for a
    connected micro:bit device. If no device is connected the tuple will be
    (None, None).
499179
def find_microbit():
    
    ports = list_serial_ports()
    for port in ports:
        if "VID:PID=0D28:0204" in port[2].upper():
            return (port[0], port.serial_number)
    return (None, None)
912045
def get_available_devices(self):
        
        connected_devices = self.mbeds.list_mbeds() if self.mbeds else []
        # Check non mbedOS supported devices.
        # Just for backward compatible reason - is obsolete..
        edbg_ports = self.available_edbg_ports()
        for port in edbg_ports:
            connected_devices.append({
                "platform_name": "SAM4E",
                "serial_port": port,
                "mount_point": None,
                "target_id": None,
                "baud_rate": 460800
            })
        for dev in connected_devices:
            dev['state'] = "unknown"

        return connected_devices
880382
def chip_id(self):
        
        id0 = self.read_reg(self.ESP_OTP_MAC0)
        id1 = self.read_reg(self.ESP_OTP_MAC1)
        return (id0 >> 24) | ((id1 & MAX_UINT24) << 8)
1315321
def serial(self):
        
        asnint = libcrypto.X509_get_serialNumber(self.cert)
        bio = Membio()
        libcrypto.i2a_ASN1_INTEGER(bio.bio, asnint)
        return int(str(bio), 16)
572773
def check_serial_port(name):
    """"""
    try:
        cdc = next(serial.tools.list_ports.grep(name))
        return cdc[0]
    except StopIteration:
        msg = "device {} not found. ".format(name)
        msg += "available devices are: "
        ports = list(serial.tools.list_ports.comports())
        for p in ports:
            msg += "{},".format(text_type(p))
        raise ValueError(msg)
1289110
def get_info(self):
        '''  '''
        return {
            'Connected': self.is_connected(),
            'Port': self.port,
            'Bytes Waiting': self.ser.in_waiting if self.ser else 0
        }
460001
def get_ip_addr(self) -> str:
        ''''''
        output, _ = self._execute(
            '-s', self.device_sn, 'shell', 'ip', '-f', 'inet', 'addr', 'show', 'wlan0')
        ip_addr = re.findall(
            r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b", output)
        if not ip_addr:
            raise ConnectionError(
                'The device is not connected to WLAN or not connected via USB.')
        return ip_addr[0]
493195
def getport(self, default=None):
        
        port = self.port
        if port:
            return int(port)
        else:
            return default
589376
def mps_device_name():
    
    lib = _load_tcmps_lib()
    if lib is None:
        return None

    n = 256
    c_name = (_ctypes.c_char * n)()
    ret = lib.TCMPSMetalDeviceName(_ctypes.byref(c_name), _ctypes.c_int32(n))
    if ret == 0:
        return _decode_bytes_to_native_string(c_name.value)
    else:
        return None
645977
def bytes_available(device):
    
    bytes_avail = 0

    if isinstance(device, alarmdecoder.devices.SerialDevice):
        if hasattr(device._device, "in_waiting"):
            bytes_avail = device._device.in_waiting
        else:
            bytes_avail = device._device.inWaiting()
    elif isinstance(device, alarmdecoder.devices.SocketDevice):
        bytes_avail = 4096

    return bytes_avail
917117
def get_stopbits():
    
    stopbits = []
    s = pyserial.Serial()
    for name, value in s.getSupportedStopbits():
        stopbits.append((value, name,))
    return tuple(stopbits)
51150
def _hardware_count(self):
        
        return self._counts.get("hardware") + self._counts.get("serial") + self._counts.get("mbed")
1297834
def port(self):
        
        try:
            rv = int(to_native(self._split_host()[1]))
            if 0 <= rv <= 65535:
                return rv
        except (ValueError, TypeError):
            pass
381002
def device_id(self):
        
        if self.is_block:
            for filename in self._P.Block.Symlinks:
                parts = decode_ay(filename).split('/')
                if parts[-2] == 'by-id':
                    return parts[-1]
        elif self.is_drive:
            return self._assocdrive._P.Drive.Id
        return ''
184525
def num_devices(self):
        
        c_count = c_uint()
        _check_return(_NVML.get_function(
            "nvmlDeviceGetCount_v2")(byref(c_count)))
        return c_count.value
251144
def describe_connection(self):
        """"""
        if self.device==None:
            return "%s [disconnected]" % (self.name)
        else:
            return "%s connected to %s %s version: %s [serial: %s]" % (self.name, 
                self.vendor_name, self.product_name,
                self.version_number, self.serial_number)
435931
def scan():
    
    available = []
    for i in range(256):
        try:
            s = serial.Serial('COM'+str(i))
            available.append((i, s.portstr))
            s.close()
        except serial.SerialException:
            pass
    return available