Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: help with libusb

  1. #11
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: help with libusb

    Hmmm, it looks like the documentation is a little bit incomplete here. Try calling "usb_set_debug(3)" before the execution of the rest of your commands and see if you get any additional information.

    Just found another thread on the same problem: http://www.nabble.com/usb_claim_inte...d17792140.html. Maybe that helps.

  2. #12
    Join Date
    Aug 2008
    Location
    worcs
    Beans
    10
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: help with libusb

    Thanks for that. I now get an additional error message "USB error: could not claim interface 0: No such file or directory". I am looking into that other thread, which as you say, sounds very relevant.

    ta, Nick

  3. #13
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,267
    Distro
    Kubuntu

    Re: help with libusb

    Quote Originally Posted by nickbarnes View Post
    ...
    Am I right in concluding that a -1 error, returned by usb_set_configuration and usb_claim_interface, is a -EPERM?
    ...
    If you want error code, include <errno.h>, then reference the value of the global variable 'errno'. If you want the English version of the error, use strerror().

    For example:
    PHP Code:
    #include <errno.h>
    #include <string.h>
    ...
    if ( 
    Clibfunc() == -)
    {
      
    // be careful not to call anything else here, as that might change
      // the value of errno.
      
    const char *error strerror(errno);
      
    printf"%s\n"error );
    }
    ... 

  4. #14
    Join Date
    Aug 2008
    Location
    worcs
    Beans
    10
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: help with libusb

    I have yet another output message now "No such file or directory".

    Nick

  5. #15
    Join Date
    Aug 2008
    Location
    worcs
    Beans
    10
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: help with libusb

    I have also tried Xiang's usb_get_driver_np. It returns -61 (No data available) and consequently does not attempt the detach_kernel_driver_np anymore. What it is saying is that there is not another driver already loaded. This makes sense, because the device concerned is proprietry and has never been used for linux, so there is no existing driver for it.

    thanks, Nick

  6. #16
    Join Date
    Aug 2008
    Location
    worcs
    Beans
    10
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: help with libusb

    Hello chaps

    Have solved my problems
    1. problem 1 was that I needed write access to the files in /dev/bus/usb. If I chmod this it works, but reverts back to read only on reboot, so put chmod o+w -R /dev/bus/usb into /etc/init.d/rc shell script
    2. problem 2 was that I needed the right configuration in my call to usb_set_configuration. I needed to do lsusb -v and read the bConfigurationValue for my device and use this as the 2nd param in the call.

    Having done these two simple things, I was able to claim my interface and do my bulk write to end point 1.

    thanks to all
    Nick

  7. #17
    Join Date
    Aug 2008
    Beans
    7

    Re: help with libusb

    You need to do a usb_detach_kernel_driver_np( udev, interface); before the usb_claim_interface. The reason, I have read, is that the kernel has claimed the interface, and it has to be detached before the process claims it.

    G

  8. #18
    Join Date
    Aug 2008
    Beans
    7

    Re: help with libusb

    My apologies. I read back a page and see you did use detach_kernel_driver_np .

    I had similar problems with usb_claim_interface, and it was solved via the detach.

    Your solution is plausible, and should work. Next time I'll read a bit more before sticking my foot in my mouth.

    G

  9. #19
    Join Date
    Aug 2007
    Beans
    1

    Re: help with libusb

    I didn't have to modify my /dev/bus/usb permissions - not sure why.

    Here's what I hacked up to successfully claim my interface:
    Code:
    ...
    
    usb_dev_handle * open_and_claim(struct usb_device *dev, int interface) {
    
      usb_dev_handle *dh;
      int res;
    
      dh = usb_open(dev);
    	
      if(dh == NULL) {
        printf("Could not open device: %s\n", usb_strerror());
        return NULL;
      }
    
    #if defined(LIBUSB_HAS_GET_DRIVER_NP)
    #if defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
      char *name[256];
      if (usb_get_driver_np(dh, interface, (char *) name, sizeof(name)) == 0)
      {
        if (usb_detach_kernel_driver_np(dh, interface) < 0)
        {
          printf("%s\n", usb_strerror());
          return NULL;
        }
        usb_set_altinterface(dh, interface);
      }
    #endif
    #endif
    	
      res = usb_claim_interface(dh, interface);
    	
      if(res != 0) {
        printf("%s\n", usb_strerror());
        return NULL;
      }
    
      return dh;
    }
    
    ...
    I'm not sure the above is complete or well coded, but I hope it helps.
    Last edited by mooselix; August 19th, 2008 at 07:14 PM. Reason: assert(not_compatible(foot, mouth));

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •