7

USB デバイスの文字列記述子を取得できません。私が探しているのは、人に優しいメーカー名と製品名です。libusb-1.0 をバックエンドとして使用しており、提供された libusb テスト プログラムを使用してメーカー名を取得できるため、それが存在することがわかります。

usb_get_string_simplePyUSB ヘルプ ファイルには、次を使用して (libusb バックエンドから)アクセスできると書かれています。

get_string(dev, length, index, langid=None)

   Retrieve a string descriptor from the device.
   dev is the Device object to which the request will be sent to.

   length is the length of string in number of characters.

   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.

   The return value is the unicode string present in the descriptor.
import usb
#help(usb.core) 
busses = usb.busses()
for bus in busses:
  devices = bus.devices
  for dev in devices:
    _name = usb.util.get_string(dev.dev,256,0)  #This is where I'm having trouble
    print "device name=",_name
    print "Device:", dev.filename
    print "  Device class:",dev.deviceClass
    print "  Device sub class:",dev.deviceSubClass
    print "  Device protocol:",dev.deviceProtocol
    print "  Max packet size:",dev.maxPacketSize
    print "  idVendor:",hex(dev.idVendor)
    print "  idProduct:",hex(dev.idProduct)
    print "  Device Version:",dev.deviceVersion
    for config in dev.configurations:
      print "  Configuration:", config.value
      print "    Total length:", config.totalLength 
      print "    selfPowered:", config.selfPowered
      print "    remoteWakeup:", config.remoteWakeup
      print "    maxPower:", config.maxPower
      for intf in config.interfaces:
        print "    Interface:",intf[0].interfaceNumber
        for alt in intf:
          print "    Alternate Setting:",alt.alternateSetting
          print "      Interface class:",alt.interfaceClass
          print "      Interface sub class:",alt.interfaceSubClass
          print "      Interface protocol:",alt.interfaceProtocol
          for ep in alt.endpoints:
            print "      Endpoint:",hex(ep.address)
            print "        Type:",ep.type
            print "        Max packet size:",ep.maxPacketSize
            print "        Interval:",ep.interval

どんな助けでも大歓迎です。

4

4 に答える 4

6

2019年7月の更新:実際にインデックスをハードコードしない理由の明確な説明については、以下のTeodor-Bogdan Barbieruの回答を参照してください!)

2019年7月の2回目の更新:すべてのデバイス記述子フィールドをリストした表を含むUSB仕様へのリンクについては、以下のgogのコメントを参照してください。)

コードの次の行:

usb.util.get_string(dev.dev,256,0)

確かに問題です。USB仕様が何を言っているのかよくわかりませんが、現在のハードウェアプロジェクトでは、インデックスの選択について次のようになっています。

  • index = 0(選択)は単一のUnicode文字を返します
  • index=1はメーカーを送信します
  • index=2はデバイスの説明を送信します
  • index=3はデバイスのシリアル番号を送信します

だから、試してみてください:

usb.util.get_string(dev.dev, 256, 2)

幸運を!

于 2012-06-12T11:14:33.120 に答える
6

インデックスをハードコーディングするのは得策ではありません。

次のようなものを使用することをお勧めします。

usb.util.get_string(dev, 256, dev.iSerialNumber)
usb.util.get_string(dev, 256, dev.iManufacturer)

以下に示すように、インデックスはデバイスごとに異なります。

lsusb -v の出力:

device 1:            #index #string_descriptor
      iManufacturer  3 Linux 3.8.13 musb-hcd
      iProduct       2 MUSB HDRC host driver
      iSerial        1 musb-hdrc.1.auto

device 2:
      iManufacturer  2 E-boda
      iProduct       3 SUNNY V35
      iSerial        4 0123456789ABCDEF
于 2014-08-29T20:40:04.027 に答える