From: Tom Z. on
I'm using WinUSB on Windows 7 with WDK 7600. I have a USB device has a pair
of bulk endpoints, one IN and one OUT. I also have an application that reads
and writes these pipes.

I'm running in a loop, first sending a few bytes using WinUsb_WritePipe, and
then receiving a few bytes using WinUsb_ReadPipe. This works fine for a long
while, and the correct data is transferred in both directions. I am sending
and receiving the same data in each loop iteration (this is test code), and
there is nothing else in the loop.

But after 23071 iterations of the loop, the call to WinUsb_ReadPipe fails.
GetLastError returns 6 (invalid handle). This error is 100 repeatable,
meaning that if I re-start my application (which also re-initializes and
opens the handle again), it runs and fails in the same way again.

When I look at the USB bus with a bus analyzer, everything looks normal, and
the last transfer is the OUT. The PC is not sending an IN request as a result
to my final failed call to WinUsb_ReadPipe.

Does anyone have any ideas what might be wrong?
From: Tim Roberts on
Tom Z. <none> wrote:
>
>I'm using WinUSB on Windows 7 with WDK 7600. I have a USB device has a pair
>of bulk endpoints, one IN and one OUT. I also have an application that reads
>and writes these pipes.

What kind of device? FX2? Full speed or high speed? What's the max
packet size for your bulk pipes?

>I'm running in a loop, first sending a few bytes using WinUsb_WritePipe, and
>then receiving a few bytes using WinUsb_ReadPipe. This works fine for a long
>while, and the correct data is transferred in both directions. I am sending
>and receiving the same data in each loop iteration (this is test code), and
>there is nothing else in the loop.

How many bytes each time? How large is the buffer in your ReadPipe call?

>But after 23071 iterations of the loop, the call to WinUsb_ReadPipe fails.
>GetLastError returns 6 (invalid handle). This error is 100 repeatable,
>meaning that if I re-start my application (which also re-initializes and
>opens the handle again), it runs and fails in the same way again.

Very odd that it's a consistent number. That implies a buffering problem
somewhere. Is it possible that you are incrementing the input buffer
pointer during each loop, so that you eventually overwrite the handle? Are
you able to post the code?

>When I look at the USB bus with a bus analyzer, everything looks normal, and
>the last transfer is the OUT. The PC is not sending an IN request as a result
>to my final failed call to WinUsb_ReadPipe.

Is the final IN token very close to the end of a frame?

>Does anyone have any ideas what might be wrong?

Just wild guesses for now, but it's an interesting problem.
--
Tim Roberts, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: RNA on


"Tim Roberts" wrote:

> Tom Z. <none> wrote:
> >
> >I'm using WinUSB on Windows 7 with WDK 7600. I have a USB device has a pair
> >of bulk endpoints, one IN and one OUT. I also have an application that reads
> >and writes these pipes.
>
> What kind of device? FX2? Full speed or high speed? What's the max
> packet size for your bulk pipes?
>
> >I'm running in a loop, first sending a few bytes using WinUsb_WritePipe, and
> >then receiving a few bytes using WinUsb_ReadPipe. This works fine for a long
> >while, and the correct data is transferred in both directions. I am sending
> >and receiving the same data in each loop iteration (this is test code), and
> >there is nothing else in the loop.
>
> How many bytes each time? How large is the buffer in your ReadPipe call?
>
> >But after 23071 iterations of the loop, the call to WinUsb_ReadPipe fails.
> >GetLastError returns 6 (invalid handle). This error is 100 repeatable,
> >meaning that if I re-start my application (which also re-initializes and
> >opens the handle again), it runs and fails in the same way again.
>
> Very odd that it's a consistent number. That implies a buffering problem
> somewhere. Is it possible that you are incrementing the input buffer
> pointer during each loop, so that you eventually overwrite the handle? Are
> you able to post the code?
>
> >When I look at the USB bus with a bus analyzer, everything looks normal, and
> >the last transfer is the OUT. The PC is not sending an IN request as a result
> >to my final failed call to WinUsb_ReadPipe.
>
> Is the final IN token very close to the end of a frame?
>
> >Does anyone have any ideas what might be wrong?
>
> Just wild guesses for now, but it's an interesting problem.
> --
> Tim Roberts, timr(a)probo.com
> Providenza & Boekelheide, Inc.
>

Even i have the same problem.When writting too much data continuously get
windows last error
ERROR_BAD_COMMAND,ERROR_DEVICE_NOT_CONNECTED,ERROR_INVALID_HANDLE .The
application works fine if restart the application(initialize the winusba
gain).What might be the problem?