How to clear the pipes using usb4java

36 views
Skip to first unread message

Nathaniel Marzan

unread,
Jun 8, 2018, 10:19:31 PM6/8/18
to usb4java

Hi,

I have been successful on connecting with a device and sending data into in using LibUsb.bulktransfer. 

I am getting an errorcode sometimes of -7 and the third party says I need to clear pipes and gave me this pseudo-code. I see that it is expecting an ERROR_TIMEOUT and says continue. I don't know what it means to clear the pipe. Thanks!


clear_pipe()

{
err = receive()
if(err == ERROR_TIMEOUT)

{
continue;
}
else if (err == SUCCESS)
{
log data received;
}
else
{
display message cannot clear pipe;
}

}

Dennis Sheirer

unread,
Jun 9, 2018, 4:55:43 AM6/9/18
to usb4java
Assuming the device is halted due to the bulk transfer error, you can clear it with:

LibUsb.clearHalt(mUsbBulkTransferDeviceHandle, USB_BULK_TRANSFER_ENDPOINT);

Denny

Nathaniel Marzan

unread,
Jun 9, 2018, 5:20:47 AM6/9/18
to usb4...@googlegroups.com
Thanks! but how about for normal operations? I asked this post in stackoverflow > https://stackoverflow.com/questions/50770815/how-to-clear-pipe-in-syncbulktransfer-in-usb4java

As I saw a LibUsb.freeTransfer in Async method. 
Is there a same one in Sync?

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

Dennis Sheirer

unread,
Jun 10, 2018, 4:28:24 AM6/10/18
to usb4java
I believe that LibUsb.freeTransfer is used to release the memory associated with the transfer structure when you're finally finished transferring data.

When you're using the bulk transfer interface, you're specifying a timeout for the device to fill the transfer buffer that you provided with data and return the transfer buffer back to you via the callback.  That timeout period is being exceeded before the buffer is being filled, and this could be for various reasons.  Two possibilities come to mind: a)the device simply doesn't have more data to send, or b) you may not be invoking LibUsb.handleEvents (sufficiently/repeatedly) in time for the transfer buffer(s) to be filled.

I'm not aware (but I'm not an expert either) of a 'clearPipes' option when you encounter the timeout.  In my software, I normally stop/start (ie restart) the device when I encounter an error like this, but that may be a heavy-handed approach for you.  

How much data/how often are you expecting from the device?  How many/size transfer buffers are you making available to the device?  How are you managing the USB bus transfer processing, invoking the LibUsb.handleEvents() method call, is it via a dedicated thread or runnable?

Denny

Nathaniel Marzan

unread,
Jun 21, 2018, 1:18:12 PM6/21/18
to usb4...@googlegroups.com
I saw this code snippet on a sample code and is this by any way a clear pipe?

 int j = 0;
    i = LibUsb.kernelDriverActive(localDeviceHandle, j);
    if (i != 0) {
      i = LibUsb.detachKernelDriver(localDeviceHandle, j);
    }
    i = LibUsb.claimInterface(localDeviceHandle, j);
    if (i != 0)
    {
      LibUsbException localLibUsbException2 = new LibUsbException("Unable to claim usb interface", i);
      throw new ConnectionException(localLibUsbException2.getLocalizedMessage(), localLibUsbException2);
    }
Reply all
Reply to author
Forward
0 new messages