USB bulkTransfer between Android tablet and camera
I think this function is not passing the correct endpoint
int status = connection.bulkTransfer(endpoint, getEvent, getEvent.length, TIMEOUT);
which is coming from
UsbInterface intf = device.getInterface(0);UsbEndpoint endpoint = intf.getEndpoint(0);
maybe the USB interface is not correct. Please check if index 0 parameter is correct.
Check usb endpoint direction. I've encountered some devices where USB_DIR_OUT was USB_DIR_IN and USB_DIR_IN was USB_DIR_OUT and it was causing some issues.
A few things that looks wrong in the provided code: a) An OpenSession
request need to be done first with transaction id 0, b) Increment the transaction ids, c) Read from USB_DIR_IN
.
My understanding is that the first request should open a session to the camera, only after this you can use GetEvent
requests. Furthermore, you need to increment the transaction ids and only use id 0 for OpenSession
. Below a quote from a PTP spec I found for Nikon cameras.
TransactionIDs are continuous sequences in numerical order starting from 0x00000001. The TransactionID used for the OpenSession operation shall be 0x00000000.
I open-sourced an Android camera app for Nikon and Canon apps on my Github. The code is a few years old. You will have a hard time to compile it, but the PTP code might be a good reference.