itdaniher / WeDoMore

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

Access denied on OS X #6

Open cbare opened 9 years ago

cbare commented 9 years ago

Hi, cool project. Is this known to work (or not) on Mac OS X? I tried and got the following error:

import logging
from wedo import WeDo
logging.basicConfig()
wd = WeDo()
wd.motor_a = 100
ERROR:wedo:Could not write to driver
Traceback (most recent call last):
  File "wedo/__init__.py", line 109, in setMotors
    self.dev.ctrl_transfer(bmRequestType=0x21, bRequest=0x09, wValue=0x0200, wIndex=0, data_or_wLength=data)
  File "build/bdist.macosx-10.9-x86_64/egg/usb/core.py", line 962, in ctrl_transfer
    self._ctx.managed_claim_interface(self, interface_number)
  File "build/bdist.macosx-10.9-x86_64/egg/usb/core.py", line 146, in managed_claim_interface
    self.backend.claim_interface(self.handle, i)
  File "build/bdist.macosx-10.9-x86_64/egg/usb/backend/libusb1.py", line 747, in claim_interface
    _check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
  File "build/bdist.macosx-10.9-x86_64/egg/usb/backend/libusb1.py", line 552, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno 13] Access denied (insufficient permissions)

I came across a ticket for libusb that seems to indicate that Mac OS X is not supported. Any hints appreciated.

itdaniher commented 9 years ago

Would you try running python with sudo?

cbare commented 9 years ago

OK, I got the same thing:

$ sudo python
Password:
Python 2.7.8 (default, Oct 19 2014, 16:03:53) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> from wedo import WeDo
>>> 
>>> logging.basicConfig()
>>> 
>>> wd = WeDo()
>>> wd.motor_a = 100
ERROR:wedo:Could not write to driver
Traceback (most recent call last):
  File "wedo/__init__.py", line 109, in setMotors
    self.dev.ctrl_transfer(bmRequestType=0x21, bRequest=0x09, wValue=0x0200, wIndex=0, data_or_wLength=data)
  File "build/bdist.macosx-10.9-x86_64/egg/usb/core.py", line 962, in ctrl_transfer
    self._ctx.managed_claim_interface(self, interface_number)
  File "build/bdist.macosx-10.9-x86_64/egg/usb/core.py", line 146, in managed_claim_interface
    self.backend.claim_interface(self.handle, i)
  File "build/bdist.macosx-10.9-x86_64/egg/usb/backend/libusb1.py", line 747, in claim_interface
    _check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
  File "build/bdist.macosx-10.9-x86_64/egg/usb/backend/libusb1.py", line 552, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno 13] Access denied (insufficient permissions)
itdaniher commented 9 years ago

OSX is supported by libusb. It's been a year or two since I last tried pyusb on OSX.

It's possible another driver could be using the device. Poke around in osx's device manager, see if you can find the wedo, and moreover see if there's any software indicated as currently handling the device?

cbare commented 9 years ago

The device manager sees it. Under USB-3.0 Hi-Speed Bus it says:

LEGO USB Hub V1.00:

  Product ID:   0x0003
  Vendor ID:    0x0694  (Lego Group)
  Version:   1.00
  Speed:    Up to 1.5 Mb/sec
  Location ID:  0x14200000 / 2
  Current Available (mA):   500
  Current Required (mA):    100

I don't see anything about drivers.

Thanks for the response, BTW.

cbare commented 9 years ago

I did a bit more poking around and it seems that the wedo device identifies itself as a "USB Human Interface Device" device and it sounds like OS-X's built in HID driver binds to the device and I'm seeing the permission error because libusb is trying to bind to it when there's already a driver bound. (...with the caveat that my understanding is pretty shaky on all this.)

Scratch can talk to it via a non-open-source browser plugin.

itdaniher commented 9 years ago

Iiiinteresting.

That sounds plausible. I know Windows has trouble unbinding kernel drivers from inside Python.

Link me to the browser plugin?

cbare commented 9 years ago

Info on the scratch extension is here along with installation instructsions. But, it's distributed as a closed source binary. Bummer!