Beispiel #1
0
def search_nxp_usb_devices(
        extend_vid_list: list = None) -> Sequence[DeviceDescription]:
    """Searches all NXP USB devices based on their Vendor ID.

    :extend_vid_list: list of VIDs, to extend the default NXP VID list (int)
    :return: list of dicts corresponding to NXP devices
    """
    sio = libusbsio.usbsio()
    all_usb_devices = sio.HIDAPI_Enumerate()
    nxp_usb_devices = []

    search_vids = NXP_USB_DEVICE_VIDS

    if extend_vid_list is not None:
        search_vids = list(set(search_vids) | set(extend_vid_list))

    for usb_device in all_usb_devices:
        for nxp_vid in search_vids:
            if nxp_vid == usb_device["vendor_id"]:
                # We found our device, let's create container for it
                vid = usb_device["vendor_id"]
                pid = usb_device["product_id"]
                path = convert_usb_path(usb_device["path"])
                product_string = usb_device["product_string"]
                manufacturer_string = usb_device["manufacturer_string"]
                name = ", ".join(get_usb_device_name(vid, pid, None))
                usb_dev = USBDeviceDescription(vid, pid, path, product_string,
                                               manufacturer_string, name)

                nxp_usb_devices.append(usb_dev)
                break

    return nxp_usb_devices
Beispiel #2
0
    def enumerate(usb_device_filter: USBDeviceFilter) -> Sequence[Interface]:
        """Get list of all connected devices matching the USBDeviceFilter object.

        :param usb_device_filter: USBDeviceFilter object
        :return: List of interfaces found
        """
        devices = []

        # use HID_API of LIBUSBSIO library to enumerate all USB HID devices
        sio = libusbsio.usbsio()
        all_hid_devices = sio.HIDAPI_Enumerate()

        # iterate on all devices found
        for dev in all_hid_devices:
            if usb_device_filter.compare(dev) is True:
                new_device = RawHid()
                new_device.device = sio.HIDAPI_DeviceCreate()
                new_device.vid = dev["vendor_id"]
                new_device.pid = dev["product_id"]
                new_device.vendor_name = dev["manufacturer_string"]
                new_device.product_name = dev["product_string"]
                new_device.interface_number = dev["interface_number"]
                new_device.path = dev["path"]
                devices.append(new_device)

        return devices
Beispiel #3
0
def _get_usbsio() -> LIBUSBSIO:
    """Wraps getting USBSIO library to raise SPSDK errors in case of problem.

    :return: LIBUSBSIO object
    :raises SPSDKError: When libusbsio library error or if no bridge device found
    """
    try:
        # get the global singleton instance of LIBUSBSIO library
        return libusbsio.usbsio(loglevel=logger.level)
    except libusbsio.LIBUSBSIO_Exception as e:
        raise SPSDKError(f"Error in libusbsio interface: {e}") from e
    except Exception as e:
        raise SPSDKError(str(e)) from e
Beispiel #4
0
def search_libusbsio_devices() -> List[SIODeviceDescription]:
    """Returns a list of all LIBUSBSIO devices.

    :retval: list of UartDeviceDescription devices from devicedescription module
    :raises SPSDKError: In any case of LIBUSBSIO problems.
    """
    retval = []
    try:
        sio = usbsio()  # Get Singleton of LIBUSBSIO
        for i in range(sio.GetNumPorts()):
            info = sio.GetDeviceInfo(i)
            if not info:
                raise SPSDKError("Cannot retrive the Device Information.")
            retval.append(SIODeviceDescription(info))
    except (LIBUSBSIO_Exception, SPSDKError) as exc:
        raise SPSDKError(
            f"LIBUSBSIO search devices fails: [{str(exc)}]") from exc

    return retval
Beispiel #5
0
    def enumerate(usb_device_filter: USBDeviceFilter) -> List["RawHid"]:
        """Get list of all connected devices which matches device_id.

        :param usb_device_filter: USBDeviceFilter object
        :return: List of interfaces found
        """
        devices = []
        sio = libusbsio.usbsio()
        all_hid_devices = sio.HIDAPI_Enumerate()

        # iterate on all devices found
        for dev in all_hid_devices:
            if usb_device_filter.compare(vars(dev)) is True:
                new_device = RawHid()
                new_device.device = sio.HIDAPI_DeviceCreate()
                new_device.vid = dev["vendor_id"]
                new_device.pid = dev["product_id"]
                new_device.vendor_name = dev["manufacturer_string"]
                new_device.product_name = dev["product_string"]
                new_device.interface_number = dev["interface_number"]
                new_device.path = dev["path"]
                devices.append(new_device)

        return devices