Windows configuration bug should be fixed.

This commit is contained in:
Kovid Goyal 2007-01-16 22:02:34 +00:00
parent d789b6d627
commit 0ca3a7861f
3 changed files with 16 additions and 23 deletions

View File

@ -36,6 +36,11 @@ the following rule in C{/etc/udev/rules.d/90-local.rules} ::
You may have to adjust the GROUP and the location of the rules file to You may have to adjust the GROUP and the location of the rules file to
suit your distribution. suit your distribution.
""" """
__version__ = "0.3.4" __version__ = "0.3.4"
__docformat__ = "epytext" __docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>" __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
import sys
iswindows = 'win32' in sys.platform.lower()
isosx = 'darwin' in sys.platform.lower()

View File

@ -233,17 +233,10 @@ class PRS500Device(Device):
raise DeviceError() raise DeviceError()
try: try:
self.handle = self.device.open() self.handle = self.device.open()
configs = self.device.configurations
cfg = configs[0]
for config in configs:
if config.MaxPower > cfg.MaxPower:
cfg = config
try: try:
self.handle.set_configuration(cfg) self.handle.set_configuration(1)
except USBError: except USBError:
for config in configs: self.handle.set_configuration(2)
if config.Value != cfg.Value:
self.handle.set_configuration(config)
self.handle.claim_interface(self.INTERFACE_ID) self.handle.claim_interface(self.INTERFACE_ID)
except USBError, err: except USBError, err:
raise DeviceBusy(str(err)) raise DeviceBusy(str(err))

View File

@ -16,25 +16,24 @@
This module provides a thin ctypes based wrapper around libusb. This module provides a thin ctypes based wrapper around libusb.
""" """
import sys
from ctypes import cdll, POINTER, byref, pointer, Structure, \ from ctypes import cdll, POINTER, byref, pointer, Structure, \
c_ubyte, c_ushort, c_int, c_char, c_void_p, c_byte, c_uint c_ubyte, c_ushort, c_int, c_char, c_void_p, c_byte, c_uint
from errno import EBUSY, ENOMEM from errno import EBUSY, ENOMEM
_iswindows = 'win32' in sys.platform.lower() from libprs500 import iswindows, isosx
_isosx = 'darwin' in sys.platform.lower()
_libusb_name = 'libusb.so' _libusb_name = 'libusb.so'
if _iswindows: if iswindows:
_libusb_name = 'libusb0' _libusb_name = 'libusb0'
elif _isosx: elif isosx:
_libusb_name = 'libusb.dylib' _libusb_name = 'libusb.dylib'
_libusb = cdll.LoadLibrary(_libusb_name) _libusb = cdll.LoadLibrary(_libusb_name)
# TODO: Need to set this in a platform dependednt way (limits.h in linux) # TODO: Need to set this in a platform dependednt way (limits.h in linux)
PATH_MAX = 4096 PATH_MAX = 4096
if _iswindows: if iswindows:
PATH_MAX = 511 PATH_MAX = 511
if _isosx: if isosx:
PATH_MAX = 1024 PATH_MAX = 1024
class DeviceDescriptor(Structure): class DeviceDescriptor(Structure):
@ -91,7 +90,7 @@ class Interface(Structure):
('num_altsetting', c_int)\ ('num_altsetting', c_int)\
] ]
class ConfigDescriptor(Structure): class ConfigDescriptor(Structure):
_fields_ = [\ _fields_ = [\
('Length', c_ubyte), \ ('Length', c_ubyte), \
('DescriptorType', c_ubyte), \ ('DescriptorType', c_ubyte), \
@ -102,7 +101,7 @@ class ConfigDescriptor(Structure):
('Attributes', c_ubyte), \ ('Attributes', c_ubyte), \
('MaxPower', c_ubyte), \ ('MaxPower', c_ubyte), \
('interface', POINTER(Interface)), \ ('interface', POINTER(Interface)), \
('extra', POINTER(c_char)), \ ('extra', POINTER(c_ubyte)), \
('extralen', c_int) \ ('extralen', c_int) \
] ]
@ -131,7 +130,6 @@ class Device(Structure):
doc = """ List of device configurations. See L{ConfigDescriptor} """ doc = """ List of device configurations. See L{ConfigDescriptor} """
def fget(self): def fget(self):
ans = [] ans = []
ans.append(self.config_descriptor.contents)
for config in range(self.device_descriptor.NumConfigurations): for config in range(self.device_descriptor.NumConfigurations):
ans.append(self.config_descriptor[config]) ans.append(self.config_descriptor[config])
return tuple(ans) return tuple(ans)
@ -306,8 +304,6 @@ Device._fields_ = [ \
('children', POINTER(POINTER(Device))) ('children', POINTER(POINTER(Device)))
] ]
_libusb.usb_get_busses.restype = POINTER(Bus) _libusb.usb_get_busses.restype = POINTER(Bus)
_libusb.usb_open.restype = POINTER(DeviceHandle) _libusb.usb_open.restype = POINTER(DeviceHandle)
_libusb.usb_open.argtypes = [POINTER(Device)] _libusb.usb_open.argtypes = [POINTER(Device)]
@ -342,11 +338,10 @@ def busses():
def get_device_by_id(idVendor, idProduct): def get_device_by_id(idVendor, idProduct):
""" Return a L{Device} by vendor and prduct ids """ """ Return a L{Device} by vendor and prduct ids """
ans = []
buslist = busses() buslist = busses()
for bus in buslist: for bus in buslist:
devices = bus.device_list devices = bus.device_list
for dev in devices: for dev in devices:
if dev.device_descriptor.idVendor == idVendor and \ if dev.device_descriptor.idVendor == idVendor and \
dev.device_descriptor.idProduct == idProduct: dev.device_descriptor.idProduct == idProduct:
return dev return dev