READ BULK DATA FROM USB

1,487 views
Skip to first unread message

Johnson Z.

unread,
Jul 11, 2013, 11:09:46 AM7/11/13
to usb4...@googlegroups.com
First, let me say thanks to Claus Reimer!!!
without ur code, i even can't get a tiger.

these days, i try to read/write data from/to a cypress-usb fixed on a radar device.
the write-data-code is working well, but the read-data-code doesn't work.
i always get a timeout error when i read data from usb.
1. drv status is ok.
2. radar is working well
3. bothe async and sync submit-method are tested

cld u pls tell me what i missed? i don't know why it timeouts all the time..... tks advance.
here is the snip:
        inputEndpoint = findEndpoint(usbInterface.getUsbEndpoints(),
                UsbConst.REQUESTTYPE_DIRECTION_IN, UsbConst.ENDPOINT_TYPE_BULK);
        inputPipe = inputEndpoint.getUsbPipe();
        inputPipe.open();
        irp = inputPipe.createUsbIrp();
        data = new byte[512];// for my usb, max-size of pkg of in-pipe is 512
        irp.setData(data);

        /*
         * always time-out on this line!!! no matter sync or async method is
         * used. no matter sumbmit a byte[] or irp, i get a timeout error.
         */

        inputPipe.syncSubmit(irp); // god bless me, Claus, help me......
        irp.complete();
        Log.i("data is read and actual length is " + irp.getActualLength());


for the whole file, pls refer to attachment.
tar.gz is the eclipse project on my pc.
png is a img to show lib/project tree.







Screenshot from 2013-07-11 22:49:28.png
MyUsbIOTest.java
javax-usb-demo.from.Johnson.Z.tar.gz

Klaus Reimer

unread,
Jul 11, 2013, 12:32:12 PM7/11/13
to usb4...@googlegroups.com
On 07/11/2013 05:09 PM, Johnson Z. wrote:
> irp = inputPipe.createUsbIrp();
> data = new byte[512];// for my usb, max-size of pkg of in-pipe is
> 512
> irp.setData(data);

How many bytes are you expecting to receive? What happens if you set the
buffer size to exactly the number of bytes you want to read? It's not an
error to use a larger buffer, it's just interesting to know if this also
fails.

There is an IRP flag called "acceptShortPacket" which may be relevant
here but even if this is not set it should throw a
UsbShortPacketException and not a timeout. And you say you also tried
out syncSubmit(byte[])? Then this flag is automatically set to true so I
guess this is not the problem.

Well, it's hard to help here. Can you provide more information? Which
operating system are you using? Can you provide the full stack trace of
the exception?

--
Klaus Reimer <http://www.ailis.de/~k/>
[A735 47EC D87B 1F15 C1E9 53D3 AA03 6173 A723 E391]

Johnson Z.

unread,
Jul 11, 2013, 11:30:02 PM7/11/13
to usb4...@googlegroups.com
thank u so much for ur reply.
 
1. How many bytes are you expecting to receive?
    i wann read 2048 bytes each time.
 
2. What happens if you set the buffer size to exactly the number of bytes you want to read?
    i got the same timeout error. and here is the stack:
INF: data is sent and actual length is 6 // this means the write-code works well
INF: data is sent and actual length is 6 // this is frm the 2nd writing code, woks too.
INF: data is read and actual length is 0 // now, i got nothing here, the reading code is a tiger on my road.
de.ailis.usb4java.libusb.LibUsbException: USB error 7: Transfer error on bulk endpoint: LIBUSB_ERROR_TIMEOUT
 at de.ailis.usb4java.IrpQueue.transfer(IrpQueue.java:201) // the method used is LibUsb.bulkTransfer()
 at de.ailis.usb4java.IrpQueue.read(IrpQueue.java:126)
 at de.ailis.usb4java.IrpQueue.processIrp(IrpQueue.java:76)
 at de.ailis.usb4java.AbstractIrpQueue.process(AbstractIrpQueue.java:91)
 at de.ailis.usb4java.AbstractIrpQueue$1.run(AbstractIrpQueue.java:71)
 at java.lang.Thread.run(Thread.java:724)
 
3. Which operating system are you using?
    OS: windows xp is used
    DRV: zadig_v2.0.1.160 is used to install the WinUSB (v6.1.7600.16385) drvier for my usb deivce.
 
4. Current status.
    I validate the the cmd for initializing the usb device again. when i rerun the code, it's worked one times and i got 512bytes data. but, then, it failed forever again. so funny!
 
    Klaus, do u have any good idea....tku so much.
    BRG
    Johnson
 

 

I wana know whic line throws the timeout error, but I can't debug the code and here is the log:
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x70884ba7, pid=4676, tid=760
#
# JRE version: 7.0_25-b17
# Java VM: Java HotSpot(TM) Client VM (23.25-b01 mixed mode windows-x86 )
# Problematic frame:
# C  [libusb4java.dll+0x4ba7]  Java_de_ailis_usb4java_libusb_ConfigDescriptor_bLength+0x18
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# F:\wks\jee\javax-usb-tck_1.0.1\hs_err_pid4676.log
#
# If you would like to submit a bug report, please visit:
#  
http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
maybe, it's caused by jni...i dnt know...


 


