itdaniher / WeDoMore

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

usb.core.USBError: Resource busy #4

Closed joefly888 closed 10 years ago

joefly888 commented 10 years ago

using code on raspberry Pi Rev B rev1,2

confirm works with Scratch on Rpi out of the box, Have done new install of raspbian and also powered hub seen others having similar problem on pi

erroor code

pi@raspberrypi ~ $ sudo python Python 2.7.3 (default, Mar 18 2014, 05:13:23) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

from wedo import WeDo wd=WeDo() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/wedo-1.0.0-py2.7.egg/wedo/init.py", line 60, in init raise OSError("Could not find a connected WeDo device") OSError: Could not find a connected WeDo device wd=WeDo() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/wedo-1.0.0-py2.7.egg/wedo/init.py", line 62, in init self.dev.set_configuration() File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 530, in set_configuration self._ctx.managed_set_configuration(self, configuration) File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 92, in managed_set_configuration self.backend.set_configuration(self.handle, cfg.bConfigurationValue) File "/usr/local/lib/python2.7/dist-packages/usb/_debug.py", line 52, in do_trace return f(_args, *_named_args) File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 455, in set_configuration _check(_lib.libusb_set_configuration(dev_handle, config_value)) File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 357, in _check raise USBError(_str_error[retval.value]) usb.core.USBError: Resource busy

itdaniher commented 10 years ago

relevant dmesg log:

http://itdaniher.com/p?TeZY

ming - can you run 'lsmod' after plugging in the wedo? I suspect the 'hiddev' kernel module is blocking python's use of the usb device. scratch may unload the module on start.

itdaniher commented 10 years ago

someone else ran into a similar problem, also on raspbian: http://unix.stackexchange.com/questions/55495/prevent-usbhid-from-claiming-usb-device

itdaniher commented 10 years ago

It looks like the solution is to add a udev rule to flag the device as not an input device.

I built a test rule, uploaded at http://itdaniher.com/p?UltH.

To try it out, run:

sudo wget -O /etc/udev/rules.d/wedomore.rules http://itdaniher.com/p?UltH

and reboot.

joefly888 commented 10 years ago

ian, tried this and same error, and did reboot

hephaestos commented 10 years ago

I am having the same "resource busy" error. I am running Ubuntu 14.04. my error looks like this.

from wedo import WeDo wd = WeDo() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/wedo-1.0.0-py2.7.egg/wedo/init.py", line 62, in init self.dev.set_configuration() File "usb/core.py", line 559, in set_configuration self._ctx.managed_set_configuration(self, configuration) File "usb/core.py", line 92, in managed_set_configuration self.backend.set_configuration(self.handle, cfg.bConfigurationValue) File "usb/backend/libusb1.py", line 741, in set_configuration _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value)) File "usb/backend/libusb1.py", line 571, in _check raise USBError(_str_error[ret], ret, _libusb_errno[ret]) usb.core.USBError: [Errno 16] Resource busy

itdaniher commented 10 years ago

I'll work to get my hands on a WeDo soon, haven't the hardware to debug now.

cpseager commented 10 years ago

You can get error 16 if your udev rule isn't correct. This works for me on Ubuntu 14.04

Remove the WeDo cable from the computer then type

sudo gedit /etc/udev/rules.d/99-legousb.rules

Right click in gedit and paste in this text.

# WeDo dialout rule
SUBSYSTEM=="usb", ATTRS{idVendor}=="0694", ATTRS{idProduct}=="0003", GROUP="dialout", MODE="0666"

then save and exit gedit. Also make sure you are in the dialout group, then reboot to make sure the groups and udev rules are active.

sudo adduser your_user_name dialout
sudo reboot

I tend to use the dialout group as that is where similar usb<>serial adapter type things also end up by default, but you could use any group you are a member of.

hephaestos commented 10 years ago

I have done this and am still getting the same error.

itdaniher commented 10 years ago

Please run lsof | curl --http1.0 -F "content=<-" itdaniher.com/p and paste the resulting URL. lsof shows all open programs and the executable with lock.

Thanks, Ian

cpseager commented 10 years ago

@Hephaestos Have you installed libhid, and if so is it grabbing the WeDo? Check with:

sudo lsusb -t

If so you can release the device using

sudo libhid-detach-device 0694:0003
AlanJAS commented 10 years ago

Hi,

I have this rule:

UBSYSTEMS=="usb", ATTRS{idVendor}=="0694", ATTRS{idProduct}=="0003", GROUP="robots", MODE="0660"

And I in the group "robots".

Wich version of PyUSB are you using?

AlanJAS commented 10 years ago

I found the problem. The code try set a configuration before dettach kernel driver! I fix that in my fork (i send a pull request with that and another things). Please test it.

itdaniher commented 10 years ago

I've merged Alan's work on WeDoMore into master. It should behave the same, as well as work nicely on OLPC XO linux distros. Once someone can confirm that moving the detach to before the configuration set solves the issue at hand, then this issue can be closed.

joefly888 commented 10 years ago

AlanJAS, great work, this now works for me on RPI. Thanks Guys, and to ian for the original work