python-ivi / python-usbtmc

Provides a USBTMC driver for controlling instruments over USB
MIT License
160 stars 69 forks source link

pyusb doesnt have enough permissionsto detach kernel driver #2

Closed Zaharid closed 10 years ago

Zaharid commented 10 years ago

Hi,

I am trying to run usbtmc as nonroot in linux mint 15.

I have set the permissions with an udev rule as described in the index. I can do things like:

echo "*idn?" >> /dev/usbtmc0

and cat /dev/usbtmv0

However I get the following error when running as non root:


In [1]: import usbtmc

In [2]: device = usbtmc.list_devices()[0]

In [3]: device
Out[3]: <usb.core.Device at 0x13c5d50>

In [4]: instr = usbtmc.Instrument(device)
---------------------------------------------------------------------------
USBError                                  Traceback (most recent call last)
<ipython-input-4-830fc6de9693> in <module>()
----> 1 instr = usbtmc.Instrument(device)

/usr/local/lib/python2.7/dist-packages/python_usbtmc-0.1-py2.7.egg/usbtmc/usbtmc.pyc in __init__(self, *args, **kwargs)
    163 
    164         # initialize device
--> 165         if self.device.is_kernel_driver_active(0):
    166             self.device.detach_kernel_driver(0)
    167 

/usr/local/lib/python2.7/dist-packages/usb/core.pyc in is_kernel_driver_active(self, interface)
    717         """If a kernel driver is active, and the object will be unable to perform I/O.
    718         """
--> 719         self._ctx.managed_open()
    720         return self._ctx.backend.is_kernel_driver_active(self._ctx.handle,
    721                 self._ctx.get_interface(self, interface).bInterfaceNumber)

/usr/local/lib/python2.7/dist-packages/usb/core.pyc in managed_open(self)
     68     def managed_open(self):
     69         if self.handle is None:
---> 70             self.handle = self.backend.open_device(self.dev)
     71         return self.handle
     72 

/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.pyc in open_device(self, dev)
    731     @methodtrace(_logger)
    732     def open_device(self, dev):
--> 733         return _DeviceHandle(dev)
    734 
    735     @methodtrace(_logger)

/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.pyc in __init__(self, dev)
    616         self.handle = _libusb_device_handle()
    617         self.devid = dev.devid
--> 618         _check(_lib.libusb_open(self.devid, byref(self.handle)))
    619 
    620 class _IsoTransferHandler(object):

/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.pyc in _check(retval)
    569         if retval.value < 0:
    570            ret = retval.value
--> 571            raise USBError(_str_error[ret], ret, _libusb_errno[ret])
    572     return retval
    573 

USBError: [Errno 13] Access denied (insufficient permissions)
alexforencich commented 10 years ago

python-usbtmc actually doesn't use the /dev/usbtmc devices, it detaches the driver that provides those and then communicates with the instrument directly. I think you still may have a permissions issue. Can you please check the permissions of the USB device itself in /dev/bus/usb? lsusb will give you the bus and device numbers, so just run ls -al /dev/bus/usb/[bus]/[device] and let me know what it says.

Zaharid commented 10 years ago

Hi, thank you for the fast reply.

After a few hours of fighting it worked after rebooting (probably needed to restart something in udev). This was pretty lame...

By the way, what is the reason you don't use the linux driver?

alexforencich commented 10 years ago

Yeah, it's a bit annoying when it requires the standard Windows solution (reboot) to fix a problem in Linux. Anyway, the reason I don't just wrap the Linux driver is because I want python ivi and as many of the interface modules as possible to be cross platform, and Windows does not have a built in usbtmc driver. I have not yet tested python USBTMC on Windows, however.

Alex Forencich

Zaharid notifications@github.com wrote:

Hi, thank you for the fast reply.

After a few hours of fighting it worked after rebooting (probably needed to restart something in udev). This was pretty lame...

By the way, what is the reason you don't use the linux driver?


Reply to this email directly or view it on GitHub: https://github.com/alexforencich/python-usbtmc/issues/2#issuecomment-27978193