How to get in Android Usb Host what Usb Device responses after Host sends command?
Asked Answered
C

1

7

Following the simple tutorial I'm able to connect to device (usb optical mouse with ADNS-5000 chip inside) and make a 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

ADNS-5000 spec (can be googled out) defines some set of "USB Commands" among which there is for example:

Mnemonic: Get_Status_Device

Command: 80 00 00 00 00 00 02 00

Notes: Normally returns 00 00, Self powered 00 00, Remote wakeup 02 00

So I understand it like: when I write data:

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

to the device I should get either 0x00, 0x00 or 0x00, 0x00 (this is probably an error in spec as this byte sequence is defined as result for two different statuses) or 0x20, 0x00 in return, but I don't see any way the api returns anything, am I right?

Caulicle answered 20/7, 2016 at 14:45 Comment(0)
T
0

I took a quick look on a ADNS-5000 specification. One thing is for sure, you have IN and OUT endpoint available.

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

Which means that commands (there is no API) can return result.

The only way that I can imagine would be to write command to OUT endpoint and read (by polling) the status (after command execution) from IN endpoint.

This is something that I've been using in a few projects and it is perfectly fine. I am not sure about ADNS-5000 since I haven't checked the USB protocol details.

Hope it helps.

Trickle answered 22/8, 2016 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.