0

Im having issues with this line of code. I was able to successfully open the device and send .

Sending:

retCode = LibUsb.bulkTransfer(devHandle, endpointSend, buf, iBuf, timeout);

Receiving:

retCode = LibUsb.bulkTransfer(devHandle, endpointReceive, messageBuf, iBuf, timeout);   
logger.debug("Receiving Message Status: "+retCode);

Output:

For Sending, I got a response of 0 but in receiving, I got -7.

Receiving Message Status: -7

libusb: error [init_device] program assertion failed: device address collision with root hub

Other logs

receiveMessage messageBuf: java.nio.DirectByteBuffer[pos=0 lim=1000 cap=1000]
receiveMessage iBuf: java.nio.HeapIntBuffer[pos=1 lim=1 cap=1]

References searched:

http://usb4java.org/apidocs/constant-values.html#org.usb4java.LibUsb.ERROR_TIMEOUT

public static final int ERROR_PIPE  -9
public static final int ERROR_TIMEOUT   -7

sometimes it is -9 when I disconnect and connect the device but usually -7. Since I have been playing with the timeout for a while now, I'm beginning to suspect that it is about the pipe. How do I resolve a -9 Error Code?

DarthVeder
  • 35
  • 8
  • Does it work in C? What kind of device is it? Sure that there is no kernel driver attached and that devHandle is valid? – Erlkoenig May 11 '18 at 05:38
  • @Erlkoenig have not tried in C. It is an Android device. How do I check the kernel driver? Im pretty sure that the devHandle is valid as I opened and sent a request to the device successfully – DarthVeder May 11 '18 at 06:07
  • Highly likely just a wrong error message. This looks like normal TIMEOUT error code, which just means that the device did not send data during `timeout` interval. – Turbo J May 12 '18 at 06:48
  • @TurboJ any docs that can help me with this one? – DarthVeder May 15 '18 at 07:54
  • Try increasing timout to over `9000`? No idea, depends on your hardware. – Turbo J May 15 '18 at 08:29
  • I tried increasing to 50000 and still the same issue occurs @TurboJ – DarthVeder May 15 '18 at 15:29
  • @TurboJ - does this logs help? > receiveMessage messageBuf: java.nio.DirectByteBuffer[pos=0 lim=1000 cap=1000] receiveMessage iBuf: java.nio.HeapIntBuffer[pos=1 lim=1 cap=1] – DarthVeder May 15 '18 at 16:54

1 Answers1

0

sometimes it is -9 when I disconnect

Should always be -9, as a disconnect clears the USB handle inside the kernel.

For Sending, I got a response of 0 but in receiving, I got -7.

That is the regular ERROR_TIMEOUT, which may or may not be an error at all.

The basic meaning is just: The USB device did not send any data on the endpoint during the timeout period.

In the (example) case of an USB2UART chip, the ERROR_TIMEOUT would just mean that there were no bytes received on the UART RX line.

Fun fact: LibUsb.bulkTransfer() can receive zero bytes from a USB device, and would not return an error code in this case. USB bulk endpoints actually allow that (and it is different from the "no data at all" case).

Turbo J
  • 7,563
  • 1
  • 23
  • 43
  • Note: A common case of `ERROR_TIMOUT` would be a protocol error when communicating with a device. – Turbo J May 15 '18 at 21:07
  • Actually I just put a timeout between creating the connecting and sending the bulktransfer and receiving got me a responseCode of 0 – DarthVeder May 16 '18 at 16:10