Im tring to read data from a USB device (USB camera that for some reason the CameraManager doesn't recognize). Ive asked for intent for intent and I can establish a connection with the device, but when i try to read data using bulkTransfer but it returns -1 each time.
This is the code for reading the data:
fun readat(): ByteArray {
val buffer = ByteArray(endpoint.maxPacketSize)
val result = m_connection?.bulkTransfer(endpoint, buffer, buffer.size, 6000)
if (result!! < 0) {
Log.i("serial", "The receive wasn't successful ")
}
return buffer.copyOf(result)
}
I also tried setting the DTR after establishing the connection as was suggested in some post i had seen:
m_connection = manager.openDevice(m_device)
var intf = m_device?.getInterface(0)!!
endpoint = intf.getEndpoint(0)
if (m_connection!!.claimInterface(intf, true)) {
Log.i("serial", "The interface was claimed successfully")
} else {
Log.i("serial", "The interface could not be claimed")
}
m_connection!!.controlTransfer(0x21, 0x22, 0x1, 0, null, 0, 0);
Does anyone have any suggestion on how to fix it?