--
You received this message because you are subscribed to a topic in the Google Groups "usb4java" group.
To post to this group, send an email to usb4...@googlegroups.com.
Visit this group at http://groups.google.com/group/usb4java.



Klaus Reimer

unread,
Jul 12, 2013, 2:14:55 AM7/12/13
to usb4...@googlegroups.com
On 07/12/2013 05:30 AM, Johnson Z. wrote:
> 1. How many bytes are you expecting to receive?
> i wann read 2048 bytes each time.

This won't help fixing your current problem but why are you using a
buffer auf 512 bytes when you want to read 2048 bytes? The maximum
packet size has nothing to do with the buffer size you can give the
library. If you want to read 2048 bytes then you can do this in one
call. The library automatically splits the transfer into multiple
transfers depending on the maximum packet size.


> I validate the the cmd for initializing the usb device again. when i
> rerun the code, it's worked one times and i got 512bytes data. but,
> then, it failed forever again. so funny!
> Klaus, do u have any good idea....tku so much.

Unfortunately I don't have a good idea... Maybe... you say it worked one
time and then never again? Have you tried physically reconnecting your
device before starting your program? Maybe it is in some invalid state
because something else failed in the previous run?
signature.asc

Harshad RJ

unread,
Jul 12, 2013, 2:33:58 AM7/12/13
to usb4...@googlegroups.com


On Friday, 12 July 2013 09:00:02 UTC+5:30, Johnson Z. wrote:
    OS: windows xp is used
    DRV: zadig_v2.0.1.160 is used to install the WinUSB (v6.1.7600.16385) drvier for my usb deivce.
 

I just tried that zadig thing while testing my app on Win7 today. One thing I noticed was they have a different version for XP users.
See here:
http://sourceforge.net/projects/libwdi/files/zadig/

The file zadig_xp_v2.0.1.160.7z is recommended for XP. Did you use the XP specific version?

 

Johnson Z.

unread,
Jul 12, 2013, 3:44:39 AM7/12/13
to usb4...@googlegroups.com
yeah, u r right, big pkg is splitted automatically. i just do a test here, 512 sld be ok, for the usb maxPkgSize is 512.
and, 2048 is failed too. never success...yeah, i definitely reset the device, reconnect it before my test.....
:) Klaus, is there any bug in my read-data-code?
 
i think i cld a have a final fight for this issue: modify the jni with offcial dirver from usb vendor. but i am not sure is there a c-implemented dirver for my cypress usb device or not. for it sounds good to call c with java. if dirver is implemented with C++/MFC, it's not a good news for jni/jna. it's right? we know, u r good at jni :)

BRG
Johnson

Klaus Reimer

unread,
Jul 12, 2013, 5:29:56 AM7/12/13
to usb4...@googlegroups.com
On 07/12/2013 09:44 AM, Johnson Z. wrote:
> :) Klaus, is there any bug in my read-data-code?

Sorry, I don't see an error.


> i think i cld a have a final fight for this issue: modify the jni with
> offcial dirver from usb vendor. but i am not sure is there a
> c-implemented dirver for my cypress usb device or not.

You mean modifying the JNI code of usb4java to use a special device
driver? This makes no sense. usb4java implements generic USB
functionality while a specific device driver implements a specific
device protocol. So in this case it makes more sense to write your own
JNI or JNA wrapper around the device driver if generic USB stuff fails.
You no longer need usb4java then.

But before you do this you could try writing a small test program which
directly uses libusb. If this works, then it would be good base to find
the problem in usb4java if there is one. If this also fails then it is a
good indicator that you are communicating with the device in the wrong
way (Maybe some other command must be sent to it before you can read
from it?). And if you are absolutely sure that you are communicating
correctly with the device but it still fails with native libusb then you
might find help on the libusb mailing list (And there are the *REAL* USB
gurus).

Another thing you might try: If you have access to a linux system maybe
you can try your Java program there? libusb works best on Linux. If your
program runs there then this is a good indicator that your program works
correctly and we have some windows problem with libusb here.
signature.asc

Johnson Z.

unread,
Jul 12, 2013, 7:10:18 PM7/12/13
to usb4...@googlegroups.com


thk u so much.
but it still doesn't work for me :<
 
BRG
Johnson
 

--

Johnson Z.

unread,
Jul 12, 2013, 7:28:24 PM7/12/13
to usb4...@googlegroups.com

Yeah! Thank u, i got it and i will try.

Johnson Z.

unread,
Jul 13, 2013, 2:01:20 AM7/13/13
to usb4...@googlegroups.com
Dear Klaus, how abt ur weekend?
I hope my msg make no noise to u.

i have a old software, it cld read/write data frm/to the radar-usb by
using driver from the usb vendor.
i checked the pkg sent to usb by old sftware. as u said, there r some
differences between the old one and my new one.

the the code in old one is just to send the same cmd as i do in the new one.
i'am not sure where the other pkg is from. it's sent by dirver?
ok, i cld simulate it.

finally, thk u for ur professional suggestion. infact, i get no time to
fix this issue, i need to ensure the project speed...so, maybe, i will
switch to dev the new sft with c++ first.

Have a nice day.
Johnson
Reply all
Reply to author
Forward
0 new messages