The following snippet is from a pyusb tutuorial. It is being used to find all printers connected :
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))
This class seems to have multiple points where it returns a boolean value. How many returns are being sent?
Also I couldn't understand how this code searches all printers connected to the system. Things in this code that escape me are:
Is
device
a list/tuple? If yes, how does this code check all the devices by executingif device.bDeviceClass == self._class:
just once?what is happening in this line:
self._class = class_
why is the class
find_class
never instantiated inprinters = usb.core.find(find_all=1, custom_match=find_all(7))
If you have worked on pyusb/any usb program, please tell me how.