title: Getting -1 while data transfer using bulktransfer()
body: <p>I am working on an application which needs data communication between Android phone and Camera. Android phone and camera connected via usb.</p>
  
  <p>I can read and write data first time with <code>bulkTransfer()</code>,but  when I try it for second time, I am getting negative 1. 
  I also tried with different timeout. Any kind of suggestion is highly appreciated.</p>
  
  <p>My code is given bellow</p>
  
  <pre><code>public int process()
  {
      // prepare the command data
      ContainerCommand data = prepareCommand();
  
      int reqSize = data.size();
      data.prepareRequest(outBuffer);
  
      if (! skipLogging) {
          Log.i(TAG, "-== Ready to send Command [**- " + commandName + " -**] ==-");
          if (OperationCode.debugVerbose) {
              Log.v(TAG, data.toString());
              Log.v(TAG, StringUtility.dumpByteArray(outBuffer, reqSize));
          }
          Log.d(TAG, "reqLen: " + reqSize);
      }
  
      int sentLen;
      sentLen = usbConnection.bulkTransfer(epHost2Camera, outBuffer, reqSize, usbTimeout);
      if (sentLen != reqSize) {
          if (! skipLogging) {
              Log.w(TAG, "******--- UNEXPECTED send len:" + sentLen);
          }
          return UsbCameraConstants.RET_GENERAL_ERROR;
      }
  
      int resultCode;
      resultCode = sendExtraData4Command();
      if (resultCode != UsbCameraConstants.RET_SUCCESSFULLY_DONE) {
          if (! skipLogging) {
              Log.w(TAG, "******--- UNEXPECTED extra data send for command! retCode:" 
                      +  short2Hex(resultCode) );
          }
          return resultCode;          
      }
  
      resultCode = UsbCameraConstants.RET_GENERAL_ERROR;
      // get response
      int readLen;
      boolean responseGet = false;
      boolean errorFound = false;
  
      readLen = usbConnection.bulkTransfer(epCamera2Host, inBuffer
              , maxInPacketSize, usbTimeout);
      if (! skipLogging) {
          Log.d(TAG, "******--- Got first response, read len:" + readLen);
      }
      if (readLen &lt;= 0) {
          if (! skipLogging) {
              Log.w(TAG, "******--- UNEXPECTED read len:" + readLen);
          }
          errorFound = true;  
      }
      while ((readLen &gt; 0) &amp;&amp; (! responseGet) &amp;&amp; (! errorFound)) {
          ContainerBase container = null;
          try {
              container = ContainerBase.parseBaseValue(inBuffer, 0, readLen);
          } catch (Exception e) {
              Log.e(TAG, "Failed to parse container packet!", e);
              errorFound = true;
              resultCode = UsbCameraConstants.RET_GENERAL_ERROR;
          }
          if (container != null) {
              if (! skipLogging) {
                  Log.d(TAG, "Response packet basic information:" + container.toString());
                  if (OperationCode.debugVerbose) { 
                      Log.v(TAG, StringUtility.dumpByteArray(inBuffer, readLen));
                  }
              }
              if (container.type == ContainerBase.TYPE_DATA_BLOCK) {
                  // need read again
                  if (! skipLogging) {
                      Log.d(TAG, "Data container block found!");
                  }
                  if (readLen &gt; leastPacketSize) {
                      // need process the data content
                      if (! processDataBlock(container.length, readLen) ) {
                          Log.w(TAG, "Failed to Process Data Packet!");
                          errorFound = true;
                      }
                  }
              }
              else if (container.type == ContainerBase.TYPE_RESPONSE_BLOCK) {
                  resultCode = container.code;
                  if (! skipLogging) {
                      Log.d(TAG, "Response container block found! retCode:" + short2Hex(resultCode));
                  }
                  responseGet = true;
                  if (! processResponseBlock() ) {
                      Log.w(TAG, "Failed to Process Response Packet!");
                  }
              }
              if (! responseGet) {
                  do {
                      readLen = usbConnection.bulkTransfer(epCamera2Host, inBuffer
                              , maxInPacketSize, usbTimeout);
                      if (! skipLogging) {
                          Log.d(TAG, "******--- Got packet from endpoint Camera2Host, read len:" 
                                      + readLen);
                      }
                      if (readLen == 0) {
                          Log.w(TAG, "***ReadLen=0, camera data not ready yet. sleep a little while!");
                          try {
                              Thread.sleep(50L); // 50 milliseconds
                          }
                          catch (Exception e) {
                              // do nothing
                              e.printStackTrace();
                          }
                      }                       
                  } while (readLen == 0);
  
              }
          }
  
  
      }
  
      return resultCode;
  } 
  </code></pre>