ITで遊ぶ

汎用プログラムPythonとUSB(2)

LibUSBとの接続をするPyUSB
パッケージをダウンロードし、コマンドラインでそのフォルダーに移動します。
そこにはsetup.pyがあるはずです。確認してください。

python setup.py install

でインストールします。
USBと通信するためには、DeviceID, ProductIDが必要です。
次のプログラムを用意します。(名前を仮にfindusb.pyとします。)

#!/usr/bin/python
import sys
import usb.core
# find USB devices
dev = usb.core.find(find_all=True)
# loop through devices, printing vendor and product ids in decimal and hex
for cfg in dev:
  sys.stdout.write('Decimal VendorID=' + str(cfg.idVendor) + ' & ProductID=' + str(cfg.idProduct) + '\n')
  sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + '\n\n')
  1. USBデバイスを差し込んで、findusb.pyを走らせます。
  2. 次にデバイスを抜いて、またfindusb.pyを走らせます。
  3. なくなっているものが、対象のUSBデバイスのデータということになります。

 

>>> import usb.core
>>> dev = usb.core.find()

PyUSB記事へ続く。。。

関連記事

  1. 音声をテキストに(google speech-to-text API)…

  2. htmltemplate for PHP

  3. Arduinoで脈拍を測る

  4. MPASMがなくなった

  5. PIC16F1705

  6. Windowsパソコンの買い替え/アップデート

  7. Raspberry Piに本当の乱数発生器が追加されていた

  8. SysLinux翻訳