예제 #1
0
    def test_multiple_interface_usb_device(self):
        from mbed_tools.devices._internal.windows.usb_device_identifier import parse_device_id

        self.assertEqual(
            parse_device_id(
                "USB\\VID_0D28&PID_0204&MI_00\\0240000034544E45001A00018AA900292011000097969900"
            ).uid.uid,
            "0240000034544e45001a00018aa900292011000097969900",
        )
        self.assertEqual(
            parse_device_id(
                "USB\\VID_0D28&PID_0204&MI_00\\0240000034544E45001A00018AA900292011000097969900"
            ).uid.raw_uid,
            "0240000034544E45001A00018AA900292011000097969900",
        )
        self.assertEqual(
            parse_device_id(
                "USB\\VID_0D28&PID_0204&MI_00\\0240000034544E45001A00018AA900292011000097969900"
            ).PID,
            "0204",
        )
        self.assertEqual(
            parse_device_id(
                "USB\\VID_0D28&PID_0204&MI_02\\0240000034544E45001A00018AA900292011000097969900"
            ).VID,
            "0D28",
        )
        self.assertEqual(
            parse_device_id(
                "USB\\VID_0D28&PID_0204&MI_02\\0240000034544E45001A00018AA900292011000097969900"
            ).MI, "02")
 def _load_data(self) -> None:
     self._serial_port_by_usb_id = {
         parse_device_id(p.pnp_id): p
         for p in cast(
             Generator[SerialPort, None, None],
             ComponentsLoader(self._data_loader,
                              SerialPort).element_generator())
     }
예제 #3
0
 def _list_usb_controller_ids(self) -> List[UsbIdentifier]:
     return cast(
         List[UsbIdentifier],
         [
             parse_device_id(cast(UsbController, usbc).component_id)
             for usbc in ComponentsLoader(self._data_loader, UsbController).element_generator()
         ],
     )
예제 #4
0
    def _load(self) -> None:
        """Populates the cache."""
        self._cache = cast(Dict[UsbIdentifier, List[UsbHub]], dict())
        self._ids_cache = cast(Set[UsbIdentifier], set())
        controllers = self._list_usb_controller_ids()
        for usb_device in self._iterate_over_hubs():
            usb_id = parse_device_id(
                usb_device.component_id, serial_number=self._determine_potential_serial_number(cast(UsbHub, usb_device))
            )
            if usb_id in controllers:
                continue
            entry = self._cache.get(usb_id, list())
            entry.append(cast(UsbHub, usb_device))
            self._cache[usb_id] = entry

            if usb_id.contains_genuine_serial_number():
                self._ids_cache.add(usb_id)
        self._populate_id_cache_with_non_serialnumbers()
예제 #5
0
    def test_single_interface_usb_device(self):
        from mbed_tools.devices._internal.windows.usb_device_identifier import parse_device_id

        self.assertTrue(parse_device_id("").is_undefined)
        self.assertTrue(parse_device_id(None).is_undefined)
        self.assertTrue(parse_device_id("4&38EF038C&0&0").is_undefined)
        self.assertFalse(parse_device_id("USB\\4&38EF038C&0&0").is_undefined)
        self.assertEqual(
            parse_device_id("USB\\4&38EF038C&0&0").uid,
            WindowsUID(uid="4&38ef038c&0",
                       raw_uid="4&38EF038C&0&0",
                       serial_number=None),
        )
        self.assertEqual(
            parse_device_id("USB\\ROOT_HUB30\\4&38EF038C&0&0").uid.raw_uid,
            "4&38EF038C&0&0")
        self.assertEqual(
            parse_device_id("USB\\VID_2109&PID_2812\\6&38E4CCB6&0&4").uid,
            WindowsUID(uid="6&38e4ccb6&0",
                       raw_uid="6&38E4CCB6&0&4",
                       serial_number=None),
        )
        self.assertEqual(
            parse_device_id("USB\\VID_2109&PID_2812\\6&38E4CCB6&0&4").PID,
            "2812")
        self.assertEqual(
            parse_device_id("USB\\VID_2109&PID_2812\\6&38E4CCB6&0&4").VID,
            "2109")
        self.assertEqual(
            parse_device_id(
                "USB\\VID_2109&PID_2812&REV_1100\\6&38E4CCB6&0&4").REV, "1100")

        self.assertGreaterEqual(
            data_object_to_dict(
                parse_device_id(
                    "USB\\VID_2109&PID_2812&REV_1100\\6&38E4CCB6&0&4")).items(
                    ),
            {
                "VID":
                "2109",
                "PID":
                "2812",
                "REV":
                "1100",
                "UID":
                WindowsUID(uid="6&38e4ccb6&0",
                           raw_uid="6&38E4CCB6&0&4",
                           serial_number=None),
            }.items(),
        )
        self.assertEqual(parse_device_id("USB\\4&38EF038C&0&0").product_id, "")
        self.assertEqual(parse_device_id("USB\\4&38EF038C&0&0").vendor_id, "")