Created
March 20, 2011 12:11
-
-
Save eblot/878301 to your computer and use it in GitHub Desktop.
Adding bus usb information to PyUSB 1.0.0 (for libusb-1.0.x only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ur a/usb/backend/__init__.py b/usb/backend/__init__.py | |
--- a/usb/backend/__init__.py 2010-12-15 10:40:52.000000000 +0100 | |
+++ b/usb/backend/__init__.py 2011-03-15 17:01:35.000000000 +0100 | |
@@ -176,6 +176,14 @@ | |
""" | |
_not_implemented(self.close_device) | |
+ def get_bus_number(self, dev): | |
+ r"""Get the number of the bus that a device is connected to.""" | |
+ _not_implemented(self.get_bus_number) | |
+ | |
+ def get_device_address(self, dev): | |
+ r"""Get the address of the device on the bus it is connected to.""" | |
+ _not_implemented(self.get_device_address) | |
+ | |
def set_configuration(self, dev_handle, config_value): | |
r"""Set the active device configuration. | |
diff -ur a/usb/backend/libusb10.py b/usb/backend/libusb10.py | |
--- a/usb/backend/libusb10.py 2010-12-15 18:39:03.000000000 +0100 | |
+++ b/usb/backend/libusb10.py 2011-03-15 16:51:01.000000000 +0100 | |
@@ -194,6 +194,14 @@ | |
c_int | |
] | |
+ # uint8_t libusb_get_bus_number(libusb_device *dev) | |
+ lib.libusb_get_bus_number.argtypes = [c_void_p] | |
+ lib.libusb_get_bus_number.restype = c_uint8 | |
+ | |
+ # uint8_t libusb_get_device_address(libusb_device *dev) | |
+ lib.libusb_get_device_address.argtypes = [c_void_p] | |
+ lib.libusb_get_device_address.restype = c_uint8 | |
+ | |
# libusb_device *libusb_ref_device (libusb_device *dev) | |
lib.libusb_ref_device.argtypes = [c_void_p] | |
lib.libusb_ref_device.restype = c_void_p | |
@@ -451,6 +459,14 @@ | |
_lib.libusb_close(dev_handle) | |
@methodtrace(_logger) | |
+ def get_bus_number(self, dev): | |
+ return _lib.libusb_get_bus_number(dev.devid) | |
+ | |
+ @methodtrace(_logger) | |
+ def get_device_address(self, dev): | |
+ return _lib.libusb_get_device_address(dev.devid) | |
+ | |
+ @methodtrace(_logger) | |
def set_configuration(self, dev_handle, config_value): | |
_check(_lib.libusb_set_configuration(dev_handle, config_value)) | |
diff -ur a/usb/core.py b/usb/core.py | |
--- a/usb/core.py 2010-12-17 14:42:53.000000000 +0100 | |
+++ b/usb/core.py 2011-03-15 16:58:27.000000000 +0100 | |
@@ -559,6 +559,16 @@ | |
""" | |
self._ctx.managed_set_interface(self, interface, alternate_setting) | |
+ def get_bus_number(self): | |
+ r"""Get the number of the bus that a device is connected to.""" | |
+ self._ctx.managed_open() | |
+ return self._ctx.backend.get_bus_number(self._ctx.dev) | |
+ | |
+ def get_device_address(self): | |
+ r"""Get the address of the device on the bus it is connected to.""" | |
+ self._ctx.managed_open() | |
+ return self._ctx.backend.get_device_address(self._ctx.dev) | |
+ | |
def reset(self): | |
r"""Reset the device.""" | |
self._ctx.dispose(self, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment