How to get what Usb device responses to Android Usb Host after the host sends a command?

Following a simple tutorial , I can connect to the device (usb optical mouse with an ADNS-5000 chip inside) and make bulkTransfer .

UsbInterface intf = device.getInterface(0); UsbEndpoint endpoint = intf.getEndpoint(0); UsbDeviceConnection connection = manager.openDevice(device); connection.claimInterface(intf, forceClaim); connection.bulkTransfer(endpoint, bytes, bytes.length, TIMEOUT); //do in another thread 

The ADNS-5000 specification (can be disabled) defines a certain set of "USB commands", among which there are, for example:

Mnemonics: Get_Status_Device

Team: 80 00 00 00 00 00 00 02 00

Notes: Usually returns 00 00, Power 00 00, Remote Awakening 02 00

So, I understand this as: when I write data:

 private byte[] bytes = {(byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00}; 

I should get either 0x00, 0x00 , or 0x00, 0x00 to the device (this is probably an error in spec, because this sequence of bytes is defined as the result for two different statuses) or 0x20, 0x00 in return , but I donโ€™t see any way api returned something, am i right?

+7
android android-usb usb-hostcontroller
source share
1 answer

I quickly looked through the ADNS-5000 specification. One thing is certain that you have an endpoint of IN and OUT.

Get_Status_Endpt0 82 00 00 00 xx 00 02 00 OUT: xx = 00, IN: xx = 80 Usually returns 00 00

This means that commands (no API) can return a result.

The only way I can imagine is to write the command to the OUT endpoint and read (by polling) the state (after executing the command) from the IN endpoint.

This is what I used in several projects, and it is wonderful. I'm not sure about the ADNS-5000, since I did not check the details of the USB protocol.

Hope this helps.

0
source share

All Articles