(dev, index, langid = None)
return buf[2:blen].tobytes().decode('utf-16-le')
r"""Retrieve a string descriptor from the device.

    dev is the Device object which the string will be read from.

    index is the string descriptor index and langid is the Language
    ID of the descriptor. If langid is omitted, the string descriptor
    of the first Language ID will be returned.

    Zero is never the index of a real string. The USB spec allows a device to
    use zero in a string index field to indicate that no string is provided.
    So the caller does not have to treat that case specially, this function
    returns None if passed an index of zero, and generates no traffic
    to the device.

    The return value is the unicode string present in the descriptor, or None
    if the requested index was zero.
r"""Retrieve a string descriptor from the device.
r Retrieve a string descriptor from the device .
def get_string(dev, index, langid = None):
    r"""Retrieve a string descriptor from the device.

    dev is the Device object which the string will be read from.

    index is the string descriptor index and langid is the Language
    ID of the descriptor. If langid is omitted, the string descriptor
    of the first Language ID will be returned.

    Zero is never the index of a real string. The USB spec allows a device to
    use zero in a string index field to indicate that no string is provided.
    So the caller does not have to treat that case specially, this function
    returns None if passed an index of zero, and generates no traffic
    to the device.

    The return value is the unicode string present in the descriptor, or None
    if the requested index was zero.
    """
    if 0 == index:
        return None

    from usb.control import get_descriptor

    if langid is None:
        langids = dev.langids
        if 0 == len(langids):
            raise ValueError("The device has no langid"
                             " (permission issue, no string descriptors supported or device error)")
        langid = langids[0]

    buf = get_descriptor(
                dev,
                254, # maximum even length
                DESC_TYPE_STRING,
                index,
                langid
            )
    blen = buf[0] & 0xfe # should be even, ignore any trailing byte (see #154)
    return buf[2:blen].tobytes().decode('utf-16-le')
def get_string ( dev , index , langid = None ) : if 0 == index : return None from usb . control import get_descriptor if langid is None : langids = dev . langids if 0 == len ( langids ) : raise ValueError ( "The device has no langid" " (permission issue, no string descriptors supported or device error)" ) langid = langids [ 0 ] buf = get_descriptor ( dev , 254 , # maximum even length DESC_TYPE_STRING , index , langid ) blen = buf [ 0 ] & 0xfe # should be even, ignore any trailing byte (see #154) return buf [ 2 : blen ] . tobytes ( ) . decode ( 'utf-16-le' )