itdaniher / WeDoMore

A Python Library & Reverse Engineering for the WeDo Kit.
GNU General Public License v2.0
36 stars 18 forks source link

Problems on Rasbpian #5

Closed crlane closed 9 years ago

crlane commented 9 years ago

I'm using Raspbian and python and trying to connect to wedo. The device is detected just fine, but there appears to be a problem with the interface between pyusb and the os version of libusb (I'm guessing at this, but it seems reasonable).

when I run the command >>> wd = WeDo(), it fails during the __init__ and gives the following traceback:

In [3]: wd = WeDo()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-3-78204b0d00fc> in <module>()
----> 1 wd = WeDo()

/home/cameron/prj/wedo/WeDoMore/wedo/__init__.pyc in __init__(self, device)
     69                 raise OSError("Could not find a connected WeDo device")
     70             self.dev = devices[0]
---> 71         self.init_device()
     72         self.valMotorA = 0
     73         self.valMotorB = 0

/home/cameron/prj/wedo/WeDoMore/wedo/__init__.pyc in init_device(self)
     79         """
     80         try:
---> 81             if os.name != 'nt' and self.dev.is_kernel_driver_active(WEDO_INTERFACE):
     82                 try:
     83                     self.dev.detach_kernel_driver(WEDO_INTERFACE)

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/core.pyc in is_kernel_driver_active(self, interface)
    990         return self._ctx.backend.is_kernel_driver_active(
    991                 self._ctx.handle,
--> 992                 interface)
    993
    994     def detach_kernel_driver(self, interface):

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/__init__.pyc in is_kernel_driver_active(self, dev_handle, intf)
    361         and the backend will be unable to perform I/O.
    362         """
--> 363         _not_implemented(self.is_kernel_driver_active)
    364
    365     def detach_kernel_driver(self, dev_handle, intf):

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/__init__.pyc in _not_implemented(func)
     77
     78 def _not_implemented(func):
---> 79     raise NotImplementedError(func.__name__)
     80
     81 class IBackend(object):

NotImplementedError: is_kernel_driver_active

Upon further inspection (manually collecting the device, then trying to configure it), I also see this error:

