本文整理汇总了Python中usb.busses函数的典型用法代码示例。如果您正苦于以下问题:Python busses函数的具体用法?Python busses怎么用?Python busses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了busses函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self,skipNIAs):
self.VENDOR_ID = 0x1234 #: Vendor Id
self.PRODUCT_ID = 0x0000 #: Product Id for the bridged usb cable
self.TIME_OUT = 100
self.handle = None
self.device = None
buses = usb.busses()
found = False
for bus in buses :
for device in bus.devices :
if device.idVendor == self.VENDOR_ID and device.idProduct == self.PRODUCT_ID:
if skipNIAs ==0:
self.device = device
self.config = self.device.configurations[0]
self.interface = self.config.interfaces[0][0]
self.ENDPOINT1 = self.interface.endpoints[0].address
self.ENDPOINT2 = self.interface.endpoints[1].address
self.PACKET_LENGTH1 = self.interface.endpoints[0].maxPacketSize
self.PACKET_LENGTH2 = self.interface.endpoints[1].maxPacketSize
found = True
break
else:
skipNIAs -= 1
if found:
break
示例2: get_device
def get_device(self):
for bus in usb.busses():
for device in bus.devices:
if (device.idVendor == self.VENDOR_ID and
device.idProduct in self.POSSIBLE_PRODUCTS):
return device
raise NoBuddyFound
示例3: devices
def devices(vendor_id=None, product_id=None):
usb_devices = [d for b in usb.busses() for d in b.devices
if d.deviceClass == USB_CLASS_PER_INTERFACE
and d.idVendor == vendor_id
and d.idProduct == product_id]
return [HIDDevice(u) for u in usb_devices]
示例4: search_usb
def search_usb(device):
'''
Takes either None, specifying that any USB device in the
global vendor and product lists are acceptable, or takes
a string that identifies a device in the format
<BusNumber>:<DeviceNumber>, and returns the pyUSB objects
for bus and device that correspond to the identifier string.
'''
if device == None:
busNum = None
devNum = None
else:
if ':' not in device:
raise KBInterfaceError("USB device format expects <BusNumber>:<DeviceNumber>, but got {0} instead.".format(device))
busNum, devNum = map(int, device.split(':', 1))
if USBVER == 0:
busses = usb.busses()
for bus in busses:
dev = search_usb_bus_v0x(bus, busNum, devNum)
if dev != None:
return (bus, dev)
return None #Note, can't expect a tuple returned
elif USBVER == 1:
return usb.core.find(custom_match=findFromListAndBusDevId(busNum, devNum, usbVendorList, usbProductList)) #backend=backend,
else:
raise Exception("USB version expected to be 0.x or 1.x.")
示例5: find_sixaxes
def find_sixaxes():
res = []
for bus in usb.busses():
for dev in bus.devices:
if dev.idVendor == vendor and dev.idProduct == product:
res.append(dev)
return res
示例6: get_device
def get_device(self) :
buses = usb.busses()
for bus in buses :
for device in bus.devices :
if device.idVendor == self.idVendor and device.idProduct == self.idProduct :
return device
return None
示例7: is_available
def is_available():
for bus in usb.busses():
for device in bus.devices:
if (device.idVendor == ID_VENDOR_GTEC and
device.idProduct == ID_PRODUCT_GUSB_AMP):
return True
return False
示例8: __init__
def __init__(self):
self.dh = None
footswitch = None
self.iface = None
self.location = None
for bus in usb.busses():
for dev in bus.devices:
if dev.idVendor == VENDOR_ID and dev.idProduct == PRODUCT_ID:
footswitch = dev
self.location = (bus.dirname, dev.filename)
break
if footswitch is None:
raise BackendError("Device not found")
for intf in footswitch.configurations[0].interfaces:
if intf[0].interfaceNumber == INTERFACE_NUMBER:
self.iface = intf
self.dh = footswitch.open()
# TODO: flaky after an ACPI suspend
self.dh.reset()
# This sometimes fails, and then errno doesn't get reset
# so subsequent errors are still populated with this.
try:
self.dh.detachKernelDriver(self.iface[0])
except usb.USBError as e:
if 'Operation not permitted' in e.message:
raise BackendError("Permission denied while removing kernel driver")
self.dh.claimInterface(self.iface[0])
示例9: find_device
def find_device(vendor, product):
for bus in usb.busses():
for device in bus.devices:
if device.idVendor == vendor \
and device.idProduct == product:
return device
return None
示例10: JobTask
def JobTask(self):
LinkState = 0
if fileExists('/sys/class/net/wlan0/operstate'):
LinkState = open('/sys/class/net/wlan0/operstate').read()
if LinkState != 'down':
LinkState = open('/sys/class/net/wlan0/operstate').read()
elif fileExists('/sys/class/net/eth0/operstate'):
LinkState = open('/sys/class/net/eth0/operstate').read()
if LinkState != 'down':
LinkState = open('/sys/class/net/eth0/carrier').read()
LinkState = LinkState[:1]
if fileExists("/proc/stb/lcd/symbol_network") and config.lcd.mode.value == '1':
open("/proc/stb/lcd/symbol_network", "w").write(str(LinkState))
elif fileExists("/proc/stb/lcd/symbol_network") and config.lcd.mode.value == '0':
open("/proc/stb/lcd/symbol_network", "w").write('0')
USBState = 0
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
if dev.deviceClass != 9 and dev.deviceClass != 2 and dev.idVendor > 0:
# print ' '
# print "Device:", dev.filename
# print " Number:", dev.deviceClass
# print " idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor)
# print " idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct)
USBState = 1
if fileExists("/proc/stb/lcd/symbol_usb") and config.lcd.mode.value == '1':
open("/proc/stb/lcd/symbol_usb", "w").write(str(USBState))
elif fileExists("/proc/stb/lcd/symbol_usb") and config.lcd.mode.value == '0':
open("/proc/stb/lcd/symbol_usb", "w").write('0')
self.timer.startLongTimer(30)
示例11: _findDevice
def _findDevice(self):
"""Find the vendor and product ID on the USB bus."""
for bus in usb.busses():
for dev in bus.devices:
if dev.idVendor == self.vendor_id and dev.idProduct == self.product_id:
return dev
return None
示例12: find_keyboard_device
def find_keyboard_device():
for bus in usb.busses():
for device in bus.devices:
print device
if device.idVendor == USB_VENDOR and \
device.idProduct == USB_PRODUCT or device.idProduct == USB_OTHER_PRODUCT:
return device
示例13: find_usb_devices
def find_usb_devices():
busses = usb.busses()
devobjs = []
for dev in usb.core.find(find_all=True):
serialno = None
if dev.iSerialNumber > 0:
try:
serialno = dev.serial_number
except usb.USBError:
pass
except ValueError:
pass
did = None
try:
did = '%04x' % dev.bcdDevice
except TypeError:
pass
devobjs.append(
LibDevice(
vid=dev.idVendor,
pid=dev.idProduct,
did=did,
serialno=serialno,
path=Path(
bus=dev.bus,
address=dev.address)))
return devobjs
示例14: init
def init(n=0): #opens the device, returns its deviceHandle
import usb
#global dh
b=usb.busses()
d=b[0].devices[n]
print "DEVICE ",n,": PID:", d.idProduct ," VID: ",d.idVendor,", devnum: ",d.devnum
dh=d.open()
print "manuf:",dh.getString(d.iManufacturer,1000),", SN:",dh.getString(d.iSerialNumber,1000)
c=d.configurations[0]
try:
print "config:",c.value,",",dh.getString(c.iConfiguration,1000)
except:
pass
ifs=c.interfaces
i=ifs[0][0]
es=i.endpoints
for e in es:
if e.address>=128:
ei=e.address
else:
eo=e.address
dh.setConfiguration(c)
global dhG
try:
dh.claimInterface(i)
dhG=dh
except usb.USBError:
print " INTERFACE WAS BUSY; RELEASING..."
dhG.releaseInterface()
#dh.releaseInterface()
dh.claimInterface(i)
dhG=dh
return {"hnd":dh,"in":ei,"out":eo}
示例15: get_g9_device
def get_g9_device():
for bus in usb.busses():
for device in bus.devices:
if device.idVendor == G9_VENDOR_ID \
and device.idProduct in G9_PRODUCT_IDS:
return device.open()
return None