- 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?

