UsbDeviceConnection bulktransfer not working properly

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 4

Aug 6, 2016, 10:45:45 PM via Website

I need a help to understand how UsbDeviceConnection bulktransfer works. For example I do not understand what is TIMEOUT good for? I changed it to different values, but I do not see any differences in received data.

Here I have a small testing code:

public static void read2(){

r = new Runnable() {
    public void run() {
        synchronized (this) {
            final int SIZE = 4096;
            while (true) {

                if (mUsbManager.hasPermission(device)){

                    byte[] buffer = new byte[SIZE];

                    StringBuilder str = new StringBuilder();

                    if (connection.bulkTransfer(epIn, buffer, SIZE, 0) >= 0) {
                        for (int i = 2; i < SIZE; i++) {
                            if (buffer[i] != 0) {
                                str.append((char) buffer[i]);
                            } else {
                                Log.e("Database", "M=" + str.toString());
                        Log.e("Database", "M=" + str.toString());
                try {
                } catch (InterruptedException e) {

thread = new Thread(r);


public static void send(String command){
String fullCommand = "@" + command + "\r\n"; /*+ "\r\n"*/

bytes = fullCommand.getBytes();

while (connection==null){
connection.bulkTransfer(epOut, bytes, bytes.length, 100); //0


Here I try to send a command to an USB device, and then it sends me back a string. That string should be about 25 character long, but the result what I get is different, sometimes 2 characters, sometimes 5, but I do not get the whole string.

I tried to change the buffers size, the timeout, the Thread.sleep() waiting time, but nothing solved my problem.

Could anybody help me to understand how this whole thing works, where can be the problem and how should I set these variables to get a functioning code?

Thanks in advance.


Recommended articles