gpt4 book ai didi

android - 如何在 Android Usb 主机中获取主机发送命令后 USB 设备响应的内容?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:15:01 25 4
gpt4 key购买 nike

正在关注 the simple tutorial我能够连接到设备(内置 ADNS-5000 芯片的 USB 光电鼠标)并制作 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 规范(可以用谷歌搜索出来)定义了一些“USB 命令”集,例如:

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

所以我这样理解:当我写数据的时候:

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

对于设备,我应该得到 0x00, 0x000x00, 0x00 (这可能是规范中的错误,因为此字节序列被定义为结果对于两种不同的状态)0x20、0x00 作为返回,但我看不到 api 以任何方式返回任何东西,对吗?

最佳答案

我快速浏览了 ADNS-5000 规范。可以肯定的是,您有可用的 IN 和 OUT 端点。

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

这意味着命令(没有API)可以返回结果。

我能想到的唯一方法是将命令写入 OUT 端点并从 IN 端点读取(通过轮询)状态(在命令执行后)。

这是我在几个项目中一直使用的东西,它非常好。我不确定 ADNS-5000,因为我没有检查 USB 协议(protocol)的详细信息。

希望对您有所帮助。

关于android - 如何在 Android Usb 主机中获取主机发送命令后 USB 设备响应的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38484474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com