Xiaofan Chen | 1 May 2008 02:50
Picon

Re: usb_bulk_read vs. openusb_bulk_xfer

On Thu, May 1, 2008 at 2:05 AM, Michael Lewis <milewis1 <at> gmail.com> wrote:
> On Wed, Apr 30, 2008 at 11:21 AM, adamlah <adamlah <at> gmail.com> wrote:
>
> >
> > Using libusb my code is something like this..
> >
> > const int bulklen = 65536;
> > char bulk[bulklen]
> > while {
> >    int ret = usb_bulk_read(udev, 0x82, bulk, bulklen, 500);
> >    write(1, bulk, ret);
> > }
> >
> > I get a whole bunch of output to the screen. Now, converting this to
> openusb
> > I have something like..
> >
> > openusb_bulk_request_t bulk;
> > memset(&bulk, 0, sizeof(bulk));
> > memset(bulkrd, 0, buflen);
> > while {
> >  ret = openusb_bulk_xfer(devh, 0, 0x82, &bulk);
> >  for (i=0; i<bulk.result.transferred_bytes; i++) {
> >  printf("%02x ", (unsigned char)bulkrd[1]);
> >  }
> > }
> >
> > I get nothing. bulkrd is always empty and bulk.result.transferred_bytes is
> > always 0. I've spent hours trying to sort this bit out and I was wondering
> > if anyone could offer me any advice?
(Continue reading)

adamlah | 1 May 2008 10:09
Picon

Re: usb_bulk_read vs. openusb_bulk_xfer


No error is returned in ret. I always test ret to ensure its not negative.

bulk_max_xfer_size is indeed returned as 0x4000 (16KB)

Can you suggest to me how I can make my code work? Would it simply involve
setting bulklen to 16384 rather than 65536?

Cheers

Michael Lewis wrote:
> 
> On Wed, Apr 30, 2008 at 11:21 AM, adamlah <adamlah <at> gmail.com> wrote:
> 
>>
>> Using libusb my code is something like this..
>>
>> const int bulklen = 65536;
>> char bulk[bulklen]
>> while {
>>    int ret = usb_bulk_read(udev, 0x82, bulk, bulklen, 500);
>>    write(1, bulk, ret);
>> }
>>
>> I get a whole bunch of output to the screen. Now, converting this to
>> openusb
>> I have something like..
>>
>> openusb_bulk_request_t bulk;
>> memset(&bulk, 0, sizeof(bulk));
(Continue reading)

Xiaofan Chen | 1 May 2008 10:20
Picon

Re: usb_bulk_read vs. openusb_bulk_xfer

On Thu, May 1, 2008 at 4:09 PM, adamlah <adamlah <at> gmail.com> wrote:
>
> No error is returned in ret. I always test ret to ensure its not negative.
>
> bulk_max_xfer_size is indeed returned as 0x4000 (16KB)
>
> Can you suggest to me how I can make my code work? Would it simply involve
> setting bulklen to 16384 rather than 65536?
>

I will think so. You have to manually split 65536 into 16384 x 4. So you
need to call the function 4 times.

I think this is not ok for an libusb implementation.

Xiaofan

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
adamlah | 1 May 2008 11:13
Picon

Re: usb_bulk_read vs. openusb_bulk_xfer


just to confirm.. this code works fine.. thanks for your help!

=============

int buflen = 0x4000; // where 0x4000 is returned from pdev->
char bulkrd[buflen];
openusb_bulk_request_t bulk;
int i, ret;

memset(&bulk, 0, sizeof(bulk));
memset(bulkrd, 0, buflen);

bulk.payload = (unit8_t*)bulkrd;
bulk.length = buflen;
bulk.timeout = 500;

ret = openusb_bulk_xfer(devh, 0, 0x82, &bulk);
if (ret < 0) {
 printf("bulk sync read fail : %s\n", openusb_strerror(ret));
 return (ret);
}

for (i=0; i<bulk.result.transferred_bytes; i++) {
 if (%16 == 0) { printf("\n"); }
 printf("%02x ", (unsigned char)bulkrd[i]);
}
printf("\n");

adamlah wrote:
(Continue reading)

adamlah | 1 May 2008 12:53
Picon

openusb_isoc_xfer problems


Sorry about all these problems i'm having, you guys are being so helpful and
this is now my last hurdle!

Firstly, it may be important to say that my devices isoc_max_xfer_device
returns as 0x0. I hope this is because the isoc mode is real time streaming
and not chunked like the other modes.

Here is my code using openusb_isoc_xfer, I get no further than the actual
call to the xfer function and the code just hangs......

==================

int pkt_cnt = 12;
int pkt_len = 128;

char bulkrd[pkt_cnt*pkt_len];
openusb_isoc_request_t isoc;
int i, j, ret;

