Xiaofan Chen | 1 Jun 14:59 2008
Picon

How to better distribute a libusb based program under Linux

Jeff Post (http://home.pacbell.net/theposts/picmicro/) is the author of the
two programs (pk2 and pk2cmdLinux) to use Microchip PICkit 2
(http://www.microchip.com/pickit2) under Linux. We support Linux
PICkit 2 users with the Google group pickit-devel
(http://groups.google.com/group/pickit-devel).

Right now Jeff distributs the source package and then the user
can build the binary from the source packages. He would like to
make it as easy as possible for the end user. Unfortunately there
will not be a universal binaries for various Linux distros. If there is,
that would be nice.

He would like to have codes that would just compile and run
without all the headaches of installing libusb, setting udev or
hotplug rules, etc.

To me installing libusb is not a big problem. Runtime library should
already be installed for many distros. The development header file is not
always installed. But mostly it is called libusb-dev or libusb-devel.

Unfortunately udev rules are the part and parcel with different Linux
distros if we want pk2/pk2cmd to be run as as normal user.

Are there any good solutions to support various distros which
have different package name for libusb development packages
and more importantly different udev rules implementations?

Right now I can only think of setting up a wiki or something like
that to tell the user how to build pk2/pk2cmd and how to
set up the udev rules.
(Continue reading)

Xiaofan Chen | 2 Jun 05:52 2008
Picon

Re: Help debugging my first libusb-1.0 program

On Wed, May 28, 2008 at 10:20 PM, Xiaofan Chen <xiaofanc <at> gmail.com> wrote:
> Hmm, I must miss something very obvious. I just "wrote" (copy/paste)
> a simple libusb-1.0 based program for Jan Axelson's Generic WinUSB
> example (http://www.lvr.com/winusb.htm).
> Now it has the same problem with my other program based
> on OpenUSB. The first run will be ok. After that, it will not work any
> more.
>
> The original program based on libusb-0.1 works fine every time.
> http://forum.microchip.com/tm.aspx?m=340892

After some trying, I have got it work thanks to the help of Daniel.
I've got the loop back testing working for control transfer, interrupt
transfer and bulk transfer with libusb-1.0.

The codes are listed here. If it does not show properly, you can
also get it from the Microchip forum.
http://forum.microchip.com/tm.aspx?m=340892

#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <libusb-1.0/libusb.h>

#define VERSION "0.1.0"

#define VENDOR_ID 0x0925
(Continue reading)

Xiaofan Chen | 2 Jun 06:13 2008
Picon

Re: Help debugging my first openusb program

On Thu, May 29, 2008 at 9:23 PM, Daniel Drake <dsd <at> gentoo.org> wrote:
> I actually just modified libusb to not do anything when requested to set the
> same configuration again. This will break things for you even when you do
> make the equivalent change to your app. I'll add
> libusb_set_configuration_forced() or something.
>

You are right. It does break the program. But I think this does make
libusb-compact-0.1 not behave the same as libusb 0.1 unless you
change the implementation of usb_set_configuration() in
libusb-compact-0.1.

Xiaofan

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Michael Lewis | 2 Jun 18:42 2008
Picon

Re: Help debugging my first openusb program

On Fri, May 30, 2008 at 11:26 PM, Xiaofan Chen <xiaofanc <at> gmail.com> wrote:

On Thu, May 29, 2008 at 10:25 PM, Xiaofan Chen <xiaofanc <at> gmail.com> wrote:
> Unfortunately, this does not work for openusb based program.
>
> I add the following code before claiming the interface.
>        ret = openusb_set_configuration(lvr_winusb, 1);
>        if ( ret != OPENUSB_SUCCESS)
>        {
>                printf("Cannot set configuration 1.\n");
>                printf("Error code %d.\n",ret);
>                exit(-1);
>        }
>
> However this will fail.
>
> mcuee <at> ubuntu804:~/Desktop/build/winusb$ ./openusb_winusb
> Specified USB device found.
> Cannot set configuration 1.
> Error code -8.
>
> According to openusb.h, it means invalid parameter. Strange.
> #define OPENUSB_BADARG                  -8      /* Invalid parameter */

This is very strange.
Opening the device is successful.
       ret = openusb_open_device(libhandle, devids[i], USB_INIT_DEFAULT, &lvr_winusb);
       if (ret != OPENUSB_SUCCESS)
       {
               printf("Cannot open specified device.\n");
               printf("Error code %d.\n",ret);
               exit(-1);
       }
       printf("Specified USB device found.\n");

Setting the configuration will fail.
       ret = openusb_set_configuration(lvr_winusb, 1);
       if ( ret != OPENUSB_SUCCESS)
       {
               printf("Cannot set configuration 1.\n");
               printf("Error code %d.\n",ret);
               exit(-1);
       }
       printf("Successfully set usb configuration 1.\n");

>From the source code, the problem is that handle lvr_winusb
does not exist. However it does exist since the call to
openusb_open_device is successful.

>From the source code linux.c:
/*
 * linux_set_configuration
 *
 *  Sets the usb configuration, via IOCTL_USB_SETCONFIG
 */
int32_t linux_set_configuration(struct usbi_dev_handle *hdev, uint8_t cfg)
{
       int32_t ret;

       /* Validate... */
       if (!hdev)
               return OPENUSB_BADARG;

       ret = ioctl(hdev->priv->fd, IOCTL_USB_SETCONFIG, &cfg);
       if (ret < 0) {
               usbi_debug(hdev->lib_hdl, 1, "could not set config %u: %s", cfg,
                                                        strerror(errno));
               return (translate_errno(errno));
       }

       hdev->idev->cur_config = cfg;
       hdev->config_value = cfg + 1;

       return (OPENUSB_SUCCESS);
}

What is the potential problem here?

Regards,
Xiaofan


I will take a look at this tonight and see what I can find. I've was able to replicate the problem with one of my devices, so I should be able to find it pretty easily.

--Mike
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Libusb-devel mailing list
Libusb-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel
srpoc103 | 3 Jun 10:21 2008
Picon

Re: Sample application using OpenUSB isochronous transfer

Quoting Lei Chen <Raymond.Chen <at> Sun.COM>:

> Hi developers,
>     Thanks to a developer's great effort, there appears the application
> using OpenUSB to do ISOC transfer on Solaris. This application operates
> on an OV511/OV511+ based webcam. It works very well when capturing
> image. You can get the source code from:
> http://dev4usb.netbeans.org/source/browse/dev4usb/samples/webeye/webeye_video/
> and have a try on Solaris with latest OpenUSB svn version(I believe it
> will also work on Linux). This application is part of dev4usb project in
> NetBeans community. With dev4usb, developers can easily develop an
> application to drive USB device using libusb or OpenUSB library. See
> more information at: http://dev4usb.netbeans.org/.
>
> Regards,
> Lei Chen
>
>

Has anyone tested this on Linux? I am having problems with ISO URBs  
using the Linux OpenUSB backend.

>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Libusb-devel mailing list
> Libusb-devel <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libusb-devel
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Lei Chen | 3 Jun 11:21 2008
Picon

Re: Sample application using OpenUSB isochronous transfer

srpoc103 <at> ecs.soton.ac.uk wrote:
> Quoting Lei Chen <Raymond.Chen <at> Sun.COM>:
>
>   
>> Hi developers,
>>     Thanks to a developer's great effort, there appears the application
>> using OpenUSB to do ISOC transfer on Solaris. This application operates
>> on an OV511/OV511+ based webcam. It works very well when capturing
>> image. You can get the source code from:
>> http://dev4usb.netbeans.org/source/browse/dev4usb/samples/webeye/webeye_video/
>> and have a try on Solaris with latest OpenUSB svn version(I believe it
>> will also work on Linux). This application is part of dev4usb project in
>> NetBeans community. With dev4usb, developers can easily develop an
>> application to drive USB device using libusb or OpenUSB library. See
>> more information at: http://dev4usb.netbeans.org/.
>>
>> Regards,
>> Lei Chen
>>
>>
>>     
>
> Has anyone tested this on Linux? I am having problems with ISO URBs  
> using the Linux OpenUSB backend.
>   
What's the problem? Can the application get isoc packet?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
srpoc103 | 3 Jun 11:20 2008
Picon

Re: Sample application using OpenUSB isochronous transfer

Quoting Lei Chen <Raymond.Chen <at> Sun.COM>:

> srpoc103 <at> ecs.soton.ac.uk wrote:
>> Quoting Lei Chen <Raymond.Chen <at> Sun.COM>:
>>
>>
>>> Hi developers,
>>>     Thanks to a developer's great effort, there appears the application
>>> using OpenUSB to do ISOC transfer on Solaris. This application operates
>>> on an OV511/OV511+ based webcam. It works very well when capturing
>>> image. You can get the source code from:
>>> http://dev4usb.netbeans.org/source/browse/dev4usb/samples/webeye/webeye_video/
>>> and have a try on Solaris with latest OpenUSB svn version(I believe it
>>> will also work on Linux). This application is part of dev4usb project in
>>> NetBeans community. With dev4usb, developers can easily develop an
>>> application to drive USB device using libusb or OpenUSB library. See
>>> more information at: http://dev4usb.netbeans.org/.
>>>
>>> Regards,
>>> Lei Chen
>>>
>>>
>>>
>>
>> Has anyone tested this on Linux? I am having problems with ISO URBs
>> using the Linux OpenUSB backend.
>>
> What's the problem? Can the application get isoc packet?
>
>

No the library segfaults at various places, I'm trying to work out if  
it's something I'm doing wrong or not, I think it's a problem in the  
couple of the library functions - at the moment I have a problem with  
the free() calls in free_isoc_urbs() in linux.c

>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Libusb-devel mailing list
> Libusb-devel <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libusb-devel
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Dany Joumaa | 3 Jun 15:09 2008
Picon

libusb_handle_events() and timing

Hi.

I've got this strange thing going here: I'm trying to do a synchronous 
transfer to a USB device. The transfer is successful and there are no 
anomalies on that front. However, when I call libusb_handle_events() to 
block for a response on a transfer I've previously submitted, nothing 
comes in when I'm positive *something* should be coming in.

Naturally the remedy to waiting for data and not having that data come 
in is to increase the waiting time. Consequently, after my transfer but 
before my call to block events, I sleep a number of seconds, hoping 
that the device would have more than enough time to send its data. But 
no matter how much I sleep before calling handle events, the data 
doesn't come in.

Here's the weird part: if I remove my call to sleep() and place another 
call to handle events after a certain if statement, the data comes in 
on time! It also works when I put a call to handle events outside of 
the original calling function, after it finished. (I tried calling 
handle events twice in succession, in hope that it would work, but to 
no avail.)

Here's the code for reference:

  struct _usb_cmdreq out_packet;
..
  if( err = libusb_bulk_transfer( pdrv_handle, 0x02, (unsigned char
*)&out_packet, 
                            sizeof(out_packet), &transferred, 10000 ) <
0 ) {
    fprintf( stderr, "Failed to transfer command request, %i.\n", err );
    return -1;
  }

  sleep(2);

  // Block until we get a response
  if( libusb_handle_events( ) <0 ) {
    fprintf( stderr, "Handle events failed: %i\n", transferred );
    return -1;
  }

  if( pdrv_resp_buffer->cmdresp.status >> 7  ) {
    ... // when step-debugging, this truncated scope doesn't run
  }

  // a call to handle_events here again, without the sleep() above,
  // seems to fix it

I appreciate the help very much.

--ness

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Libusb-devel mailing list
Libusb-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel
Daniel Drake | 4 Jun 00:07 2008
Picon

Re: libusb_handle_events() and timing

Dany Joumaa wrote:
> Hi.
> 
> I've got this strange thing going here: I'm trying to do a synchronous 
> transfer to a USB device. The transfer is successful and there are no 
> anomalies on that front. However, when I call libusb_handle_events() to 
> block for a response on a transfer I've previously submitted, nothing 
> comes in when I'm positive *something* should be coming in.

Your code only does synchronous I/O and no asynchronous stuff, so there 
is no need to wait for events.

libusb_bulk_transfer returns when the transfer has completed (or the 
timeout is met, or an error occurs). Nothing else will happen with 
respect to that transfer afterwards.

Daniel

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Michael Lewis | 4 Jun 13:47 2008
Picon

Re: Sample application using OpenUSB isochronous transfer

On Tue, Jun 3, 2008 at 4:21 AM, <srpoc103 <at> ecs.soton.ac.uk> wrote:

Quoting Lei Chen <Raymond.Chen <at> Sun.COM>:

> Hi developers,
>     Thanks to a developer's great effort, there appears the application
> using OpenUSB to do ISOC transfer on Solaris. This application operates
> on an OV511/OV511+ based webcam. It works very well when capturing
> image. You can get the source code from:
> http://dev4usb.netbeans.org/source/browse/dev4usb/samples/webeye/webeye_video/
> and have a try on Solaris with latest OpenUSB svn version(I believe it
> will also work on Linux). This application is part of dev4usb project in
> NetBeans community. With dev4usb, developers can easily develop an
> application to drive USB device using libusb or OpenUSB library. See
> more information at: http://dev4usb.netbeans.org/.
>
> Regards,
> Lei Chen
>
>

Has anyone tested this on Linux? I am having problems with ISO URBs
using the Linux OpenUSB backend.

No unfortunately this has NOT been tested on Linux. I made some changes to try and improve iso transfers on Linux, but they've received no testing, as I don't have the hardware at the moment.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Libusb-devel mailing list
Libusb-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel

Gmane