String descriptors are optional. As noted previously, if a device does not support string descriptors, all references to string descriptors within device, configuration, and interface descriptors must be reset to zero.

    String descriptors use UNICODE encodings as defined by The Unicode Standard, Worldwide Character Encoding, Version 1.0, Volumes 1 and 2, The Unicode Consortium, Addison-Wesley Publishing Company, Reading, Massachusetts. The strings in a USB device may support multiple languages. When requesting a string descriptor, the requester specifies the desired language using a sixteen-bit language ID (LANGID) defined by Microsoft for Windows as described in Developing International Software for Windows 95 and Windows NT, Nadine Kano, Microsoft Press, Redmond, Washington. String index zero for all languages returns a string descriptor that contains an array of two-byte LANGID codes supported by the device.

    Table 9-11 shows the LANGID code array. A USB device may omit all string descriptors. USB devices
    that omit all string descriptors shall not return an array of LANGID codes.

    The array of LANGID codes is not NULL-terminated. The size of the array (in bytes) is computed by
    subtracting two from the value of the first byte of the descriptor.


    字符串描述符是可选的。 如前所述,如果设备不支持字符串描述符,则设备、配置和接口描述符中所有对字符串描述符的引用都必须重置为零。

    字符串描述符使用由 Unicode 标准《Worldwide Character Encoding, Version 1.0, Volumes 1 and 2》(The Unicode Consortium, Addison-Wesley Publishing Company, Reading, Massachusetts)定义的 UNICODE 编码。USB 设备中的字符串可能支持多种语言。当请求字符串描述符时,请求方需使用一个十六位的语言 ID(LANGID)来指定所需的语言,该 ID 由 Microsoft 为 Windows 定义,详见《Developing International Software for Windows 95 and Windows NT》(Nadine Kano, Microsoft Press, Redmond, Washington)。对于所有语言,字符串索引零将返回一个字符串描述符,其中包含设备所支持的由双字节 LANGID 代码组成的数组。

    表 9-11 显示了 LANGID 代码数组。USB 设备可以省略所有字符串描述符。省略所有字符串描述符的 USB 设备不得返回 LANGID 代码数组。

    LANGID 代码数组不以 NULL 结尾。数组的大小(以字节为单位)通过从描述符第一个字节的值中减去二来计算。

    表 9-11. 设备支持的语言代码

    偏移量 字段 大小 值类型 描述
    0 bLength 1 N+2 描述符大小(字节)
    1 bDescriptorType 1 常量 字符串描述符类型
    2 wLANGID[0] 2 数字 LANGID 代码 0
    N wLANGID[x] 2 数字 LANGID 代码 x

    UNICODE 字符串描述符(如表 9-12 所示)不是以 NULL 结尾的。字符串长度通过从描述符第一个字节的值中减去二来计算。

    表 9-12. UNICODE 字符串描述符

    偏移量 字段 大小 值类型 描述
    0 bLength 1 数字 本描述符的大小(字节)
    1 bDescriptorType 1 常量 字符串描述符类型
    2 bString N 数字 UNICODE 编码的字符串