USB设备识别 [英] usb device identification
本文介绍了USB设备识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ubuntu 9.04上使用python 说我有两个USB设备连接到一台PC.我如何识别python代码中的设备.....例如
如果USB端口ID == A 将数据写入设备1 如果USB端口ID == B 将数据写入设备2
任何想法....
解决方案
您是否尝试过 pyUsb ? 使用以下方式安装:
pip install pyusb
以下是您可以做什么的摘要:
import usb
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
print("Device:", dev.filename)
print(" idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor))
print(" idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct))
这里 pyUsb的好指南.>
有关更多文档,请使用带有dir()和help()的Python交互模式.
i am using python on ubuntu 9.04 say i have two usb devices connected to a single PC. how can i identify the devices in python code.....for example like
if usb port id == A write data to device 1 if usb port id == B write data to device 2
any ideas....
解决方案
Have you tried pyUsb? Install using:
pip install pyusb
Here a snippet of what you can do:
import usb
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
print("Device:", dev.filename)
print(" idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor))
print(" idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct))
Here a good tutorial of pyUsb.
For more documentation, use Python interactive mode with dir() and help().
这篇关于USB设备识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文