【发布时间】:2014-03-01 04:20:30
【问题描述】:
以下 sn-p 来自 pyusb tutuorial。它被用来查找所有连接的打印机:
import usb.core
import usb.util
import sys
class find_class(object):
def __init__(self, class_):
self._class = class_
def __call__(self, device):
# first, let's check the device
if device.bDeviceClass == self._class:
return True
# ok, transverse all devices to find an
# interface that matches our class
for cfg in device:
# find_descriptor: what's it?
intf = usb.util.find_descriptor(
cfg,
bInterfaceClass=self._class
)
if intf is not None:
return True
return False
printers = usb.core.find(find_all=1, custom_match=find_all(7))
这个类似乎有多个点,它返回一个布尔值。正在发送多少退货?
我也无法理解此代码如何搜索连接到系统的所有打印机。 这段代码中让我无法理解的是:
-
device是列表/元组吗?如果是,这段代码如何通过执行一次if device.bDeviceClass == self._class:来检查所有设备? -
这一行发生了什么:
self._class = class_ -
为什么
find_class类从未在printers = usb.core.find(find_all=1, custom_match=find_all(7))中实例化如果你做过pyusb/任何usb程序,请告诉我怎么做。
【问题讨论】:
-
投反对票是为了什么?
-
+1 :) 对我来说很清楚