memset(&isoc, 0, sizeof(isoc));
memset(bulkrd, 0, pkt_num*pkt_cnt);

isoc.start_frame = 0;

// set up packets
isoc.pkts.packets = (openusb_isoc_packet_t*)malloc(sizeof(struct
openusb_isoc_packet) * pkt_cnt);
for (i=0; i<pkt_cnt; i++) {
 isoc.pkts.packets[i].length = pkt_len;
(Continue reading)

Michael Lewis | 1 May 2008 14:54
Picon

Re: openusb_isoc_xfer problems

On Thu, May 1, 2008 at 6:53 AM, adamlah <adamlah <at> gmail.com> wrote:


Sorry about all these problems i'm having, you guys are being so helpful and
this is now my last hurdle!

I will take a look at this program and try and see what might be happening. To be honest, OpenUSB has not been well tested with isochronous hardware so there still may be some problems, but I'm happy to help you work through them. I will get back to you later in the day.
 

Firstly, it may be important to say that my devices isoc_max_xfer_device
returns as 0x0. I hope this is because the isoc mode is real time streaming
and not chunked like the other modes.

Here is my code using openusb_isoc_xfer, I get no further than the actual
call to the xfer function and the code just hangs......

==================

int pkt_cnt = 12;
int pkt_len = 128;

char bulkrd[pkt_cnt*pkt_len];
openusb_isoc_request_t isoc;
int i, j, ret;

memset(&isoc, 0, sizeof(isoc));
memset(bulkrd, 0, pkt_num*pkt_cnt);

isoc.start_frame = 0;

// set up packets
isoc.pkts.packets = (openusb_isoc_packet_t*)malloc(sizeof(struct
openusb_isoc_packet) * pkt_cnt);
for (i=0; i<pkt_cnt; i++) {
 isoc.pkts.packets[i].length = pkt_len;
 isoc.pkts.packets[i].payload = (uint8_t*)bulkrd+pkt_len*i;
}
isoc.pkts.num_packets = pkt_cnt;

isoc.isoc_results = (openusb_request_result*)malloc(sizeof(struct
openusb_request_result) * pkt_cnt);
memset(isoc.isoc_results, 0, sizeof(struct openusb_request_result) *
pkt_cnt);

ret = openusb_isoc_xfer(devh, 0, 0x82, &isoc);

printf("returned\n");

if (ret < 0) {
 printf("isoc xfer read fail : %s\n", openusb_strerror(ret));
 return (-1);
}

for (i=0; i<pkt_cnt; i++) {
 for (j=0; j<pkt_len; j++) {
 if (j%16==0) { printf("\n"); }
 printf("%02x ", isoc.pkts.packets[i].payload[j];
 }
 printf("\n");
}
printf("\n");

return(0);

==================

If your still with me, the result of this code executing is the program
hanging on the openusb_isoc_xfer command (ie. "returned" is never printed).

Could this be something to do with me needing to call one of the other
transfer commands like openusb_xfer_aio or similar?

I have also tried setting different alt values before the xfer but this
doesnt seem to help either.

Any ideas or suggestions are greatly appreciated!

Cheers
--
View this message in context: http://www.nabble.com/openusb_isoc_xfer-problems-tp16993209p16993209.html
Sent from the LibUSB Dev mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Libusb-devel mailing list
Libusb-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel



--
Mike Lewis
milewis1 <at> gmail.com

"Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind."
--Dr. Seuss
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Libusb-devel mailing list
Libusb-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel
adamlah | 1 May 2008 15:28
Picon

Re: openusb_isoc_xfer problems


just to let you know i had to make the changes to openusb.h as detailed in
the post below to make it compile, which is why my code may not seem to
follow suit!

http://www.nabble.com/proposed-change-to-openusb.h-to16985457.html

adamlah wrote:
> 
> Sorry about all these problems i'm having, you guys are being so helpful
> and this is now my last hurdle!
> 
> Firstly, it may be important to say that my devices isoc_max_xfer_device
> returns as 0x0. I hope this is because the isoc mode is real time
> streaming and not chunked like the other modes.
> 
> Here is my code using openusb_isoc_xfer, I get no further than the actual
> call to the xfer function and the code just hangs......
> 
> ==================
> 
> int pkt_cnt = 12;
> int pkt_len = 128;
> 
> char bulkrd[pkt_cnt*pkt_len];
> openusb_isoc_request_t isoc;
> int i, j, ret;
> 
> memset(&isoc, 0, sizeof(isoc));
> memset(bulkrd, 0, pkt_num*pkt_cnt);
> 
> isoc.start_frame = 0;
> 
> // set up packets
> isoc.pkts.packets = (openusb_isoc_packet_t*)malloc(sizeof(struct
> openusb_isoc_packet) * pkt_cnt);
> for (i=0; i<pkt_cnt; i++) {
>  isoc.pkts.packets[i].length = pkt_len;
>  isoc.pkts.packets[i].payload = (uint8_t*)bulkrd+pkt_len*i;
> }
> isoc.pkts.num_packets = pkt_cnt;
> 
> isoc.isoc_results = (openusb_request_result*)malloc(sizeof(struct
> openusb_request_result) * pkt_cnt);
> memset(isoc.isoc_results, 0, sizeof(struct openusb_request_result) *
> pkt_cnt);
> 
> ret = openusb_isoc_xfer(devh, 0, 0x82, &isoc);
> 
> printf("returned\n");
> 
> if (ret < 0) {
>  printf("isoc xfer read fail : %s\n", openusb_strerror(ret));
>  return (-1);
> }
> 
> for (i=0; i<pkt_cnt; i++) {
>  for (j=0; j<pkt_len; j++) {
>   if (j%16==0) { printf("\n"); }
>   printf("%02x ", isoc.pkts.packets[i].payload[j];
>  }
>  printf("\n");
> }
> printf("\n");
> 
> return(0);
> 
> ==================
> 
> If your still with me, the result of this code executing is the program
> hanging on the openusb_isoc_xfer command (ie. "returned" is never
> printed).
> 
> Could this be something to do with me needing to call one of the other
> transfer commands like openusb_xfer_aio or similar?
> 
> I have also tried setting different alt values before the xfer but this
> doesnt seem to help either.
> 
> Any ideas or suggestions are greatly appreciated!
> 
> Cheers
> 

--

-- 
View this message in context: http://www.nabble.com/openusb_isoc_xfer-problems-tp16993209p16993246.html
Sent from the LibUSB Dev mailing list archive at Nabble.com.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Xiaofan Chen | 1 May 2008 15:38
Picon

Re: usb_bulk_read vs. openusb_bulk_xfer

On Thu, May 1, 2008 at 9:09 PM, Michael Lewis <milewis1 <at> gmail.com> wrote:
> > What is the reason behind this? This will break quite some libusb based
> > programs.
>
> The reason is because the operating system only allows chunks of a certain
> size to be sent down with each request. I've been trying to think of a way
> to allow chunks of arbitrary sizes to be sent down within the asynchronous
> framework, but I admit that I haven't had the time I'd like to spend on it.
> Until I/we do then the api that reports the max chunk size and a loops
> should be sufficient to do this in a generic way.
>
> As always any ideas are always welcome.
>

I see.I remember under Windows there is no such problem as the
upper level usb driver will do that for you.

Maybe the Linux USB experts in the list (Alan Stern and Greg KH)
can help you on this.

Xiaofan

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Alan Stern | 1 May 2008 16:14
Picon
Favicon

Re: usb_bulk_read vs. openusb_bulk_xfer

On Thu, 1 May 2008, Xiaofan Chen wrote:

> On Thu, May 1, 2008 at 9:09 PM, Michael Lewis <milewis1 <at> gmail.com> wrote:
> > > What is the reason behind this? This will break quite some libusb based
> > > programs.
> >
> > The reason is because the operating system only allows chunks of a certain
> > size to be sent down with each request. I've been trying to think of a way
> > to allow chunks of arbitrary sizes to be sent down within the asynchronous
> > framework, but I admit that I haven't had the time I'd like to spend on it.
> > Until I/we do then the api that reports the max chunk size and a loops
> > should be sufficient to do this in a generic way.
> >
> > As always any ideas are always welcome.
> >
> 
> I see.I remember under Windows there is no such problem as the
> upper level usb driver will do that for you.
> 
> Maybe the Linux USB experts in the list (Alan Stern and Greg KH)
> can help you on this.

Linux doesn't break large chunks into smaller pieces because it expects 
userspace libraries (like libusb) to do so.

Alan Stern

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Xiaofan Chen | 1 May 2008 16:44
Picon

Re: usb_bulk_read vs. openusb_bulk_xfer

On Thu, May 1, 2008 at 10:14 PM, Alan Stern <stern <at> rowland.harvard.edu> wrote:
> > > The reason is because the operating system only allows chunks of a certain
> > > size to be sent down with each request.
> > I see.I remember under Windows there is no such problem as the
> > upper level usb driver will do that for you.
> >
> > Maybe the Linux USB experts in the list (Alan Stern and Greg KH)
> > can help you on this.
>
> Linux doesn't break large chunks into smaller pieces because it expects
> userspace libraries (like libusb) to do so.
>

Just curious here. What are the pros and cons of leave it to the user space
or leave it to the kernel driver?

Xiaofan

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

Gmane