In [16]: device.set_configuration(0)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-2e72cff85b10> in <module>()
----> 1 device.set_configuration(0)

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/core.pyc in set_configuration(self, configuration)
    797         without arguments is enough to get the device ready.
    798         """
--> 799         self._ctx.managed_set_configuration(self, configuration)
    800
    801     def get_active_configuration(self):

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/core.pyc in managed_set_configuration(self, device, config)
    125             cfg = util.find_descriptor(device, bConfigurationValue=config)
    126
--> 127         self.managed_open()
    128         self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
    129

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/core.pyc in managed_open(self)
    103     def managed_open(self):
    104         if self.handle is None:
--> 105             self.handle = self.backend.open_device(self.dev)
    106         return self.handle
    107

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/libusb1.pyc in open_device(self, dev)
    720     @methodtrace(_logger)
    721     def open_device(self, dev):
--> 722         return _DeviceHandle(dev)
    723
    724     @methodtrace(_logger)

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/libusb1.pyc in __init__(self, dev)
    598         self.handle = _libusb_device_handle()
    599         self.devid = dev.devid
--> 600         _check(_lib.libusb_open(self.devid, byref(self.handle)))
    601
    602 class _IsoTransferHandler(object):

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/libusb1.pyc in _check(ret)
    550             raise NotImplementedError(_strerror(ret))
    551         else:
--> 552             raise USBError(_strerror(ret), ret, _libusb_errno[ret])
    553
    554     return ret

/home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/libusb1.pyc in _strerror(errcode)
    539
    540 def _strerror(errcode):
--> 541     return _lib.libusb_strerror(errcode).decode('utf8')
    542
    543 # check a libusb function call

/usr/lib/python2.7/ctypes/__init__.pyc in __getattr__(self, name)
    376         if name.startswith('__') and name.endswith('__'):
    377             raise AttributeError(name)
--> 378         func = self.__getitem__(name)
    379         setattr(self, name, func)
    380         return func

/usr/lib/python2.7/ctypes/__init__.pyc in __getitem__(self, name_or_ordinal)
    381
    382     def __getitem__(self, name_or_ordinal):
--> 383         func = self._FuncPtr((name_or_ordinal, self))
    384         if not isinstance(name_or_ordinal, (int, long)):
    385             func.__name__ = name_or_ordinal

AttributeError: /lib/arm-linux-gnueabihf/libusb-1.0.so.0: undefined symbol: libusb_strerror

Has anyone else encountered this problem? is there something that I am doing wrong? I'm willing to help hack on this if I can get some guidance as to how I can proceed. Thanks.

distro information

Linux version 3.10.25+ (dc4@dc4-arm-01) 
PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)"

libusb information

Package: libusb-1.0-0
Status: install ok installed
Priority: optional
Section: libs
Installed-Size: 95
Maintainer: Aurelien Jarno <aurel32@debian.org>
Architecture: armhf
Multi-Arch: same
Source: libusbx
Version: 2:1.0.11-1
Depends: libc6 (>= 2.13-28)
Pre-Depends: multiarch-support
Description: userspace USB programming library
 Library for programming USB applications without the knowledge
 of Linux kernel internals.
Homepage: http://www.linux-usb.org/
lfaraone commented 9 years ago

​See https://github.com/Tigge/Garmin-Forerunner-610-Extractor/issues/103

AlanJAS commented 9 years ago

Wich version of PyUSB are you using?

Date: Thu, 1 Jan 2015 11:07:40 -0800 From: notifications@github.com To: WeDoMore@noreply.github.com Subject: [WeDoMore] Problems on Rasbpian (#5)

I'm using Raspbian and python and trying to connect to wedo. The device is detected just fine, but there appears to be a problem with the interface between pyusb and the os version of libusb (I'm guessing at this, but it seems reasonable).

when I run the command >>> wd = WeDo(), it fails during the init and gives the following traceback:

In [3]: wd = WeDo()

NotImplementedError Traceback (most recent call last)

in () ----> 1 wd = WeDo() /home/cameron/prj/wedo/WeDoMore/wedo/**init**.pyc in **init**(self, device) 69 raise OSError("Could not find a connected WeDo device") 70 self.dev = devices[0] ---> 71 self.init_device() 72 self.valMotorA = 0 73 self.valMotorB = 0 /home/cameron/prj/wedo/WeDoMore/wedo/**init**.pyc in init_device(self) 79 """ 80 try: ---> 81 if os.name != 'nt' and self.dev.is_kernel_driver_active(WEDO_INTERFACE): 82 try: 83 self.dev.detach_kernel_driver(WEDO_INTERFACE) /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/core.pyc in is_kernel_driver_active(self, interface) 990 return self._ctx.backend.is_kernel_driver_active( 991 self._ctx.handle, --> 992 interface) 993 994 def detach_kernel_driver(self, interface): /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/**init**.pyc in is_kernel_driver_active(self, dev_handle, intf) 361 and the backend will be unable to perform I/O. 362 """ --> 363 _not_implemented(self.is_kernel_driver_active) 364 365 def detach_kernel_driver(self, dev_handle, intf): /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/**init**.pyc in _not_implemented(func) 77 78 def _not_implemented(func): ---> 79 raise NotImplementedError(func.__name__) 80 81 class IBackend(object): NotImplementedError: is_kernel_driver_active Upon further inspection (manually collecting the device, then trying to configure it), I also see this error: ## In [16]: device.set_configuration(0) AttributeError Traceback (most recent call last) in () ----> 1 device.set_configuration(0) /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/core.pyc in set_configuration(self, configuration) 797 without arguments is enough to get the device ready. 798 """ --> 799 self._ctx.managed_set_configuration(self, configuration) 800 801 def get_active_configuration(self): /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/core.pyc in managed_set_configuration(self, device, config) 125 cfg = util.find_descriptor(device, bConfigurationValue=config) 126 --> 127 self.managed_open() 128 self.backend.set_configuration(self.handle, cfg.bConfigurationValue) 129 /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/core.pyc in managed_open(self) 103 def managed_open(self): 104 if self.handle is None: --> 105 self.handle = self.backend.open_device(self.dev) 106 return self.handle 107 /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/libusb1.pyc in open_device(self, dev) 720 @methodtrace(_logger) 721 def open_device(self, dev): --> 722 return _DeviceHandle(dev) 723 724 @methodtrace(_logger) /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/libusb1.pyc in **init**(self, dev) 598 self.handle = _libusb_device_handle() 599 self.devid = dev.devid --> 600 _check(_lib.libusb_open(self.devid, byref(self.handle))) 601 602 class _IsoTransferHandler(object): /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/libusb1.pyc in _check(ret) 550 raise NotImplementedError(_strerror(ret)) 551 else: --> 552 raise USBError(_strerror(ret), ret, _libusb_errno[ret]) 553 554 return ret /home/cameron/.virtualenvs/wedo/local/lib/python2.7/site-packages/usb/backend/libusb1.pyc in _strerror(errcode) 539 540 def _strerror(errcode): --> 541 return _lib.libusb_strerror(errcode).decode('utf8') 542 543 # check a libusb function call /usr/lib/python2.7/ctypes/**init**.pyc in **getattr**(self, name) 376 if name.startswith('**') and name.endswith('**'): 377 raise AttributeError(name) --> 378 func = self.**getitem**(name) 379 setattr(self, name, func) 380 return func /usr/lib/python2.7/ctypes/**init**.pyc in **getitem**(self, name_or_ordinal) 381 382 def **getitem**(self, name_or_ordinal): --> 383 func = self._FuncPtr((name_or_ordinal, self)) 384 if not isinstance(name_or_ordinal, (int, long)): 385 func.__name__ = name_or_ordinal AttributeError: /lib/arm-linux-gnueabihf/libusb-1.0.so.0: undefined symbol: libusb_strerror Has anyone else encountered this problem? is there something that I am doing wrong? I'm willing to help hack on this if I can get some guidance as to how I can proceed. Thanks. distro information Linux version 3.10.25+ (dc4@dc4-arm-01) PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)" libusb information Package: libusb-1.0-0 Status: install ok installed Priority: optional Section: libs Installed-Size: 95 Maintainer: Aurelien Jarno aurel32@debian.org Architecture: armhf Multi-Arch: same Source: libusbx Version: 2:1.0.11-1 Depends: libc6 (>= 2.13-28) Pre-Depends: multiarch-support Description: userspace USB programming library Library for programming USB applications without the knowledge of Linux kernel internals. Homepage: http://www.linux-usb.org/ — Reply to this email directly or view it on GitHub. ``` = ```
crlane commented 9 years ago

@lfaraone thanks for the link. Looked through that and tried using libopenusb0, but that didn't seem to work

@AlanJAS here's my version info of pyusb.

In [2]: usb.version_info
Out[2]: (1, 0, 0, 'b2')
AlanJAS commented 9 years ago

That seems the libusb is the old..A workarround: If you comment the two lines of the "if" and try again? Date: Thu, 1 Jan 2015 13:13:13 -0800 From: notifications@github.com To: WeDoMore@noreply.github.com CC: alanjas@hotmail.com Subject: Re: [WeDoMore] Problems on Rasbpian (#5)

@lfaraone thanks for the link. Looked through that and tried using libopenusb0, but that didn't seem to work

@AlanJAS here's my version info of pyusb.

In [2]: usb.version_info Out[2]: (1, 0, 0, 'b2')

— Reply to this email directly or view it on GitHub.

                  =
crlane commented 9 years ago

@AlanJAS Tried commenting out the offending lines. Now I end up with problems accessing the logger? Very strange. I'll keep looking for a solution that works, as I'd really like to be able to use python with the WeDo. Thanks for all your help.

AlanJAS commented 9 years ago

I'm using a bit new PyUsb version (directly with the git).Can you test this code: http://www.fing.edu.uy/~aaguiar/files/test.tar.gz It have his own pyusb, only run: python test.pyIf works, must turn motor on.If fails, must appears the problem.

Date: Sat, 3 Jan 2015 07:32:46 -0800 From: notifications@github.com To: WeDoMore@noreply.github.com CC: alanjas@hotmail.com Subject: Re: [WeDoMore] Problems on Rasbpian (#5)

@AlanJAS Tried commenting out the offending lines. Now I end up with problems accessing the logger? Very strange. I'll keep looking for a solution that works, as I'd really like to be able to use python with the WeDo. Thanks for all your help.

— Reply to this email directly or view it on GitHub.

                  =
crlane commented 9 years ago

Again, looks like it got the device okay, but pyusb was unable to configure the device. Unexpectedly, it gives a resource busy error from pyusb.

Traceback (most recent call last):
  File "test.py", line 59, in <module>
    w.init_device()
  File "test.py", line 35, in init_device
    self.dev.set_configuration(WEDO_CONFIGURATION)
  File "/home/cameron/test/usb/core.py", line 799, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/home/cameron/test/usb/core.py", line 128, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "/home/cameron/test/usb/backend/libusb1.py", line 738, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "/home/cameron/test/usb/backend/libusb1.py", line 560, in _check
    raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy
crlane commented 9 years ago

Didn't really mean to close; however, it appears this is not a problem with WeDoMore, but rather an issue between libusb and pyusb. Perhaps I'll open a bug report there. Thanks again for all the help.