0

我希望我的问题不会是奇怪的或类似的问题,但我开始了一个关于 android 终端(目前是三星 Galaxy S2,但可能会改变)和基于嵌入式 Linux 的卡(armadeus apf51-dev 但也许是覆盆子)之间对话的项目pi 将来)。实际上,我在 android 终端上有一个应用程序,它显示 Linux 嵌入式卡通过无线连接发送的速度。主要目标是通过 USB 连接更改此 wifi 连接。我的主要问题是实现管道的 android 端。我通过 FabianCook (传输数据 USB ) 找到了这个答案:

UsbDevice dev = sDevice;
        if (dev == null)
            return;
        UsbManager usbm = (UsbManager) getSystemService(USB_SERVICE);
        UsbDeviceConnection conn = usbm.openDevice(dev);
        l("Interface Count: " + dev.getInterfaceCount());
        l("Using "
                + String.format("%04X:%04X", sDevice.getVendorId(),
                        sDevice.getProductId()));

        if (!conn.claimInterface(dev.getInterface(0), true))
            return;

        conn.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset
                                                        // mConnection.controlTransfer(0×40,
                                                        // 0, 1, 0, null, 0,
                                                        // 0);//clear Rx
        conn.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
        conn.controlTransfer(0x40, 0x02, 0x0000, 0, null, 0, 0);// flow
                                                                // control
                                                                // none
        conn.controlTransfer(0x40, 0x03, 0x0034, 0, null, 0, 0);// baudrate
                                                                // 57600
        conn.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0);// data bit
                                                                // 8, parity
                                                                // none,
                                                                // stop bit
                                                                // 1, tx off

        UsbEndpoint epIN = null;
        UsbEndpoint epOUT = null;

        byte counter = 0;

        UsbInterface usbIf = dev.getInterface(0);
        for (int i = 0; i < usbIf.getEndpointCount(); i++) {
            l("EP: "
                    + String.format("0x%02X", usbIf.getEndpoint(i)
                            .getAddress()));
            if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                l("Bulk Endpoint");
                if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)
                    epIN = usbIf.getEndpoint(i);
                else
                    epOUT = usbIf.getEndpoint(i);
            } else {
                l("Not Bulk");
            }
        }

这很有帮助,但我不明白什么是“sDevice”变量(第 1 行)。我想它是一个 UsbDevice 类实例,但我不知道这个变量是如何实例化的。也许有人可以指出我的好方法?

4

1 回答 1

0

对我来说,它看起来sDevice可能已经分配到其他地方以便在此处可用,但原始分配不在原始线程的示例代码中 - 我不确定它会在哪里实例化,但它应该只是代表一些连接的设备作为UsbDevice对象。

sDevice将起源于UsbManager您可以获得具有该getDeviceList()功能的已连接设备列表的位置

http://developer.android.com/reference/android/hardware/usb/UsbManager.html#getDeviceList()

于 2013-10-29T18:27:00.900 回答