problems with bulkTransfer Android 4.0.3

Put your problem here if it does not fit any of the other categories.

problems with bulkTransfer Android 4.0.3

Postby magda » Wed Apr 25, 2012 1:20 pm

I want to send a short data package (just 2 characters) via bulkTransfer to a camera connected via USB. I am using Samsung Galaxy S2 with Android 4.0.3 as a host. Everything seems fine, accept... no data is actually being sent. Theoretically, the method bulkTransfer returns a positive value, meaning the data has been transfered, but there is no visible effect. The code is as follows:

Code: Select all
char ch = (char)34;
    char[] record = {'P',ch};
    String r = record.toString();
    byte[] bytes  =  r.getBytes(Charset.forName("ASCII"));
    int TIMEOUT = 10000;
    boolean forceClaim = true;
    UsbManager mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    UsbInterface intf = device.getInterface(0);
     for (int i = 0; i < intf.getEndpointCount(); i++) {
          UsbEndpoint ep = intf.getEndpoint(i);
          if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
            if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
              endpoint = ep;
              //Integer dir = endpoint.getDirection();
              UsbDeviceConnection connection = mUsbManager.openDevice(device);
              if(connection!=null){devMessage+=" I connected";}
              connection.claimInterface(intf, forceClaim);
              Integer res = connection.bulkTransfer(endpoint, bytes, bytes.length, TIMEOUT);
              if (res>0){devMessage += "some data transfered.";}
              connection.releaseInterface(intf);
            break;

            }
           }

Is there anything more I need to include before I start bulkTransfer? Is there any need for controlTransfer before I start bulkTransfer? Is there anything else I might be forgetting. Please be understanding as this is my first app with USB communication and there are not many resources on the net. I've already read everything about usb host on developer.android... so please do not direct me there. Thanks a lot for any help.

Also, how do I transfer data the other way around? I tried bulkTransfer() with an endpoint the other way around but with no success. I want to read the data from the buttons being pushed on the camera. I've seen apps on the net that communicate with the camera so it has to be doable.

Any ideas?
magda
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Apr 25, 2012 1:09 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests